Remove bundled shaderc

This commit is contained in:
Benau 2023-01-03 10:01:41 +08:00
parent 93613d884e
commit 99bd8a338a
1340 changed files with 32 additions and 478502 deletions

1
.gitignore vendored
View File

@ -90,5 +90,6 @@ lib/harfbuzz
lib/sdl2
lib/mbedtls
lib/astc-encoder
lib/shaderc
.DS_Store

View File

@ -260,32 +260,23 @@ if(NOT SERVER_ONLY)
endif()
if(NOT SERVER_ONLY)
find_library(SHADERC_LIBRARY NAMES shaderc_shared libshaderc_shared)
if (IOS)
find_library(SHADERC_LIBRARY NAMES shaderc_combined libshaderc_combined)
else()
find_library(SHADERC_LIBRARY NAMES shaderc_shared libshaderc_shared)
endif()
find_path(SHADERC_INCLUDEDIR NAMES shaderc/shaderc.hpp PATHS)
if (NOT SHADERC_LIBRARY OR NOT SHADERC_INCLUDEDIR)
set(SHADERC_SKIP_INSTALL ON CACHE INTERNAL "Skip installation" FORCE)
set(SHADERC_SKIP_TESTS ON CACHE INTERNAL "Skip building tests" FORCE)
set(SHADERC_SKIP_EXAMPLES ON CACHE INTERNAL "Skip building examples" FORCE)
set(SHADERC_SKIP_COPYRIGHT_CHECK ON CACHE INTERNAL "Skip copyright check" FORCE)
set(SPIRV_HEADERS_SKIP_INSTALL ON CACHE INTERNAL "Skip install" FORCE)
set(SPIRV_HEADERS_SKIP_EXAMPLES ON CACHE INTERNAL "Skip building examples" FORCE)
set(SKIP_SPIRV_TOOLS_INSTALL ON CACHE INTERNAL "Skip installation" FORCE)
set(SPIRV_SKIP_TESTS ON CACHE INTERNAL "Skip tests" FORCE)
set(SPIRV_SKIP_EXECUTABLES ON CACHE INTERNAL "Skip executables" FORCE)
set(ENABLE_GLSLANG_BINARIES OFF CACHE INTERNAL "Builds glslangValidator and spirv-remap" FORCE)
set(ENABLE_CTEST OFF CACHE INTERNAL "Enable ctest" FORCE)
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/shaderc")
include_directories(BEFORE "${PROJECT_SOURCE_DIR}/lib/shaderc/libshaderc/include")
SET(SHADERC_LIBRARY shaderc)
message(STATUS "System shaderc not found, use the bundled one.")
if (NOT NO_SHADERC)
message(FATAL_ERROR "Please install shaderc from your distribution or disable vulkan support with -DNO_SHADERC=on")
endif()
else()
include_directories("${SHADERC_INCLUDEDIR}")
MESSAGE(STATUS "Use system shaderc: ${SHADERC_LIBRARY}")
endif()
if (NO_SHADERC)
add_definitions(-DDISABLE_SHADERC)
endif()
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/graphics_engine")
endif()
@ -774,8 +765,10 @@ if(NOT SERVER_ONLY)
graphics_utils
graphics_engine
${SDL2_LIBRARY}
tinygettext
${SHADERC_LIBRARY})
tinygettext)
if (NOT NO_SHADERC)
target_link_libraries(supertuxkart ${SHADERC_LIBRARY})
endif()
endif()
if(UNIX AND NOT APPLE)

View File

@ -61,6 +61,8 @@ set(MOLTENVK_LIBRARY ${PROJECT_SOURCE_DIR}/dependencies\${EFFECTIVE_PLATFORM_NAM
set(VULKAN_INCLUDEDIR ${PROJECT_SOURCE_DIR}/dependencies-iphoneos/include CACHE STRING "")
set(LIBASTCENC_LIBRARY ${PROJECT_SOURCE_DIR}/dependencies\${EFFECTIVE_PLATFORM_NAME}/lib/libastcenc.a CACHE STRING "")
set(LIBASTCENC_INCLUDEDIR ${PROJECT_SOURCE_DIR}/dependencies-iphoneos/include CACHE STRING "")
set(SHADERC_LIBRARY ${PROJECT_SOURCE_DIR}/dependencies\${EFFECTIVE_PLATFORM_NAME}/lib/libshaderc_combined.a CACHE STRING "")
set(SHADERC_INCLUDEDIR ${PROJECT_SOURCE_DIR}/dependencies-iphoneos/include CACHE STRING "")
# For universal iOS and simulator
set(LIBRESOLV_LIBRARY -lresolv CACHE STRING "")

View File

@ -34,6 +34,7 @@ std::map<std::string, std::pair<GESpinLock, VkShaderModule>* > g_shaders;
} // GEVulkanShaderManager
// ============================================================================
#ifndef DISABLE_SHADERC
shaderc_include_result* showError(const char* message)
{
shaderc_include_result* err = new shaderc_include_result;
@ -44,6 +45,7 @@ shaderc_include_result* showError(const char* message)
err->user_data = NULL;
return err;
} // showError
#endif
// ============================================================================
void GEVulkanShaderManager::init(GEVulkanDriver* vk)
@ -90,6 +92,7 @@ void GEVulkanShaderManager::destroy()
// ----------------------------------------------------------------------------
void GEVulkanShaderManager::loadAllShaders()
{
#ifndef DISABLE_SHADERC
irr::io::IFileList* files = g_file_system->createFileList(
getShaderFolder().c_str());
for (unsigned i = 0; i < files->getFileCount(); i++)
@ -122,12 +125,16 @@ void GEVulkanShaderManager::loadAllShaders()
});
}
files->drop();
#endif
} // loadAllShaders
// ----------------------------------------------------------------------------
VkShaderModule GEVulkanShaderManager::loadShader(shaderc_shader_kind kind,
const std::string& name)
{
#ifdef DISABLE_SHADERC
return VK_NULL_HANDLE;
#else
std::string shader_fullpath = getShaderFolder() + name;
irr::io::IReadFile* r = irr::io::createReadFile(shader_fullpath.c_str());
if (!r)
@ -238,6 +245,7 @@ VkShaderModule GEVulkanShaderManager::loadShader(shaderc_shader_kind kind,
shaderc_result_release(result);
shaderc_compiler_release(compiler);
return shader_module;
#endif
} // loadShader
// ----------------------------------------------------------------------------

View File

@ -3,7 +3,11 @@
#include "vulkan_wrapper.h"
#include <string>
#include <shaderc/shaderc.h>
#ifdef DISABLE_SHADERC
#define shaderc_shader_kind int
#else
#include <shaderc/shaderc.h>
#endif
namespace GE
{

View File

@ -1,5 +0,0 @@
---
# Use Google code formatting rules.
Language: Cpp
BasedOnStyle: Google
...

View File

@ -1,9 +0,0 @@
# This is the official list of shaderc authors for copyright purposes.
# This file is distinct from the CONTRIBUTORS files.
# See the latter for an explanation.
# Names should be added to this file as:
# Name or Organization <email address>
# The email address is not required for organizations.
Google Inc.

View File

@ -1,76 +0,0 @@
# Copyright 2020 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.
ROOT_SHADERC_PATH := $(call my-dir)
include $(ROOT_SHADERC_PATH)/third_party/Android.mk
include $(ROOT_SHADERC_PATH)/libshaderc_util/Android.mk
include $(ROOT_SHADERC_PATH)/libshaderc/Android.mk
ALL_LIBS:=libglslang.a \
libOGLCompiler.a \
libOSDependent.a \
libshaderc.a \
libshaderc_util.a \
libSPIRV.a \
libHLSL.a \
libSPIRV-Tools.a \
libSPIRV-Tools-opt.a
SHADERC_HEADERS=shaderc.hpp shaderc.h env.h status.h visibility.h
SHADERC_HEADERS_IN_OUT_DIR=$(foreach H,$(SHADERC_HEADERS),$(NDK_APP_LIBS_OUT)/../include/shaderc/$(H))
define gen_libshaderc_header
$(NDK_APP_LIBS_OUT)/../include/shaderc/$(1) : \
$(ROOT_SHADERC_PATH)/libshaderc/include/shaderc/$(1)
$(call host-mkdir,$(NDK_APP_LIBS_OUT)/../include/shaderc)
$(call host-cp,$(ROOT_SHADERC_PATH)/libshaderc/include/shaderc/$(1) \
,$(NDK_APP_LIBS_OUT)/../include/shaderc/$(1))
endef
define gen_libshaderc
$(1)/combine.ar: $(addprefix $(1)/, $(ALL_LIBS))
@echo "create libshaderc_combined.a" > $(1)/combine.ar
$(foreach lib,$(ALL_LIBS),
@echo "addlib $(lib)" >> $(1)/combine.ar
)
@echo "save" >> $(1)/combine.ar
@echo "end" >> $(1)/combine.ar
$(1)/libshaderc_combined.a: $(addprefix $(1)/, $(ALL_LIBS)) $(1)/combine.ar
@echo "[$(TARGET_ARCH_ABI)] Combine: libshaderc_combined.a <= $(ALL_LIBS)"
@cd $(1) && $(TARGET_AR) -M < combine.ar && cd $(ROOT_SHADERC_PATH)
@$(TARGET_STRIP) --strip-debug $(1)/libshaderc_combined.a
$(NDK_APP_LIBS_OUT)/$(APP_STL)/$(TARGET_ARCH_ABI)/libshaderc.a: \
$(1)/libshaderc_combined.a
$(call host-mkdir,$(NDK_APP_LIBS_OUT)/$(APP_STL)/$(TARGET_ARCH_ABI))
$(call host-cp,$(1)/libshaderc_combined.a \
,$(NDK_APP_LIBS_OUT)/$(APP_STL)/$(TARGET_ARCH_ABI)/libshaderc.a)
ifndef HEADER_TARGET
HEADER_TARGET=1
$(eval $(foreach H,$(SHADERC_HEADERS),$(call gen_libshaderc_header,$(H))))
endif
libshaderc_combined: \
$(NDK_APP_LIBS_OUT)/$(APP_STL)/$(TARGET_ARCH_ABI)/libshaderc.a
endef
libshaderc_combined: $(SHADERC_HEADERS_IN_OUT_DIR)
$(eval $(call gen_libshaderc,$(TARGET_OUT)))

View File

@ -1,101 +0,0 @@
# 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("//build_overrides/build.gni")
import("//build_overrides/shaderc.gni")
glslang_dir = shaderc_glslang_dir
spirv_tools_dir = shaderc_spirv_tools_dir
config("shaderc_util_public") {
include_dirs = [ "libshaderc_util/include" ]
}
source_set("shaderc_util_sources") {
sources = [
"libshaderc_util/include/libshaderc_util/counting_includer.h",
"libshaderc_util/include/libshaderc_util/exceptions.h",
"libshaderc_util/include/libshaderc_util/file_finder.h",
"libshaderc_util/include/libshaderc_util/format.h",
"libshaderc_util/include/libshaderc_util/io_shaderc.h",
"libshaderc_util/include/libshaderc_util/message.h",
"libshaderc_util/include/libshaderc_util/mutex.h",
"libshaderc_util/include/libshaderc_util/resources.h",
"libshaderc_util/include/libshaderc_util/spirv_tools_wrapper.h",
"libshaderc_util/include/libshaderc_util/string_piece.h",
"libshaderc_util/include/libshaderc_util/universal_unistd.h",
"libshaderc_util/include/libshaderc_util/version_profile.h",
"libshaderc_util/src/compiler.cc",
"libshaderc_util/src/file_finder.cc",
"libshaderc_util/src/io_shaderc.cc",
"libshaderc_util/src/message.cc",
"libshaderc_util/src/resources.cc",
"libshaderc_util/src/shader_stage.cc",
"libshaderc_util/src/spirv_tools_wrapper.cc",
"libshaderc_util/src/version_profile.cc",
]
# Configure Glslang's interface to include HLSL-related entry points.
defines = [ "ENABLE_HLSL=1" ]
public_configs = [ ":shaderc_util_public" ]
deps = [
"${glslang_dir}:glslang_sources",
"${spirv_tools_dir}:spvtools",
]
if (build_with_chromium) {
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [ "//build/config/compiler:no_chromium_code" ]
}
}
config("shaderc_public") {
include_dirs = [ "libshaderc/include" ]
if (is_component_build) {
defines = [ "SHADERC_SHAREDLIB" ]
}
}
component("libshaderc") {
public_configs = [
":shaderc_public",
":shaderc_util_public",
]
defines = [ "SHADERC_IMPLEMENTATION" ]
sources = [
"libshaderc/include/shaderc/env.h",
"libshaderc/include/shaderc/shaderc.h",
"libshaderc/include/shaderc/shaderc.hpp",
"libshaderc/include/shaderc/status.h",
"libshaderc/include/shaderc/visibility.h",
"libshaderc/src/shaderc.cc",
"libshaderc/src/shaderc_private.h",
]
deps = [
":shaderc_util_sources",
"${spirv_tools_dir}:spvtools",
"${spirv_tools_dir}:spvtools_val",
"${glslang_dir}:glslang_sources",
]
if (build_with_chromium) {
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [ "//build/config/compiler:no_chromium_code" ]
}
}

View File

@ -1,304 +0,0 @@
Revision history for Shaderc
v2022.1 2022-01-27
- Update DEPS to include two fixes on top of SPIRV-Tools v2022.1:
- Validator handles Nontemporal image operand
- Optimizer handles RayQueryKHR type
v2022.0 2022-01-27
- Update to Glslang 11.8.0
v2021.4 2022-01-27
- Support Vulkan 1.3
- Support targeting SPIR-V 1.6, which is the default for Vulkan 1.3
- Updated copyright check: Excludes Glslang generated files when
building in source tree
- Fix Android.mk rules for building libshaderc_combined, to adapt to more
recent NDKs that have removed the GNU binutils.
v2021.3 2021-11-11
- Add build switch to disable copyright check
- Update DEPS:
- SPIRV-Tools v2021.4
- SPIRV-Headers GitHub master 2021-11-11
- Glslang GitHub master 2021-11-11
v2021.2 2021-08-25
- README: Mention Common Lisp bindings (external)
- Update DEPS:
- SPIRV-Tools v2021.3
- SPIRV-Headers master 2021-08-25
- Glslang GitHub master 2021-08-25
v2021.1 2021-06-21
- Disable --target-env=opengl_compat with an explicit error message
- It has been deprecated for a long time.
v2021.0 2021-04-21
- Refresh dependencies (in DEPS):
- SPIRV-Tools v2021.1
- SPIRV-Headers snapshot 2021-04-21
- Glslang 11.2.0, snapshot 2021-04-21
- Fixes:
#1174: Windows Bazel support: rename internal headers io.* to io_shaderc.*
v2020.5 2021-02-19
- Refresh dependencies (in DEPS):
- SPIRV-Tools v2020.7 + 1 patch
- Glslang 11.1.0
- Add option to skip building examples
- Fixes:
#1153: Improve file+line parsing from Glslang messages
v2020.4 2020-12-09
- Removed svpc
- Fixed issues with embedders getting duplicate symbols
- Converted C-style casts to static_cast
- Rolled ahead to fix/pickup Vulkan Raytracing support
v2020.3 2020-09-02
- General:
- Last release with spvc
- Cleaned up issues discovered by Infer
- spvc:
- Added support for Dawn using deprecated Options constructor
- Adding support for the additional fixed sample mask in MSL
v2020.2 2020-07-23
- General:
- Remove VS2013 support
- Support both posix and non-posix MinGW toolchains
- Support optionally building Tint tooling for WGSL
- Add -h option to glslc, spvc; same as --help
- Add source file license checker
- BUILD.gn improvements
- glslc, libshaderc:
- Update to Glslang generator 9
- Add interface to support 16bit types in HLSL
- Add glslc hidden experimental option -mfmt=wgsl; requires Tint
- spvc:
- Add minimum buffer size for Dawn reflection
v2020.1 2020-06-09
This is the last version that officially supports VS2013.
- General:
- Added warning signs about unsupported downloads (#1041)
- Added .NET bindings to README.md (#1060)
- Only add -fPIC if supported by the compiler. (#1061)
- glslc, libshaderc:
- Removed Singleton pattern around access to glslang (#1059)
- spvc:
- Added concept of comparison sampler to API (#1036)
- Added support for options.hlsl.nonwritable_uav_texture_as_srv (#1048)
- Support forcing storage buffers to be always declared as UAV. (#1076)
v2020.0 2020-03-06
- General:
- Getting spirv.hpp from SPIRV-Headers instead of not glslang (#992)
- Added clarification about status of artifacts in downloads.md (#1012)
- glslc, libshaderc:
- Added support for new Glslang profile enum, EProfileCount (#973)
- Updated user documentation for -S in glslc (#978)
- Add documentation for Vulkan 1.2 and SPIR-V 1.5 (#980)
- Removed NV_EXTENSIONS conditionals (#1003)
- Added support for generating WebGPU SPIR-V to libshaderc (#1021)
- Rolled in all DEPS for provisional SPIR-V extensions for raytracing
- spvc:
- Normalized API behaviour (#967)
- Added source_set target for libshaderc_spvc (#976)
- Added in support for spvc logging to the terminal (#981)
- Internal refactoring to reduce boiler plate in API implementations (#984)
- Added newline to logging messages to make them readable (#985)
- Added reflection support for Dawn:
- storage textures (#1001)
- storage texture format (#1005)
- texture dimension for storage textures (#1008)
- is storage texture declared as multisampled texture (#1011)
- Converted compile options to require explicit environments (#1019)
- Added knob to control force_zero_initialized_variables in SPIRV-Cross (#1028)
v2019.1 2020-01-22
- glslc, libshaderc:
- Add -fnan-clamp: Generate code for max and min builtins so that,
given a NaN operand, will return the other operand. Similarly, the
clamp builtin favours non-NaN operands, as if clamp was implemented
as the composition of max and min.
- Add -finvert-y
- Using SetBeforeHlslLegalization for more relaxed validation rules
- Added support for SPIR-V 1.5
- Add --emit-line-directive option
- Added support for Vulkan 1.2
- spvc:
- Add many options:
--flatten-multidimensional-arrays
--es
--no-es
--glsl-emit-push-constant-as-ubo
--msl-swizzle-texture-samples
--msl-platform=ios|macos
--msl-pad-fragment-output
--msl-capture-output
--msl-domain-lower-left
--msl-argument-buffers
--msl-discrete-descriptor-set=<number>
--hlsl-enable-compat
- Reintroduce shaderc_spvc_compile_options_set_shader_model
- Added option to inject robust buffer access code
- Added support for emitting ToVulkan shaders
- Added spirv-opt based IR generation as alternative to built in spirv_cross IR gen
- Added API for specifying source and target execution environments
- Added option & reflection API methods neede by Dawn
- Substantial internal refactoring and code cleanup
- Large number of breaking changes to the API
- Replaced shaderc_spvc_compile_options_set_shader_model with
shaderc_spvc_compile_options_set_hlsl_shader_model
- Compiler initialization and shader generation moved into seperate calls
- Seperated return codes from shaderc ones
- Many small API changes
- Improvements to testing
- Refactoring and clean up of run_spirv_cross_tests.py
- Seperation of expectations into known failures, known invalids, and cases
that need investigation
- Tweaks and fixes to substantially increase passing cases
- Added support for running tests using spvc IR generation
- Infrastructure
- Update DEPS with cross-verified commits from associated repos.
- Add utils/roll-deps
- Infrastructure:
- Removed Appveyor artifacts link
- Improvements and clean up of DEPS rolling scripts
- Enabled warnings about implicit fallthrough
- Enabled improper semicolon warnings
- Restricted -fPIC to platforms that support it
- Converted remaining scripts to use Python 3
- Replaced nosetest with unittest
- Removed assumptions aabout location of spirv-tools, effcee, and RE2
- Migrated BUILD.gn spirv_cross dependency to local repo
- Fixes:
- Fix duplicate install paths when using VisualStudio
- Fixed BUILD.gn for Chromium, Dawn & Fuchsia
- Explicitly enabled HLSL support in glslang
- Added installing necessary headers in Android.mk
- Removed unsupported Unicode characters
- Fixed detection of spirv-headers directory
#666: Update Docker file to use Python3
v2019.0 2019-06-04
- Add optional spvc, libshaderc_spvc as wrapper around SPIRV-Cross:
- Rejects bad modules by running the SPIR-V validator first
- Skips exception-heavy SPIRV-Cross SPIR-V parser
- Support NV extensions for shader stages
- Require SPIRV-Tools and SPIRV-Headers with SPIR-V 1.4 support
Build support:
- Use KhronosGroup/glslang instead of google/glslang
- Stop running tests on VS 2013 (googletest no longer supports VS2013)
- Require Python3 for building
- Support Chromium's GN build system
- Kokoro build fixes
- Cmake build fixes: Only build subdirs if those targets are not yet defined
- Use Android.mk from Glslang
- Dockerfile gets re2 and effcee sources
- Fixes for newer googletest
- Add address sanitizer presubmit bot
- Generate config files for pkg-config
Spvc:
- Add option to specify source environment. Spvc will transform from source
to target environment if they are different. This only works for WebGPU0
and Vulkan 1.1.
Fixes:
#499: In HLSL compilation, relax layout and logical pointer validation rules
prior to running the legalization recipe.
v2018.0 2018-10-01
- Support -fhlsl_functionality1 (also -fhlsl-functionality1)
- Support NVIDIA Turing extensions. Requires updated Glslang and SPIRV-Tools.
- Use SPIR-V optimization and HLSL legalization recipes from SPIRV-Tools.
- Pass target environment into SPIRV-Tools code, e.g. from --target-env vulkan1.1
- Add SONAME=1 property to shared library
- Support GN build for Chromium
Fixes:
#469: Add virtual dtor to classes with virtual functions.
#457: Fix writing SPIR-V binaries to standard output on Windows.
v2017.2 2018-02-27
- Add a shared library version of libshaderc
- Support GLSL 4.6 and ESSL 3.2
- 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.
- HLSL compilation now defaults to HLSL packing rules.
(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 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.
v2017.1 2017-03-10
- Add option to automatically assign bindings to uniform variables
that don't have an explicit 'binding' layout in the shader source.
- Enable NVIDIA extensions by default in GLSL compilation
- README mentions language bindings provided by 3rd parties.
- README describes the known-good branch on GitHub
- Fixed examples in shaderc.h; added C API use to examples/online-compile
- Fixes issues:
#289: Don't output an object file when compilation fails.
#296: Enable use of the CMake in Android Studio.
v2016.2 2016-12-13
- Describe Shaderc's level of stability.
- Support HLSL compilation, exposing functionality in Glslang.
- Supported in C, C++ API
- glslc accepts "-x hlsl", and assumes .hlsl files are HLSL.
- glslc accepts "-fentry-point=<name>" to set entry point name,
overriding default value "main".
- Support setting shader resource limits in C, C++ APIs, and in
glslc
- glslc adds -flimit=<setting>
- glslc adds --show-limits to display defaults and valid resource
limit syntax.
- glslc adds "-flimit-file <file>" support to read Glslang resource
configuration files, i.e. the output of "glslangValidator -c".
- Enable AMD extensions by default in GLSL compilation
- Fixes issues:
#281: Work around Android build issue with abspath on Windows
#283: Increase default maxDrawBuffers to 4, to match Vulkan/GLES3.0
v2016.1 2016-10-12
- C API for assembling now takes an options object
- Support compilation options to optimize for size.
- Maintain compatibility with recent SPIRV-Tools and Glslang versions.
- Update examples.
- Build cleanups.
- Fixes issues:
#238: Fix invocation of python scripts during build
v2016.0 2016-07-07
- Adds v<year>.<index> versioning, with "-dev" suffix to indicate work in
progress. The intent is to summarize and report functionalities more easily
for incorporating into downstream projects.
- Summary of functionalities (See the README.md for more details):
- Provides libraries and command line tools for generating SPIR-V modules
- Supports GLSL source code or SPIR-V assembly as input
- Supports SPIR-V binary or assembly text as output
- Command line options follow GCC/Clang conventions
- Supports various semantics (OpenGL, OpenGL Compatible and Vulkan)
- Supports #include
- Supports user-defined macros
- Supports dependency information dumping

View File

@ -1,165 +0,0 @@
# Copyright 2020 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.
cmake_minimum_required(VERSION 2.8.12)
project(shaderc)
enable_testing()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
message(STATUS "No build type selected, default to Debug")
set(CMAKE_BUILD_TYPE "Debug")
endif()
message(STATUS "Shaderc: build type is \"${CMAKE_BUILD_TYPE}\".")
option(SHADERC_ENABLE_WGSL_OUTPUT "Enable WGSL output" OFF)
option(SHADERC_SKIP_INSTALL "Skip installation" ${SHADERC_SKIP_INSTALL})
if(NOT ${SHADERC_SKIP_INSTALL})
set(SHADERC_ENABLE_INSTALL ON)
endif()
option(SHADERC_SKIP_TESTS "Skip building tests" ${SHADERC_SKIP_TESTS})
if(NOT ${SHADERC_SKIP_TESTS})
set(SHADERC_ENABLE_TESTS ON)
endif()
if(${SHADERC_ENABLE_TESTS})
message(STATUS "Configuring Shaderc to build tests.")
else()
message(STATUS "Configuring Shaderc to avoid building tests.")
endif()
option(SHADERC_SKIP_EXAMPLES "Skip building examples" ${SHADERC_SKIP_EXAMPLES})
if(NOT ${SHADERC_SKIP_EXAMPLES})
set(SHADERC_ENABLE_EXAMPLES ON)
endif()
if(${SHADERC_ENABLE_EXAMPLES})
message(STATUS "Configuring Shaderc to build examples.")
else()
message(STATUS "Configuring Shaderc to avoid building examples.")
endif()
option(SHADERC_SKIP_COPYRIGHT_CHECK "Skip copyright check" ${SHADERC_SKIP_COPYRIGHT_CHECK})
if(NOT ${SHADERC_SKIP_COPYRIGHT_CHECK})
set(SHADERC_ENABLE_COPYRIGHT_CHECK ON)
endif()
if(${SHADERC_ENABLE_COPYRIGHT_CHECK})
message(STATUS "Configuring Shaderc to check copyrights.")
else()
message(STATUS "Configuring Shaderc to avoid checking copyrights.")
endif()
option(SHADERC_ENABLE_WERROR_COMPILE "Enable passing -Werror to compiler, if available" ON)
set (CMAKE_CXX_STANDARD 11)
include(GNUInstallDirs)
include(cmake/setup_build.cmake)
include(cmake/utils.cmake)
include(CheckCXXCompilerFlag)
set(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS ${DISABLE_EXCEPTIONS} CACHE BOOL "Coupling SPIRV-Cross exception conversion to DISABLE_EXCEPTIONS" FORCE)
if(DISABLE_EXCEPTIONS)
# Need to set additional values here, since some of the wrapped code occurs in
# .h/.hpp files, so maybe included outside of the library.
add_definitions(-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
endif()
# These flags are not supported on Windows and some older version of GCC
# that our bots use.
# Warning about implicit fallthrough in switch blocks
check_cxx_compiler_flag(-Wimplicit-fallthrough COMPILER_SUPPORTS_FALLTHROUGH_WARNING)
if (COMPILER_SUPPORTS_FALLTHROUGH_WARNING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wimplicit-fallthrough")
endif()
# Warning about extra semi-colons
check_cxx_compiler_flag(-Wextra-semi COMPILER_SUPPORTS_EXTRA_SEMI_WARNING)
if (COMPILER_SUPPORTS_EXTRA_SEMI_WARNING)
add_compile_options("-Wextra-semi")
endif()
find_host_package(PythonInterp 3 REQUIRED)
if (SHADERC_ENABLE_COPYRIGHT_CHECK)
add_custom_target(check-copyright ALL
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/utils/add_copyright.py
--check
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Check copyright")
endif()
add_custom_target(add-copyright
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/utils/add_copyright.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Add copyright")
if(MSVC)
option(SHADERC_ENABLE_SHARED_CRT
"Use the shared CRT instead of the static CRT"
${SHADERC_ENABLE_SHARED_CRT})
if (NOT SHADERC_ENABLE_SHARED_CRT)
# Link executables statically by replacing /MD with /MT everywhere.
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
endif(NOT SHADERC_ENABLE_SHARED_CRT)
endif(MSVC)
# Configure subdirectories.
# We depend on these for later projects, so they should come first.
add_subdirectory(third_party)
add_subdirectory(libshaderc_util)
add_subdirectory(libshaderc)
if(${SHADERC_ENABLE_EXAMPLES})
add_subdirectory(examples)
endif()
add_custom_target(build-version
${PYTHON_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/utils/update_build_version.py
${shaderc_SOURCE_DIR} ${spirv-tools_SOURCE_DIR} ${glslang_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/build-version.inc
COMMENT "Update build-version.inc in the Shaderc build directory (if necessary).")
function(define_pkg_config_file NAME LIBS)
add_custom_target(${NAME}-pkg-config ALL
COMMAND ${CMAKE_COMMAND}
-DCHANGES_FILE=${CMAKE_CURRENT_SOURCE_DIR}/CHANGES
-DTEMPLATE_FILE=${CMAKE_CURRENT_SOURCE_DIR}/cmake/${NAME}.pc.in
-DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/${NAME}.pc
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
-DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}
-DLIBS=${LIBS}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/write_pkg_config.cmake
DEPENDS "CHANGES" "cmake/${NAME}.pc.in" "cmake/write_pkg_config.cmake")
if (SHADERC_ENABLE_INSTALL)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${NAME}.pc
DESTINATION
${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()
endfunction()
define_pkg_config_file(shaderc -lshaderc_shared)
define_pkg_config_file(shaderc_static "-lshaderc ${EXTRA_STATIC_PKGCONFIG_LIBS} -lshaderc_util")
define_pkg_config_file(shaderc_combined -lshaderc_combined)

View File

@ -1,25 +0,0 @@
Want to contribute? Great! First, read this page (including the small print at
the end). Then, have a look at [`DEVELOPMENT.howto.md`](DEVELOPMENT.howto.md),
which contains useful info to guide you along the way.
## Before you contribute
Before we can use your code, you must sign the
[Google Individual Contributor License Agreement](https://developers.google.com/open-source/cla/individual?csw=1)
(CLA), which you can do online. The CLA is necessary mainly because you own the
copyright to your changes, even after your contribution becomes part of our
codebase, so we need your permission to use and distribute your code. We also
need to be sure of various other things -- for instance that you'll tell us if
you know that your code infringes on other people's patents. You don't have to
sign the CLA until after you've submitted your code for review and a member has
approved it, but you must do it before we can put your code into our codebase.
Before you start working on a larger contribution, you should get in touch with
us first through the issue tracker with your idea so that we can help out and
possibly guide you. Coordinating up front makes it much easier to avoid
frustration later on.
## The small print
Contributions made by corporations are covered by a different agreement than
the one above, the Software Grant and Corporate Contributor License Agreement.

View File

@ -1,24 +0,0 @@
# People who have agreed to one of the CLAs and can contribute patches.
# The AUTHORS file lists the copyright holders; this file
# lists people. For example, Google employees are listed here
# but not in AUTHORS, because Google holds the copyright.
#
# https://developers.google.com/open-source/cla/individual
# https://developers.google.com/open-source/cla/corporate
#
# Names should be added to this file as:
# Name <email address>
Lei Zhang <antiagainst@google.com>
David Neto <dneto@google.com>
Andrew Woloszyn <awoloszyn@google.com>
Stefanus Du Toit <sdt@google.com>
Dejan Mircevski <deki@google.com>
Mark Adams <marka@nvidia.com>
Jason Ekstrand <jason.ekstrand@intel.com>
Damien Mabin <dmabin@google.com>
Qining Lu <qining@google.com>
Jakob Vogel <JakobpunktVogel@gmail.com>
David Yen <dyen@google.com>
Adam Chainz <adam@adamj.eu>
Robin Quint <robin.quint@outlook.com>

View File

@ -1,33 +0,0 @@
use_relative_paths = True
vars = {
'google_git': 'https://github.com/google',
'khronos_git': 'https://github.com/KhronosGroup',
'effcee_revision' : '2ec8f8738118cc483b67c04a759fee53496c5659',
'glslang_revision': 'c34bb3b6c55f6ab084124ad964be95a699700d34',
'googletest_revision': '389cb68b87193358358ae87cc56d257fd0d80189',
're2_revision': '7107ebc4fbf7205151d8d2a57b2fc6e7853125d4',
'spirv_headers_revision': 'b42ba6d92faf6b4938e6f22ddd186dbdacc98d78',
'spirv_tools_revision': 'b846f8f1dc2d79f2b5ce27d5ad901f885da1cf82',
}
deps = {
'third_party/effcee': Var('google_git') + '/effcee.git@' +
Var('effcee_revision'),
'third_party/googletest': Var('google_git') + '/googletest.git@' +
Var('googletest_revision'),
'third_party/glslang': Var('khronos_git') + '/glslang.git@' +
Var('glslang_revision'),
'third_party/re2': Var('google_git') + '/re2.git@' +
Var('re2_revision'),
'third_party/spirv-headers': Var('khronos_git') + '/SPIRV-Headers.git@' +
Var('spirv_headers_revision'),
'third_party/spirv-tools': Var('khronos_git') + '/SPIRV-Tools.git@' +
Var('spirv_tools_revision'),
}

View File

@ -1,52 +0,0 @@
Thank you for considering Shaderc development! Please make sure you review
[`CONTRIBUTING.md`](CONTRIBUTING.md) for important preliminary info.
## Building
Instructions for first-time building can be found in [`README.md`](README.md).
Incremental build after a source change can be done using `ninja` (or
`cmake --build`) and `ctest` exactly as in the first-time procedure.
## Code reviews
(Terminology: we consider everyone with write access to our GitHub repo a
project _member_.)
All submissions, including submissions by project members, require review. We
use GitHub pull requests to facilitate the review process. A submission may be
accepted by any project member (other than the submitter), who will then squash
the changes into a single commit and cherry-pick them into the repository.
Before accepting, there may be some review feedback prompting changes in the
submission. You should expect reviewers to strictly insist on the
[commenting](https://google.github.io/styleguide/cppguide.html#Comments)
guidelines -- in particular, every file, class, method, data member, and global
will require a comment. Reviewers will also expect to see test coverage for
every code change. _How much_ coverage will be a judgment call on a
case-by-case basis, balancing the required effort against the incremental
benefit. Coverage will be expected. As a matter of development philosophy,
we will strive to engineer the code to make writing tests easy.
## Coding style
For our C++ files, we use the
[Google C++ style guide](https://google.github.io/styleguide/cppguide.html).
(Conveniently, the formatting rules it specifies can be achieved using
`clang-format -style=google`.)
For our Python files, we use the
[Google Python style guide](https://google.github.io/styleguide/pyguide.html).
## Supported platforms
We expect Shaderc to always build and test successfully on the platforms listed
below. Please keep that in mind when offering contributions. This list will
likely grow over time.
| Platform | Build Status |
|:--------:|:------------:|
| Android (ARMv7) | Not Automated |
| Linux (x86_64) | [![Linux Build Status](https://travis-ci.org/google/shaderc.svg)](https://travis-ci.org/google/shaderc "Linux Build Status") |
| Mac OS X | [![Mac Build Status](https://travis-ci.org/google/shaderc.svg)](https://travis-ci.org/google/shaderc "Mac Build Status") |
| Windows (x86_64) | [![Windows Build status](https://ci.appveyor.com/api/projects/status/g6c372blna7vnk1l?svg=true)](https://ci.appveyor.com/project/dneto0/shaderc "Windows Build Status") |

View File

@ -1,50 +0,0 @@
# Copyright 2016 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.
FROM alpine
MAINTAINER Google Shaderc Team
RUN apk add --update \
build-base \
cmake \
git \
ninja \
python3 \
py-pip \
&& rm -rf /var/cache/apk/*
WORKDIR /root
RUN git clone https://github.com/google/shaderc
WORKDIR shaderc
RUN ./utils/git-sync-deps
WORKDIR build
RUN cmake -GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local \
.. \
&& ninja install
WORKDIR /root
RUN rm -rf shaderc
RUN adduser -s /bin/sh -D shaderc
USER shaderc
VOLUME /code
WORKDIR /code
CMD ["/bin/sh"]

View File

@ -1,201 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.

View File

@ -1,262 +0,0 @@
# Shaderc
A collection of tools, libraries and tests for shader compilation.
At the moment it includes:
- [`glslc`](glslc), a command line compiler for GLSL/HLSL to SPIR-V, and
- [`libshaderc`](libshaderc), a library API for accessing `glslc` functionality.
**Note:** The fact that that `libshaderc` is not named `libshaderc_glslc` is a
quirk of history, and a known inconsistency. Changing it would require a
significant amount of renaming and breaking of downstream projects, so it is
being left as is.
`glslc` wraps around core functionality in [glslang][khr-glslang]
and [SPIRV-Tools][spirv-tools]. `glslc` and its library aims to
to provide:
* a command line compiler with GCC- and Clang-like usage, for better
integration with build systems
* an API where functionality can be added without breaking existing clients
* an API supporting standard concurrency patterns across multiple
operating systems
* increased functionality such as file `#include` support
## Downloads
**Note: These binaries are just the artifacts of the builders and have not
undergone any QA, thus they should be considered unsupported.**
<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_clang_release.svg)](https://storage.googleapis.com/shaderc/badges/build_link_linux_clang_release.html)
<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_clang_release.svg)](https://storage.googleapis.com/shaderc/badges/build_link_macos_clang_release.html)
<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_vs2017_release.svg)](https://storage.googleapis.com/shaderc/badges/build_link_windows_vs2017_release.html)
[More downloads](downloads.md)
## Status
Shaderc has maintained backward compatibility for quite some time, and we
don't anticipate any breaking changes.
Ongoing enhancements are described in the [CHANGES](CHANGES) file.
Shaderc has been shipping in the
[Android NDK](https://developer.android.com/ndk/index.html) since version r12b.
(The NDK build uses sources from https://android.googlesource.com/platform/external/shaderc/.
Those repos are downstream from GitHub.)
We currently require r18b.
For licensing terms, please see the [`LICENSE`](LICENSE) file. If interested in
contributing to this project, please see [`CONTRIBUTING.md`](CONTRIBUTING.md).
This is not an official Google product (experimental or otherwise), it is just
code that happens to be owned by Google. That may change if Shaderc gains
contributions from others. See the [`CONTRIBUTING.md`](CONTRIBUTING.md) file
for more information. See also the [`AUTHORS`](AUTHORS) and
[`CONTRIBUTORS`](CONTRIBUTORS) files.
## File organization
- `android_test/` : a small Android application to verify compilation
- `cmake/`: CMake utility functions and configuration for Shaderc
- `examples/`: Example programs
- `glslc/`: an executable to compile GLSL to SPIR-V
- `libshaderc/`: a library for compiling shader strings into SPIR-V
- `libshaderc_util/`: a utility library used by multiple shaderc components
- `third_party/`: third party open source packages; see below
- `utils/`: utility scripts for Shaderc
Shaderc depends on glslang, the Khronos reference compiler for GLSL.
Shaderc depends on [SPIRV-Tools][spirv-tools] for assembling, disassembling,
and transforming SPIR-V binaries.
Shaderc depends on the [Google Test](https://github.com/google/googletest)
testing framework.
In the following sections, `$SOURCE_DIR` is the directory you intend to clone
Shaderc into.
## Getting and building Shaderc
**If you only want prebuilt executables or libraries, see the
[Downloads](#downloads) section.**
The rest of this section describes how to build Shaderc from sources.
Note: Shaderc assumes Glslang supports HLSL compilation. The instructions
below assume you're building Glslang from sources, and in a subtree
of `shaderc/third_party`. In that scenario, Glslang's HLSL support
is automatically enabled. Shaderc also can be built using a Glslang
from outside the `shaderc/third_party` tree. In that case you must
ensure that that external Glslang is built with HLSL functionality.
See Glslang's `ENABLE_HLSL` CMake setting.)
1) Check out the source code:
```sh
git clone https://github.com/google/shaderc $SOURCE_DIR
cd $SOURCE_DIR
./utils/git-sync-deps
```
**Note:** The [known-good](https://github.com/google/shaderc/tree/known-good)
branch of the repository contains a
[known_good.json](https://github.com/google/shaderc/blob/known-good/known_good.json)
file describing a set of repo URLs and specific commits that have been
tested together. This information is updated periodically, and typically
matches the latest update of these sources in the development branch
of the Android NDK.
The `known-good` branch also contains a
[update_shaderc.py](https://github.com/google/shaderc/blob/known-good/update_shaderc_sources.py)
script that will read the JSON file and checkout those specific commits for you.
2) Ensure you have the requisite tools -- see the tools subsection below.
3) Decide where to place the build output. In the following steps, we'll call it
`$BUILD_DIR`. Any new directory should work. We recommend building outside
the source tree, but it is also common to build in a (new) subdirectory of
`$SOURCE_DIR`, such as `$SOURCE_DIR/build`.
4a) Build (and test) with Ninja on Linux or Windows:
```sh
cd $BUILD_DIR
cmake -GNinja -DCMAKE_BUILD_TYPE={Debug|Release|RelWithDebInfo} $SOURCE_DIR
ninja
ctest # optional
```
4b) Or build (and test) with MSVC on Windows:
```sh
cd $BUILD_DIR
cmake $SOURCE_DIR
cmake --build . --config {Release|Debug|MinSizeRel|RelWithDebInfo}
ctest -C {Release|Debug|MinSizeRel|RelWithDebInfo}
```
4c) Or build with MinGW on Linux for Windows:
(Skip building threaded unit tests due to
[Googletest bug 606](https://github.com/google/googletest/issues/606))
```sh
cd $BUILD_DIR
cmake -GNinja -DCMAKE_BUILD_TYPE={Debug|Release|RelWithDebInfo} $SOURCE_DIR \
-DCMAKE_TOOLCHAIN_FILE=$SOURCE_DIR/cmake/linux-mingw-toolchain.cmake \
-Dgtest_disable_pthreads=ON
ninja
```
After a successful build, you should have a `glslc` executable somewhere under
the `$BUILD_DIR/glslc/` directory, as well as a `libshaderc` library somewhere
under the `$BUILD_DIR/libshaderc/` directory.
The default behavior on MSVC is to link with the static CRT. If you would like
to change this behavior `-DSHADERC_ENABLE_SHARED_CRT` may be passed on the
cmake configure line.
See [the libshaderc README](libshaderc/README.md) for more on using the library
API in your project.
### Tools you'll need
For building, testing, and profiling Shaderc, the following tools should be
installed regardless of your OS:
- [CMake](http://www.cmake.org/): for generating compilation targets.
- [Python 3](http://www.python.org/): for utility scripts and running the test suite.
On Linux, the following tools should be installed:
- [`gcov`](https://gcc.gnu.org/onlinedocs/gcc/Gcov.html): for testing code
coverage, provided by the `gcc` package on Ubuntu.
- [`lcov`](http://ltp.sourceforge.net/coverage/lcov.php): a graphical frontend
for `gcov`, provided by the `lcov` package on Ubuntu.
- [`genhtml`](http://linux.die.net/man/1/genhtml): for creating reports in html
format from `lcov` output, provided by the `lcov` package on Ubuntu.
On Linux, if cross compiling to Windows:
- [`mingw`](http://www.mingw.org): A GCC-based cross compiler targeting Windows
so that generated executables use the Microsoft C runtime libraries.
On Windows, the following tools should be installed and available on your path:
- Visual Studio 2015 or later. Previous versions of Visual Studio may work but
are untested and unsupported.
- Git - including the associated tools, Bash, `diff`.
Optionally, the following tools may be installed on any OS:
- [`asciidoctor`](http://asciidoctor.org/): for generating documentation.
- [`pygments.rb`](https://rubygems.org/gems/pygments.rb) required by
`asciidoctor` for syntax highlighting.
### Building and running Shaderc using Docker
Please make sure you have the Docker engine
[installed](https://docs.docker.com/engine/installation/) on your machine.
To create a Docker image containing Shaderc command line tools, issue the
following command in `${SOURCE_DIR}`: `docker build -t <IMAGE-NAME> .`.
The created image will have all the command line tools installed at
`/usr/local` internally, and a data volume mounted at `/code`.
Assume `<IMAGE-NAME>` is `shaderc/shaderc` from now on.
To invoke a tool from the above created image in a Docker container:
```bash
docker run shaderc/shaderc glslc --version
```
Alternatively, you can mount a host directory (e.g., `example`) containing
the shaders you want to manipulate and run different kinds of tools via
an interactive shell in the container:
```bash
$ docker run -i -t -v `pwd`/example:/code shaderc/shaderc
/code $ ls
test.vert
/code $ glslc -c -o - test.vert | spirv-dis
```
## Bug tracking
We track bugs using GitHub -- click on the "Issues" button on
[the project's GitHub page](https://github.com/google/shaderc).
## Test coverage
On Linux, you can obtain test coverage as follows:
```sh
cd $BUILD_DIR
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DENABLE_CODE_COVERAGE=ON $SOURCE_DIR
ninja
ninja report-coverage
```
Then the coverage report can be found under the `$BUILD_DIR/coverage-report`
directory.
## Bindings
Bindings are maintained by third parties, may contain content
offered under a different license, and may reference or contain
older versions of Shaderc and its dependencies.
* **Python:** [pyshaderc][pyshaderc]
* **Rust:** [shaderc-rs][shaderc-rs]
* **Go:** [gshaderc][gshaderc]
* **.NET:** [shaderc.net][shadercdotnet]
* **Common Lisp:** [shadercl][shaderccommonlisp]
[khr-glslang]: https://github.com/KhronosGroup/glslang
[spirv-tools]: https://github.com/KhronosGroup/SPIRV-Tools
[spirv-cross]: https://github.com/KhronosGroup/SPIRV-Cross
[pyshaderc]: https://github.com/realitix/pyshaderc
[shaderc-rs]: https://github.com/google/shaderc-rs
[appveyor]: https://ci.appveyor.com/project/dneto0/shaderc
[dawn]: https://dawn.googlesource.com/dawn
[gshaderc]: https://github.com/celer/gshaderc
[shadercdotnet]: https://github.com/jpbruyere/shaderc.net
[shaderccommonlisp]: https://github.com/JolifantoBambla/shadercl

View File

@ -1,39 +0,0 @@
# Copyright 2020 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.
SET(CMAKE_SYSTEM_NAME Windows)
set(MINGW_COMPILER_PREFIX "i686-w64-mingw32" CACHE STRING
"What compiler prefix to use for mingw")
set(MINGW_SYSROOT "/usr/${MINGW_COMPILER_PREFIX}" CACHE STRING
"What sysroot to use for mingw")
# Which compilers to use for C and C++
find_program(CMAKE_RC_COMPILER NAMES ${MINGW_COMPILER_PREFIX}-windres)
find_program(CMAKE_C_COMPILER NAMES
${MINGW_COMPILER_PREFIX}-gcc-posix
${MINGW_COMPILER_PREFIX}-gcc)
find_program(CMAKE_CXX_COMPILER NAMES
${MINGW_COMPILER_PREFIX}-g++-posix
${MINGW_COMPILER_PREFIX}-g++)
SET(CMAKE_FIND_ROOT_PATH ${MINGW_SYSROOT})
# Adjust the default behaviour of the FIND_XXX() commands:
# Search headers and libraries in the target environment; search
# programs in the host environment.
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

View File

@ -1,141 +0,0 @@
# Copyright 2020 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.
if(NOT COMMAND find_host_package)
macro(find_host_package)
find_package(${ARGN})
endmacro()
endif()
if(NOT COMMAND find_host_program)
macro(find_host_program)
find_program(${ARGN})
endmacro()
endif()
# Find asciidoctor; see shaderc_add_asciidoc() from utils.cmake for
# adding documents.
#find_program(ASCIIDOCTOR_EXE NAMES asciidoctor)
#if (NOT ASCIIDOCTOR_EXE)
# message(STATUS "asciidoctor was not found - no documentation will be"
# " generated")
#endif()
# On Windows, CMake by default compiles with the shared CRT.
# Ensure that gmock compiles the same, otherwise failures will occur.
if(WIN32)
# TODO(awoloszyn): Once we support selecting CRT versions,
# make sure this matches correctly.
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif(WIN32)
if (ANDROID)
# For android let's preemptively find the correct packages so that
# child projects (glslang, googletest) do not fail to find them.
# Tests in glslc and SPIRV-Tools tests require Python 3, or a Python 2
# with the "future" package. Require Python 3 because we can't force
# developers to manually install the "future" package.
find_host_package(PythonInterp 3 REQUIRED)
find_host_package(BISON)
else()
find_package(PythonInterp 3 REQUIRED)
endif()
option(ENABLE_CODE_COVERAGE "Enable collecting code coverage." OFF)
if (ENABLE_CODE_COVERAGE)
message(STATUS "Shaderc: code coverage report is on.")
if (NOT UNIX)
message(FATAL_ERROR "Code coverage on non-UNIX system not supported yet.")
endif()
if (NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message(FATAL_ERROR "Code coverage with non-Debug build can be misleading.")
endif()
find_program(LCOV_EXE NAMES lcov)
if (NOT LCOV_EXE)
message(FATAL_ERROR "lcov was not found")
endif()
find_program(GENHTML_EXE NAMES genhtml)
if (NOT GENHTML_EXE)
message(FATAL_ERROR "genhtml was not found")
endif()
set(LCOV_BASE_DIR ${CMAKE_BINARY_DIR})
set(LCOV_INFO_FILE ${LCOV_BASE_DIR}/lcov.info)
set(COVERAGE_STAT_HTML_DIR ${LCOV_BASE_DIR}/coverage-report)
add_custom_target(clean-coverage
# Remove all gcov .gcda files in the directory recursively.
COMMAND ${LCOV_EXE} --directory . --zerocounters -q
# Remove all lcov .info files.
COMMAND ${CMAKE_COMMAND} -E remove ${LCOV_INFO_FILE}
# Remove all html report files.
COMMAND ${CMAKE_COMMAND} -E remove_directory ${COVERAGE_STAT_HTML_DIR}
# TODO(antiagainst): the following two commands are here to remedy the
# problem of "reached unexpected end of file" experienced by lcov.
# The symptom is that some .gcno files are wrong after code change and
# recompiling. We don't know the exact reason yet. Figure it out.
# Remove all .gcno files in the directory recursively.
COMMAND ${PYTHON_EXECUTABLE}
${shaderc_SOURCE_DIR}/utils/remove-file-by-suffix.py . ".gcno"
# .gcno files are not tracked by CMake. So no recompiling is triggered
# even if they are missing. Unfortunately, we just removed all of them
# in the above.
COMMAND ${CMAKE_COMMAND} --build . --target clean
WORKING_DIRECTORY ${LCOV_BASE_DIR}
COMMENT "Clean coverage files"
)
add_custom_target(report-coverage
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}
# Run all tests.
COMMAND ctest --output-on-failure
# Collect coverage data from gcov .gcda files.
COMMAND ${LCOV_EXE} --directory . --capture -o ${LCOV_INFO_FILE}
# Remove coverage info for system header files.
COMMAND ${LCOV_EXE}
--remove ${LCOV_INFO_FILE} '/usr/include/*' -o ${LCOV_INFO_FILE}
# Remove coverage info for external and third_party code.
COMMAND ${LCOV_EXE}
--remove ${LCOV_INFO_FILE} '${shaderc_SOURCE_DIR}/ext/*'
-o ${LCOV_INFO_FILE}
COMMAND ${LCOV_EXE}
--remove ${LCOV_INFO_FILE} '${shaderc_SOURCE_DIR}/third_party/*'
-o ${LCOV_INFO_FILE}
# Remove coverage info for tests.
COMMAND ${LCOV_EXE}
--remove ${LCOV_INFO_FILE} '*_test.cc' -o ${LCOV_INFO_FILE}
# Generate html report file.
COMMAND ${GENHTML_EXE}
${LCOV_INFO_FILE} -t "Coverage Report" -o ${COVERAGE_STAT_HTML_DIR}
DEPENDS clean-coverage
WORKING_DIRECTORY ${LCOV_BASE_DIR}
COMMENT "Collect and analyze coverage data"
)
endif()
option(DISABLE_RTTI "Disable RTTI in builds")
if(DISABLE_RTTI)
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
endif(UNIX)
endif(DISABLE_RTTI)
option(DISABLE_EXCEPTIONS "Disables exceptions in builds")
if(DISABLE_EXCEPTIONS)
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
endif(UNIX)
endif(DISABLE_EXCEPTIONS)

View File

@ -1,12 +0,0 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: shaderc
Description: Tools and libraries for Vulkan shader compilation
Version: @CURRENT_VERSION@
URL: https://github.com/google/shaderc
Libs: -L${libdir} @LIBS@
Cflags: -I${includedir}

View File

@ -1,12 +0,0 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: shaderc
Description: Tools and libraries for Vulkan shader compilation
Version: @CURRENT_VERSION@
URL: https://github.com/google/shaderc
Libs: -L${libdir} @LIBS@
Cflags: -I${includedir}

View File

@ -1,12 +0,0 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: shaderc
Description: Tools and libraries for Vulkan shader compilation
Version: @CURRENT_VERSION@
URL: https://github.com/google/shaderc
Libs: -L${libdir} @LIBS@
Cflags: -I${includedir}

View File

@ -1,229 +0,0 @@
# Copyright 2020 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.
# utility functions
function (shaderc_use_gmock TARGET)
target_include_directories(${TARGET} PRIVATE
${gmock_SOURCE_DIR}/include
${gtest_SOURCE_DIR}/include)
target_link_libraries(${TARGET} PRIVATE gmock gtest_main)
endfunction(shaderc_use_gmock)
function(shaderc_default_c_compile_options TARGET)
if (NOT "${MSVC}")
if (SHADERC_ENABLE_WERROR_COMPILE)
target_compile_options(${TARGET} PRIVATE -Wall -Werror -fvisibility=hidden)
else()
target_compile_options(${TARGET} PRIVATE -Wall -fvisibility=hidden)
endif()
check_cxx_compiler_flag(-fPIC COMPILER_SUPPORTS_PIC)
if (NOT "${MINGW}" AND COMPILER_SUPPORTS_PIC)
target_compile_options(${TARGET} PRIVATE -fPIC)
endif()
if (ENABLE_CODE_COVERAGE)
# The --coverage option is a synonym for -fprofile-arcs -ftest-coverage
# when compiling.
target_compile_options(${TARGET} PRIVATE -g -O0 --coverage)
# The --coverage option is a synonym for -lgcov when linking for gcc.
# For clang, it links in a different library, libclang_rt.profile, which
# requires clang to be built with compiler-rt.
target_link_libraries(${TARGET} PRIVATE --coverage)
endif()
if (NOT SHADERC_ENABLE_SHARED_CRT)
if (WIN32)
# For MinGW cross compile, statically link to the libgcc runtime.
# But it still depends on MSVCRT.dll.
set_target_properties(${TARGET} PROPERTIES
LINK_FLAGS "-static -static-libgcc")
endif(WIN32)
endif(NOT SHADERC_ENABLE_SHARED_CRT)
else()
# disable warning C4800: 'int' : forcing value to bool 'true' or 'false'
# (performance warning)
target_compile_options(${TARGET} PRIVATE /wd4800)
endif()
endfunction(shaderc_default_c_compile_options)
function(shaderc_default_compile_options TARGET)
shaderc_default_c_compile_options(${TARGET})
if (NOT "${MSVC}")
target_compile_options(${TARGET} PRIVATE -std=c++11)
if (NOT SHADERC_ENABLE_SHARED_CRT)
if (WIN32)
# For MinGW cross compile, statically link to the C++ runtime.
# But it still depends on MSVCRT.dll.
set_target_properties(${TARGET} PROPERTIES
LINK_FLAGS "-static -static-libgcc -static-libstdc++")
endif(WIN32)
endif(NOT SHADERC_ENABLE_SHARED_CRT)
endif()
endfunction(shaderc_default_compile_options)
# Build an asciidoc file; additional arguments past the base filename specify
# additional dependencies for the file.
function(shaderc_add_asciidoc TARGET FILE)
if (ASCIIDOCTOR_EXE)
set(DEST ${CMAKE_CURRENT_BINARY_DIR}/${FILE}.html)
add_custom_command(
COMMAND ${ASCIIDOCTOR_EXE} -a toc -o ${DEST}
${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.asciidoc
DEPENDS ${FILE}.asciidoc ${ARGN}
OUTPUT ${DEST})
# Create the target, but the default build target does not depend on it.
# Some Asciidoctor installations are mysteriously broken, and it's hard
# to detect those cases. Generating HTML is not critical by default.
add_custom_target(${TARGET} DEPENDS ${DEST})
endif(ASCIIDOCTOR_EXE)
endfunction()
# Adds a set of tests.
# This function accepts the following parameters:
# TEST_PREFIX: a prefix for each test target name
# TEST_NAMES: a list of test names where each TEST_NAME has a corresponding
# file residing at src/${TEST_NAME}_test.cc
# LINK_LIBS: (optional) a list of libraries to be linked to the test target
# INCLUDE_DIRS: (optional) a list of include directories to be searched
# for header files.
function(shaderc_add_tests)
if(${SHADERC_ENABLE_TESTS})
cmake_parse_arguments(PARSED_ARGS
""
"TEST_PREFIX"
"TEST_NAMES;LINK_LIBS;INCLUDE_DIRS"
${ARGN})
if (NOT PARSED_ARGS_TEST_NAMES)
message(FATAL_ERROR "Tests must have a target")
endif()
if (NOT PARSED_ARGS_TEST_PREFIX)
message(FATAL_ERROR "Tests must have a prefix")
endif()
foreach(TARGET ${PARSED_ARGS_TEST_NAMES})
set(TEST_NAME ${PARSED_ARGS_TEST_PREFIX}_${TARGET}_test)
add_executable(${TEST_NAME} src/${TARGET}_test.cc)
shaderc_default_compile_options(${TEST_NAME})
if (MINGW)
target_compile_options(${TEST_NAME} PRIVATE -DSHADERC_DISABLE_THREADED_TESTS)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# Disable this warning, which is useless in test code.
# Fixes https://github.com/google/shaderc/issues/334
target_compile_options(${TEST_NAME} PRIVATE -Wno-noexcept-type)
endif()
if (PARSED_ARGS_LINK_LIBS)
target_link_libraries(${TEST_NAME} PRIVATE
${PARSED_ARGS_LINK_LIBS})
endif()
if (PARSED_ARGS_INCLUDE_DIRS)
target_include_directories(${TEST_NAME} PRIVATE
${PARSED_ARGS_INCLUDE_DIRS})
endif()
shaderc_use_gmock(${TEST_NAME})
add_test(
NAME ${PARSED_ARGS_TEST_PREFIX}_${TARGET}
COMMAND ${TEST_NAME})
endforeach()
endif(${SHADERC_ENABLE_TESTS})
endfunction(shaderc_add_tests)
# Finds all transitive static library dependencies of a given target
# including possibly the target itself.
# This will skip libraries that were statically linked that were not
# built by CMake, for example -lpthread.
macro(shaderc_get_transitive_libs target out_list)
if (TARGET ${target})
get_target_property(libtype ${target} TYPE)
# If this target is a static library, get anything it depends on.
if ("${libtype}" STREQUAL "STATIC_LIBRARY")
# Get the original library if this is an alias library. This is
# to avoid putting both the original library and the alias library
# in the list (given we are deduplicating according to target names).
# Otherwise, we may pack the same library twice, resulting in
# duplicated symbols.
get_target_property(aliased_target ${target} ALIASED_TARGET)
if (aliased_target)
list(INSERT ${out_list} 0 "${aliased_target}")
else()
list(INSERT ${out_list} 0 "${target}")
endif()
get_target_property(libs ${target} LINK_LIBRARIES)
if (libs)
foreach(lib ${libs})
shaderc_get_transitive_libs(${lib} ${out_list})
endforeach()
endif()
endif()
endif()
# If we know the location (i.e. if it was made with CMake) then we
# can add it to our list.
LIST(REMOVE_DUPLICATES ${out_list})
endmacro()
# Combines the static library "target" with all of its transitive static
# library dependencies into a single static library "new_target".
function(shaderc_combine_static_lib new_target target)
set(all_libs "")
shaderc_get_transitive_libs(${target} all_libs)
set(libname
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${new_target}${CMAKE_STATIC_LIBRARY_SUFFIX})
if (MSVC)
string(REPLACE ";" ">;$<TARGET_FILE:" temp_string "${all_libs}")
set(lib_target_list "$<TARGET_FILE:${temp_string}>")
add_custom_command(OUTPUT ${libname}
DEPENDS ${all_libs}
COMMAND lib.exe ${lib_target_list} /OUT:${libname} /NOLOGO)
elseif(APPLE)
string(REPLACE ";" ">;$<TARGET_FILE:" temp_string "${all_libs}")
set(lib_target_list "$<TARGET_FILE:${temp_string}>")
if(DEFINED CCTOOLS_PREFIX)
set(apple_libtool ${CCTOOLS_PREFIX}/bin/llvm-libtool-darwin)
else()
set(apple_libtool libtool)
endif()
add_custom_command(OUTPUT ${libname}
DEPENDS ${all_libs}
COMMAND ${apple_libtool} -static -o ${libname} ${lib_target_list})
else()
string(REPLACE ";" "> \naddlib $<TARGET_FILE:" temp_string "${all_libs}")
set(start_of_file
"create ${libname}\naddlib $<TARGET_FILE:${temp_string}>")
set(build_script_file "${start_of_file}\nsave\nend\n")
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${new_target}.ar"
CONTENT ${build_script_file}
CONDITION 1)
add_custom_command(OUTPUT ${libname}
DEPENDS ${all_libs}
COMMAND ${CMAKE_AR} -M < ${new_target}.ar)
endif()
add_custom_target(${new_target}_genfile ALL
DEPENDS ${libname})
# CMake needs to be able to see this as another normal library,
# so import the newly created library as an imported library,
# and set up the dependencies on the custom target.
add_library(${new_target} STATIC IMPORTED)
set_target_properties(${new_target}
PROPERTIES IMPORTED_LOCATION ${libname})
add_dependencies(${new_target} ${new_target}_genfile)
endfunction()

View File

@ -1,31 +0,0 @@
# Copyright (c) 2017 Pierre Moreau
#
# 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.
# First, retrieve the current version from CHANGES
file(STRINGS ${CHANGES_FILE} CHANGES_CONTENT)
string(
REGEX
MATCH "v[0-9]+(.[0-9]+)?(-dev)? [0-9]+-[0-9]+-[0-9]+"
FIRST_VERSION_LINE
${CHANGES_CONTENT})
string(
REGEX
REPLACE "^v([^ ]+) .+$" "\\1"
CURRENT_VERSION
"${FIRST_VERSION_LINE}")
# If this is a development version, replace "-dev" by ".0" as pkg-config nor
# CMake support "-dev" in the version.
# If it's not a "-dev" version then ensure it ends with ".1"
string(REGEX REPLACE "-dev.1" ".0" CURRENT_VERSION "${CURRENT_VERSION}.1")
configure_file(${TEMPLATE_FILE} ${OUT_FILE} @ONLY)

View File

@ -1,17 +0,0 @@
# Downloads
Download the latest builds.
**Note: These binaries are just the artifacts of the builders and have not
undergone any QA, thus they should be considered unsupported.**
## Release
| Windows | Linux | MacOS |
| --- | --- | --- |
| [MSVC 2017](https://storage.googleapis.com/shaderc/badges/build_link_windows_vs2017_release.html) | [clang](https://storage.googleapis.com/shaderc/badges/build_link_linux_clang_release.html) | [clang](https://storage.googleapis.com/shaderc/badges/build_link_macos_clang_release.html) |
| [MSVC 2015](https://storage.googleapis.com/shaderc/badges/build_link_windows_vs2015_release.html) | [gcc](https://storage.googleapis.com/shaderc/badges/build_link_linux_gcc_release.html) | |
## Debug
| Windows | Linux | MacOS |
| --- | --- | --- |
| [MSVC 2017](https://storage.googleapis.com/shaderc/badges/build_link_windows_vs2017_debug.html) | [clang](https://storage.googleapis.com/shaderc/badges/build_link_linux_clang_debug.html) | [clang](https://storage.googleapis.com/shaderc/badges/build_link_macos_clang_debug.html) |
| | [gcc](https://storage.googleapis.com/shaderc/badges/build_link_linux_gcc_debug.html) | |

View File

@ -1,29 +0,0 @@
# Copyright 2020 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.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CPP_EXTENSION := .cc .cpp .cxx
LOCAL_MODULE:=shaderc
LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)/include
LOCAL_SRC_FILES:=src/shaderc.cc
# The Shaderc third_party/Android.mk deduces SPVHEADERS_LOCAL_PATH,
# or delegates that responsibility to SPIRV-Tools' Android.mk.
LOCAL_C_INCLUDES:=$(LOCAL_PATH)/include $(SPVHEADERS_LOCAL_PATH)/include
LOCAL_STATIC_LIBRARIES:=shaderc_util SPIRV-Tools-opt
LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti -DENABLE_HLSL=1
LOCAL_EXPORT_CPPFLAGS:=-std=c++11
LOCAL_EXPORT_LDFLAGS:=-latomic
include $(BUILD_STATIC_LIBRARY)

View File

@ -1,131 +0,0 @@
# Copyright 2020 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.
project(libshaderc)
# Even though shaderc.hpp is a headers-only library, adding
# a dependency here will force clients of the library to rebuild
# when it changes.
set(SHADERC_SOURCES
include/shaderc/shaderc.h
include/shaderc/shaderc.hpp
src/shaderc.cc
src/shaderc_private.h
)
add_library(shaderc STATIC ${SHADERC_SOURCES})
shaderc_default_compile_options(shaderc)
target_include_directories(shaderc
PUBLIC include
PRIVATE ${glslang_SOURCE_DIR}
${SPIRV-Headers_SOURCE_DIR}/include)
#add_library(shaderc_shared SHARED ${SHADERC_SOURCES})
#shaderc_default_compile_options(shaderc_shared)
#target_include_directories(shaderc_shared
# PUBLIC include
# PRIVATE ${glslang_SOURCE_DIR}
# ${SPIRV-Headers_SOURCE_DIR}/include)
#target_compile_definitions(shaderc_shared
# PRIVATE SHADERC_IMPLEMENTATION
# PUBLIC SHADERC_SHAREDLIB
#)
#set_target_properties(shaderc_shared PROPERTIES SOVERSION 1)
if(SHADERC_ENABLE_INSTALL)
install(
FILES
include/shaderc/env.h
include/shaderc/status.h
include/shaderc/visibility.h
include/shaderc/shaderc.h
include/shaderc/shaderc.hpp
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/shaderc)
# install(TARGETS shaderc shaderc_shared
# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
# ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif(SHADERC_ENABLE_INSTALL)
find_package(Threads)
set(SHADERC_LIBS
glslang OSDependent OGLCompiler glslang ${CMAKE_THREAD_LIBS_INIT}
shaderc_util
SPIRV # from glslang
SPIRV-Tools
)
target_link_libraries(shaderc PRIVATE ${SHADERC_LIBS})
#target_link_libraries(shaderc_shared PRIVATE ${SHADERC_LIBS})
shaderc_add_tests(
TEST_PREFIX shaderc
LINK_LIBS shaderc
INCLUDE_DIRS include ${shaderc_SOURCE_DIR}/libshaderc_util/include ${glslang_SOURCE_DIR}
${spirv-tools_SOURCE_DIR}/include
${SPIRV-Headers_SOURCE_DIR}/include
TEST_NAMES
shaderc
shaderc_cpp
shaderc_private)
#shaderc_add_tests(
# TEST_PREFIX shaderc_shared
# LINK_LIBS shaderc_shared SPIRV-Tools
# INCLUDE_DIRS include ${shaderc_SOURCE_DIR}/libshaderc_util/include ${glslang_SOURCE_DIR}
# ${spirv-tools_SOURCE_DIR}/include
# ${SPIRV-Headers_SOURCE_DIR}/include
# TEST_NAMES
# shaderc
# shaderc_cpp
# shaderc_private)
shaderc_combine_static_lib(shaderc_combined shaderc)
if(SHADERC_ENABLE_INSTALL)
# Since shaderc_combined is defined as an imported library, we cannot use the
# install() directive to install it. Install it like a normal file.
get_target_property(generated_location shaderc_combined LOCATION)
string(REGEX MATCH "Visual Studio .*" vs_generator "${CMAKE_GENERATOR}")
if (NOT "${vs_generator}" STREQUAL "")
# With Visual Studio generators, the LOCATION property is not properly
# expanded according to the current build configuration. We need to work
# around this problem by manually substitution.
string(REPLACE "$(Configuration)" "\${CMAKE_INSTALL_CONFIG_NAME}"
install_location "${generated_location}")
install(FILES ${install_location} DESTINATION ${CMAKE_INSTALL_LIBDIR})
else()
install(FILES ${generated_location} DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
endif(SHADERC_ENABLE_INSTALL)
shaderc_add_tests(
TEST_PREFIX shaderc_combined
LINK_LIBS shaderc_combined ${CMAKE_THREAD_LIBS_INIT}
INCLUDE_DIRS include ${shaderc_SOURCE_DIR}/libshaderc_util/include ${glslang_SOURCE_DIR}
${spirv-tools_SOURCE_DIR}/include
${SPIRV-Headers_SOURCE_DIR}/include
TEST_NAMES
shaderc
shaderc_cpp)
if(${SHADERC_ENABLE_TESTS})
add_executable(shaderc_c_smoke_test ./src/shaderc_c_smoke_test.c)
shaderc_default_c_compile_options(shaderc_c_smoke_test)
target_include_directories(shaderc_c_smoke_test PUBLIC ${shaderc_SOURCE_DIR}/libshaderc_util/include)
target_link_libraries(shaderc_c_smoke_test PRIVATE shaderc)
add_test(NAME shaderc_c_smoke_test COMMAND shaderc_c_smoke_test)
endif()

View File

@ -1,52 +0,0 @@
# libshaderc
A library for compiling shader strings into SPIR-V.
## Build Artifacts
There are two main shaderc libraries that are created during a CMake
compilation. The first is `libshaderc`, which is a static library
containing just the functionality exposed by libshaderc. It depends
on other compilation targets `glslang`, `OSDependent`, `OGLCompiler`,
`shaderc_util`, `SPIRV`, `HLSL`, `SPIRV-Tools`, and `SPIRV-Tools-opt`.
The other is `libshaderc_combined`, which is a static library containing
libshaderc and all of its dependencies.
## Integrating libshaderc
There are several ways of integrating libshaderc into external projects.
1. If the external project uses CMake, then `shaderc/CMakeLists.txt` can be
included into the external project's CMake configuration and shaderc can be used
as a link target.
This is the simplest way to use libshaderc in an external project.
2. If the external project uses CMake and is building for Linux or Android,
`target_link_libraries(shaderc_combined)` can instead be specified. This is
functionally identical to the previous option.
3. If the external project does not use CMake, then the external project can
instead directly use the generated libraries. `shaderc/libshaderc/include`
should be added to the include path, and
`build/libshaderc/libshaderc_combined.a` should be linked. Note that on some
platforms `-lpthread` should also be specified.
4. If the external project does not use CMake and cannot use
`libshaderc_combined`, the following libraries or their platform-dependent
counterparts should be linked in the order specified.
* `build/libshaderc/libshaderc.a`
* `build/third_party/glslang/glslang/glslang.a`
* `build/third_party/glslang/glslang/OSDependent/{Platform}/libOSDependent.a`
* `build/third_party/glslang/OGLCompilersDLL/libOGLCompiler.a`
* `build/third_party/glslang/libglslang.a`
* `build/shaderc_util/libshaderc_util.a`
* `build/third_party/glslang/SPIRV/libSPIRV.a`
* `build/third_party/glslang/hlsl/libHLSL.a`
* `build/third_party/spirv-tools/libSPIRV-Tools-opt.a`
* `build/third_party/spirv-tools/libSPIRV-Tools.a`
5. If building for Android using the Android NDK, `shaderc/Android.mk` can be
included in the application's `Android.mk` and `LOCAL_STATIC_LIBRARIES:=shaderc`
can be specified. See `shaderc/android_test` for an example.

View File

@ -1,72 +0,0 @@
// 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.
#ifndef SHADERC_ENV_H_
#define SHADERC_ENV_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
shaderc_target_env_vulkan, // SPIR-V under Vulkan semantics
shaderc_target_env_opengl, // SPIR-V under OpenGL semantics
// NOTE: SPIR-V code generation is not supported for shaders under OpenGL
// compatibility profile.
shaderc_target_env_opengl_compat, // SPIR-V under OpenGL semantics,
// including compatibility profile
// functions
shaderc_target_env_webgpu, // Deprecated, SPIR-V under WebGPU
// semantics
shaderc_target_env_default = shaderc_target_env_vulkan
} 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 = ((1u << 22)),
shaderc_env_version_vulkan_1_1 = ((1u << 22) | (1 << 12)),
shaderc_env_version_vulkan_1_2 = ((1u << 22) | (2 << 12)),
shaderc_env_version_vulkan_1_3 = ((1u << 22) | (3 << 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_webgpu, // Deprecated, WebGPU env never defined versions
} shaderc_env_version;
// The known versions of SPIR-V.
typedef enum {
// Use the values used for word 1 of a SPIR-V binary:
// - bits 24 to 31: zero
// - bits 16 to 23: major version number
// - bits 8 to 15: minor version number
// - bits 0 to 7: zero
shaderc_spirv_version_1_0 = 0x010000u,
shaderc_spirv_version_1_1 = 0x010100u,
shaderc_spirv_version_1_2 = 0x010200u,
shaderc_spirv_version_1_3 = 0x010300u,
shaderc_spirv_version_1_4 = 0x010400u,
shaderc_spirv_version_1_5 = 0x010500u,
shaderc_spirv_version_1_6 = 0x010600u
} shaderc_spirv_version;
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // SHADERC_ENV_H_

View File

@ -1,585 +0,0 @@
// Copyright 2015 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.
#ifndef SHADERC_SHADERC_H_
#define SHADERC_SHADERC_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "shaderc/env.h"
#include "shaderc/status.h"
#include "shaderc/visibility.h"
// Source language kind.
typedef enum {
shaderc_source_language_glsl,
shaderc_source_language_hlsl,
} shaderc_source_language;
typedef enum {
// Forced shader kinds. These shader kinds force the compiler to compile the
// source code as the specified kind of shader.
shaderc_vertex_shader,
shaderc_fragment_shader,
shaderc_compute_shader,
shaderc_geometry_shader,
shaderc_tess_control_shader,
shaderc_tess_evaluation_shader,
shaderc_glsl_vertex_shader = shaderc_vertex_shader,
shaderc_glsl_fragment_shader = shaderc_fragment_shader,
shaderc_glsl_compute_shader = shaderc_compute_shader,
shaderc_glsl_geometry_shader = shaderc_geometry_shader,
shaderc_glsl_tess_control_shader = shaderc_tess_control_shader,
shaderc_glsl_tess_evaluation_shader = shaderc_tess_evaluation_shader,
// Deduce the shader kind from #pragma annotation in the source code. Compiler
// will emit error if #pragma annotation is not found.
shaderc_glsl_infer_from_source,
// Default shader kinds. Compiler will fall back to compile the source code as
// the specified kind of shader when #pragma annotation is not found in the
// source code.
shaderc_glsl_default_vertex_shader,
shaderc_glsl_default_fragment_shader,
shaderc_glsl_default_compute_shader,
shaderc_glsl_default_geometry_shader,
shaderc_glsl_default_tess_control_shader,
shaderc_glsl_default_tess_evaluation_shader,
shaderc_spirv_assembly,
shaderc_raygen_shader,
shaderc_anyhit_shader,
shaderc_closesthit_shader,
shaderc_miss_shader,
shaderc_intersection_shader,
shaderc_callable_shader,
shaderc_glsl_raygen_shader = shaderc_raygen_shader,
shaderc_glsl_anyhit_shader = shaderc_anyhit_shader,
shaderc_glsl_closesthit_shader = shaderc_closesthit_shader,
shaderc_glsl_miss_shader = shaderc_miss_shader,
shaderc_glsl_intersection_shader = shaderc_intersection_shader,
shaderc_glsl_callable_shader = shaderc_callable_shader,
shaderc_glsl_default_raygen_shader,
shaderc_glsl_default_anyhit_shader,
shaderc_glsl_default_closesthit_shader,
shaderc_glsl_default_miss_shader,
shaderc_glsl_default_intersection_shader,
shaderc_glsl_default_callable_shader,
shaderc_task_shader,
shaderc_mesh_shader,
shaderc_glsl_task_shader = shaderc_task_shader,
shaderc_glsl_mesh_shader = shaderc_mesh_shader,
shaderc_glsl_default_task_shader,
shaderc_glsl_default_mesh_shader,
} shaderc_shader_kind;
typedef enum {
shaderc_profile_none, // Used if and only if GLSL version did not specify
// profiles.
shaderc_profile_core,
shaderc_profile_compatibility, // Disabled. This generates an error
shaderc_profile_es,
} shaderc_profile;
// Optimization level.
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.
typedef enum {
shaderc_limit_max_lights,
shaderc_limit_max_clip_planes,
shaderc_limit_max_texture_units,
shaderc_limit_max_texture_coords,
shaderc_limit_max_vertex_attribs,
shaderc_limit_max_vertex_uniform_components,
shaderc_limit_max_varying_floats,
shaderc_limit_max_vertex_texture_image_units,
shaderc_limit_max_combined_texture_image_units,
shaderc_limit_max_texture_image_units,
shaderc_limit_max_fragment_uniform_components,
shaderc_limit_max_draw_buffers,
shaderc_limit_max_vertex_uniform_vectors,
shaderc_limit_max_varying_vectors,
shaderc_limit_max_fragment_uniform_vectors,
shaderc_limit_max_vertex_output_vectors,
shaderc_limit_max_fragment_input_vectors,
shaderc_limit_min_program_texel_offset,
shaderc_limit_max_program_texel_offset,
shaderc_limit_max_clip_distances,
shaderc_limit_max_compute_work_group_count_x,
shaderc_limit_max_compute_work_group_count_y,
shaderc_limit_max_compute_work_group_count_z,
shaderc_limit_max_compute_work_group_size_x,
shaderc_limit_max_compute_work_group_size_y,
shaderc_limit_max_compute_work_group_size_z,
shaderc_limit_max_compute_uniform_components,
shaderc_limit_max_compute_texture_image_units,
shaderc_limit_max_compute_image_uniforms,
shaderc_limit_max_compute_atomic_counters,
shaderc_limit_max_compute_atomic_counter_buffers,
shaderc_limit_max_varying_components,
shaderc_limit_max_vertex_output_components,
shaderc_limit_max_geometry_input_components,
shaderc_limit_max_geometry_output_components,
shaderc_limit_max_fragment_input_components,
shaderc_limit_max_image_units,
shaderc_limit_max_combined_image_units_and_fragment_outputs,
shaderc_limit_max_combined_shader_output_resources,
shaderc_limit_max_image_samples,
shaderc_limit_max_vertex_image_uniforms,
shaderc_limit_max_tess_control_image_uniforms,
shaderc_limit_max_tess_evaluation_image_uniforms,
shaderc_limit_max_geometry_image_uniforms,
shaderc_limit_max_fragment_image_uniforms,
shaderc_limit_max_combined_image_uniforms,
shaderc_limit_max_geometry_texture_image_units,
shaderc_limit_max_geometry_output_vertices,
shaderc_limit_max_geometry_total_output_components,
shaderc_limit_max_geometry_uniform_components,
shaderc_limit_max_geometry_varying_components,
shaderc_limit_max_tess_control_input_components,
shaderc_limit_max_tess_control_output_components,
shaderc_limit_max_tess_control_texture_image_units,
shaderc_limit_max_tess_control_uniform_components,
shaderc_limit_max_tess_control_total_output_components,
shaderc_limit_max_tess_evaluation_input_components,
shaderc_limit_max_tess_evaluation_output_components,
shaderc_limit_max_tess_evaluation_texture_image_units,
shaderc_limit_max_tess_evaluation_uniform_components,
shaderc_limit_max_tess_patch_components,
shaderc_limit_max_patch_vertices,
shaderc_limit_max_tess_gen_level,
shaderc_limit_max_viewports,
shaderc_limit_max_vertex_atomic_counters,
shaderc_limit_max_tess_control_atomic_counters,
shaderc_limit_max_tess_evaluation_atomic_counters,
shaderc_limit_max_geometry_atomic_counters,
shaderc_limit_max_fragment_atomic_counters,
shaderc_limit_max_combined_atomic_counters,
shaderc_limit_max_atomic_counter_bindings,
shaderc_limit_max_vertex_atomic_counter_buffers,
shaderc_limit_max_tess_control_atomic_counter_buffers,
shaderc_limit_max_tess_evaluation_atomic_counter_buffers,
shaderc_limit_max_geometry_atomic_counter_buffers,
shaderc_limit_max_fragment_atomic_counter_buffers,
shaderc_limit_max_combined_atomic_counter_buffers,
shaderc_limit_max_atomic_counter_buffer_size,
shaderc_limit_max_transform_feedback_buffers,
shaderc_limit_max_transform_feedback_interleaved_components,
shaderc_limit_max_cull_distances,
shaderc_limit_max_combined_clip_and_cull_distances,
shaderc_limit_max_samples,
} shaderc_limit;
// Uniform resource kinds.
// In Vulkan, uniform resources are bound to the pipeline via descriptors
// with numbered bindings and sets.
typedef enum {
// Image and image buffer.
shaderc_uniform_kind_image,
// Pure sampler.
shaderc_uniform_kind_sampler,
// Sampled texture in GLSL, and Shader Resource View in HLSL.
shaderc_uniform_kind_texture,
// Uniform Buffer Object (UBO) in GLSL. Cbuffer in HLSL.
shaderc_uniform_kind_buffer,
// Shader Storage Buffer Object (SSBO) in GLSL.
shaderc_uniform_kind_storage_buffer,
// Unordered Access View, in HLSL. (Writable storage image or storage
// buffer.)
shaderc_uniform_kind_unordered_access_view,
} shaderc_uniform_kind;
// Usage examples:
//
// Aggressively release compiler resources, but spend time in initialization
// for each new use.
// shaderc_compiler_t compiler = shaderc_compiler_initialize();
// shaderc_compilation_result_t result = shaderc_compile_into_spv(
// compiler, "#version 450\nvoid main() {}", 27,
// shaderc_glsl_vertex_shader, "main.vert", "main", nullptr);
// // Do stuff with compilation results.
// shaderc_result_release(result);
// shaderc_compiler_release(compiler);
//
// Keep the compiler object around for a long time, but pay for extra space
// occupied.
// shaderc_compiler_t compiler = shaderc_compiler_initialize();
// // On the same, other or multiple simultaneous threads.
// shaderc_compilation_result_t result = shaderc_compile_into_spv(
// compiler, "#version 450\nvoid main() {}", 27,
// shaderc_glsl_vertex_shader, "main.vert", "main", nullptr);
// // Do stuff with compilation results.
// shaderc_result_release(result);
// // Once no more compilations are to happen.
// shaderc_compiler_release(compiler);
// An opaque handle to an object that manages all compiler state.
typedef struct shaderc_compiler* shaderc_compiler_t;
// Returns a shaderc_compiler_t that can be used to compile modules.
// A return of NULL indicates that there was an error initializing the compiler.
// Any function operating on shaderc_compiler_t must offer the basic
// thread-safety guarantee.
// [http://herbsutter.com/2014/01/13/gotw-95-solution-thread-safety-and-synchronization/]
// That is: concurrent invocation of these functions on DIFFERENT objects needs
// no synchronization; concurrent invocation of these functions on the SAME
// object requires synchronization IF AND ONLY IF some of them take a non-const
// argument.
SHADERC_EXPORT shaderc_compiler_t shaderc_compiler_initialize(void);
// Releases the resources held by the shaderc_compiler_t.
// After this call it is invalid to make any future calls to functions
// involving this shaderc_compiler_t.
SHADERC_EXPORT void shaderc_compiler_release(shaderc_compiler_t);
// An opaque handle to an object that manages options to a single compilation
// result.
typedef struct shaderc_compile_options* shaderc_compile_options_t;
// Returns a default-initialized shaderc_compile_options_t that can be used
// to modify the functionality of a compiled module.
// A return of NULL indicates that there was an error initializing the options.
// Any function operating on shaderc_compile_options_t must offer the
// basic thread-safety guarantee.
SHADERC_EXPORT shaderc_compile_options_t
shaderc_compile_options_initialize(void);
// Returns a copy of the given shaderc_compile_options_t.
// If NULL is passed as the parameter the call is the same as
// shaderc_compile_options_init.
SHADERC_EXPORT shaderc_compile_options_t shaderc_compile_options_clone(
const shaderc_compile_options_t options);
// Releases the compilation options. It is invalid to use the given
// shaderc_compile_options_t object in any future calls. It is safe to pass
// NULL to this function, and doing such will have no effect.
SHADERC_EXPORT void shaderc_compile_options_release(
shaderc_compile_options_t options);
// Adds a predefined macro to the compilation options. This has the same
// effect as passing -Dname=value to the command-line compiler. If value
// is NULL, it has the same effect as passing -Dname to the command-line
// compiler. If a macro definition with the same name has previously been
// added, the value is replaced with the new value. The macro name and
// value are passed in with char pointers, which point to their data, and
// the lengths of their data. The strings that the name and value pointers
// point to must remain valid for the duration of the call, but can be
// modified or deleted after this function has returned. In case of adding
// a valueless macro, the value argument should be a null pointer or the
// value_length should be 0u.
SHADERC_EXPORT void shaderc_compile_options_add_macro_definition(
shaderc_compile_options_t options, const char* name, size_t name_length,
const char* value, size_t value_length);
// Sets the source language. The default is GLSL.
SHADERC_EXPORT void shaderc_compile_options_set_source_language(
shaderc_compile_options_t options, shaderc_source_language lang);
// Sets the compiler mode to generate debug information in the output.
SHADERC_EXPORT void shaderc_compile_options_set_generate_debug_info(
shaderc_compile_options_t options);
// Sets the compiler optimization level to the given level. Only the last one
// takes effect if multiple calls of this function exist.
SHADERC_EXPORT void shaderc_compile_options_set_optimization_level(
shaderc_compile_options_t options, shaderc_optimization_level level);
// Forces the GLSL language version and profile to a given pair. The version
// number is the same as would appear in the #version annotation in the source.
// Version and profile specified here overrides the #version annotation in the
// source. Use profile: 'shaderc_profile_none' for GLSL versions that do not
// define profiles, e.g. versions below 150.
SHADERC_EXPORT void shaderc_compile_options_set_forced_version_profile(
shaderc_compile_options_t options, int version, shaderc_profile profile);
// Source text inclusion via #include is supported with a pair of callbacks
// to an "includer" on the client side. The first callback processes an
// inclusion request, and returns an include result. The includer owns
// the contents of the result, and those contents must remain valid until the
// second callback is invoked to release the result. Both callbacks take a
// user_data argument to specify the client context.
// To return an error, set the source_name to an empty string and put your
// error message in content.
// An include result.
typedef struct shaderc_include_result {
// The name of the source file. The name should be fully resolved
// in the sense that it should be a unique name in the context of the
// includer. For example, if the includer maps source names to files in
// a filesystem, then this name should be the absolute path of the file.
// For a failed inclusion, this string is empty.
const char* source_name;
size_t source_name_length;
// The text contents of the source file in the normal case.
// For a failed inclusion, this contains the error message.
const char* content;
size_t content_length;
// User data to be passed along with this request.
void* user_data;
} shaderc_include_result;
// The kinds of include requests.
enum shaderc_include_type {
shaderc_include_type_relative, // E.g. #include "source"
shaderc_include_type_standard // E.g. #include <source>
};
// An includer callback type for mapping an #include request to an include
// result. The user_data parameter specifies the client context. The
// requested_source parameter specifies the name of the source being requested.
// The type parameter specifies the kind of inclusion request being made.
// The requesting_source parameter specifies the name of the source containing
// the #include request. The includer owns the result object and its contents,
// and both must remain valid until the release callback is called on the result
// object.
typedef shaderc_include_result* (*shaderc_include_resolve_fn)(
void* user_data, const char* requested_source, int type,
const char* requesting_source, size_t include_depth);
// An includer callback type for destroying an include result.
typedef void (*shaderc_include_result_release_fn)(
void* user_data, shaderc_include_result* include_result);
// Sets includer callback functions.
SHADERC_EXPORT void shaderc_compile_options_set_include_callbacks(
shaderc_compile_options_t options, shaderc_include_resolve_fn resolver,
shaderc_include_result_release_fn result_releaser, void* user_data);
// Sets the compiler mode to suppress warnings, overriding warnings-as-errors
// mode. When both suppress-warnings and warnings-as-errors modes are
// turned on, warning messages will be inhibited, and will not be emitted
// as error messages.
SHADERC_EXPORT void shaderc_compile_options_set_suppress_warnings(
shaderc_compile_options_t options);
// 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. 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,
uint32_t version);
// Sets the target SPIR-V version. The generated module will use this version
// of SPIR-V. Each target environment determines what versions of SPIR-V
// it can consume. Defaults to the highest version of SPIR-V 1.0 which is
// required to be supported by the target environment. E.g. Default to SPIR-V
// 1.0 for Vulkan 1.0 and SPIR-V 1.3 for Vulkan 1.1.
SHADERC_EXPORT void shaderc_compile_options_set_target_spirv(
shaderc_compile_options_t options, shaderc_spirv_version version);
// Sets the compiler mode to treat all warnings as errors. Note the
// suppress-warnings mode overrides this option, i.e. if both
// warning-as-errors and suppress-warnings modes are set, warnings will not
// be emitted as error messages.
SHADERC_EXPORT void shaderc_compile_options_set_warnings_as_errors(
shaderc_compile_options_t options);
// Sets a resource limit.
SHADERC_EXPORT void shaderc_compile_options_set_limit(
shaderc_compile_options_t options, shaderc_limit limit, int value);
// Sets whether the compiler should automatically assign bindings to uniforms
// that aren't already explicitly bound in the shader source.
SHADERC_EXPORT void shaderc_compile_options_set_auto_bind_uniforms(
shaderc_compile_options_t options, bool auto_bind);
// Sets whether the compiler should automatically remove sampler variables
// and convert image variables to combined image-sampler variables.
SHADERC_EXPORT void shaderc_compile_options_set_auto_combined_image_sampler(
shaderc_compile_options_t options, bool upgrade);
// Sets whether the compiler should use HLSL IO mapping rules for bindings.
// Defaults to false.
SHADERC_EXPORT void shaderc_compile_options_set_hlsl_io_mapping(
shaderc_compile_options_t options, bool hlsl_iomap);
// Sets whether the compiler should determine block member offsets using HLSL
// packing rules instead of standard GLSL rules. Defaults to false. Only
// affects GLSL compilation. HLSL rules are always used when compiling HLSL.
SHADERC_EXPORT void shaderc_compile_options_set_hlsl_offsets(
shaderc_compile_options_t options, bool hlsl_offsets);
// Sets the base binding number used for for a uniform resource type when
// automatically assigning bindings. For GLSL compilation, sets the lowest
// automatically assigned number. For HLSL compilation, the regsiter number
// assigned to the resource is added to this specified base.
SHADERC_EXPORT void shaderc_compile_options_set_binding_base(
shaderc_compile_options_t options,
shaderc_uniform_kind kind,
uint32_t base);
// Like shaderc_compile_options_set_binding_base, but only takes effect when
// compiling a given shader stage. The stage is assumed to be one of vertex,
// fragment, tessellation evaluation, tesselation control, geometry, or compute.
SHADERC_EXPORT void shaderc_compile_options_set_binding_base_for_stage(
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(
shaderc_compile_options_t options, shaderc_shader_kind shader_kind,
const char* reg, const char* set, const char* binding);
// Like shaderc_compile_options_set_hlsl_register_set_and_binding_for_stage,
// but affects all shader stages.
SHADERC_EXPORT void shaderc_compile_options_set_hlsl_register_set_and_binding(
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);
// Sets whether the compiler should invert position.Y output in vertex shader.
SHADERC_EXPORT void shaderc_compile_options_set_invert_y(
shaderc_compile_options_t options, bool enable);
// Sets whether the compiler generates code for max and min builtins which,
// if given a NaN operand, will return the other operand. Similarly, the clamp
// builtin will favour the non-NaN operands, as if clamp were implemented
// as a composition of max and min.
SHADERC_EXPORT void shaderc_compile_options_set_nan_clamp(
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;
// Takes a GLSL source string and the associated shader kind, input file
// name, compiles it according to the given additional_options. If the shader
// kind is not set to a specified kind, but shaderc_glslc_infer_from_source,
// the compiler will try to deduce the shader kind from the source
// string and a failure in deducing will generate an error. Currently only
// #pragma annotation is supported. If the shader kind is set to one of the
// default shader kinds, the compiler will fall back to the default shader
// kind in case it failed to deduce the shader kind from source string.
// The input_file_name is a null-termintated string. It is used as a tag to
// identify the source string in cases like emitting error messages. It
// doesn't have to be a 'file name'.
// The source string will be compiled into SPIR-V binary and a
// shaderc_compilation_result will be returned to hold the results.
// The entry_point_name null-terminated string defines the name of the entry
// point to associate with this GLSL source. If the additional_options
// parameter is not null, then the compilation is modified by any options
// present. May be safely called from multiple threads without explicit
// synchronization. If there was failure in allocating the compiler object,
// null will be returned.
SHADERC_EXPORT shaderc_compilation_result_t shaderc_compile_into_spv(
const shaderc_compiler_t compiler, const char* source_text,
size_t source_text_size, shaderc_shader_kind shader_kind,
const char* input_file_name, const char* entry_point_name,
const shaderc_compile_options_t additional_options);
// Like shaderc_compile_into_spv, but the result contains SPIR-V assembly text
// instead of a SPIR-V binary module. The SPIR-V assembly syntax is as defined
// by the SPIRV-Tools open source project.
SHADERC_EXPORT shaderc_compilation_result_t shaderc_compile_into_spv_assembly(
const shaderc_compiler_t compiler, const char* source_text,
size_t source_text_size, shaderc_shader_kind shader_kind,
const char* input_file_name, const char* entry_point_name,
const shaderc_compile_options_t additional_options);
// Like shaderc_compile_into_spv, but the result contains preprocessed source
// code instead of a SPIR-V binary module
SHADERC_EXPORT shaderc_compilation_result_t shaderc_compile_into_preprocessed_text(
const shaderc_compiler_t compiler, const char* source_text,
size_t source_text_size, shaderc_shader_kind shader_kind,
const char* input_file_name, const char* entry_point_name,
const shaderc_compile_options_t additional_options);
// Takes an assembly string of the format defined in the SPIRV-Tools project
// (https://github.com/KhronosGroup/SPIRV-Tools/blob/master/syntax.md),
// assembles it into SPIR-V binary and a shaderc_compilation_result will be
// returned to hold the results.
// The assembling will pick options suitable for assembling specified in the
// additional_options parameter.
// May be safely called from multiple threads without explicit synchronization.
// If there was failure in allocating the compiler object, null will be
// returned.
SHADERC_EXPORT shaderc_compilation_result_t shaderc_assemble_into_spv(
const shaderc_compiler_t compiler, const char* source_assembly,
size_t source_assembly_size,
const shaderc_compile_options_t additional_options);
// The following functions, operating on shaderc_compilation_result_t objects,
// offer only the basic thread-safety guarantee.
// Releases the resources held by the result object. It is invalid to use the
// result object for any further operations.
SHADERC_EXPORT void shaderc_result_release(shaderc_compilation_result_t result);
// Returns the number of bytes of the compilation output data in a result
// object.
SHADERC_EXPORT size_t shaderc_result_get_length(const shaderc_compilation_result_t result);
// Returns the number of warnings generated during the compilation.
SHADERC_EXPORT size_t shaderc_result_get_num_warnings(
const shaderc_compilation_result_t result);
// Returns the number of errors generated during the compilation.
SHADERC_EXPORT size_t shaderc_result_get_num_errors(const shaderc_compilation_result_t result);
// Returns the compilation status, indicating whether the compilation succeeded,
// or failed due to some reasons, like invalid shader stage or compilation
// errors.
SHADERC_EXPORT shaderc_compilation_status shaderc_result_get_compilation_status(
const shaderc_compilation_result_t);
// Returns a pointer to the start of the compilation output data bytes, either
// SPIR-V binary or char string. When the source string is compiled into SPIR-V
// binary, this is guaranteed to be castable to a uint32_t*. If the result
// contains assembly text or preprocessed source text, the pointer will point to
// the resulting array of characters.
SHADERC_EXPORT const char* shaderc_result_get_bytes(const shaderc_compilation_result_t result);
// Returns a null-terminated string that contains any error messages generated
// during the compilation.
SHADERC_EXPORT const char* shaderc_result_get_error_message(
const shaderc_compilation_result_t result);
// Provides the version & revision of the SPIR-V which will be produced
SHADERC_EXPORT void shaderc_get_spv_version(unsigned int* version, unsigned int* revision);
// Parses the version and profile from a given null-terminated string
// containing both version and profile, like: '450core'. Returns false if
// the string can not be parsed. Returns true when the parsing succeeds. The
// parsed version and profile are returned through arguments.
SHADERC_EXPORT bool shaderc_parse_version_profile(const char* str, int* version,
shaderc_profile* profile);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // SHADERC_SHADERC_H_

View File

@ -1,602 +0,0 @@
// Copyright 2015 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.
#ifndef SHADERC_SHADERC_HPP_
#define SHADERC_SHADERC_HPP_
#include <memory>
#include <string>
#include <vector>
#include "shaderc.h"
namespace shaderc {
// A CompilationResult contains the compiler output, compilation status,
// and messages.
//
// The compiler output is stored as an array of elements and accessed
// via random access iterators provided by cbegin() and cend(). The iterators
// are contiguous in the sense of "Contiguous Iterators: A Refinement of
// Random Access Iterators", Nevin Liber, C++ Library Evolution Working
// Group Working Paper N3884.
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3884.pdf
//
// Methods begin() and end() are also provided to enable range-based for.
// They are synonyms to cbegin() and cend(), respectively.
template <typename OutputElementType>
class CompilationResult {
public:
typedef OutputElementType element_type;
// The type used to describe the begin and end iterators on the
// compiler output.
typedef const OutputElementType* const_iterator;
// Upon creation, the CompilationResult takes ownership of the
// shaderc_compilation_result instance. During destruction of the
// CompilationResult, the shaderc_compilation_result will be released.
explicit CompilationResult(shaderc_compilation_result_t compilation_result)
: compilation_result_(compilation_result) {}
CompilationResult() : compilation_result_(nullptr) {}
~CompilationResult() { shaderc_result_release(compilation_result_); }
CompilationResult(CompilationResult&& other) : compilation_result_(nullptr) {
*this = std::move(other);
}
CompilationResult& operator=(CompilationResult&& other) {
if (compilation_result_) {
shaderc_result_release(compilation_result_);
}
compilation_result_ = other.compilation_result_;
other.compilation_result_ = nullptr;
return *this;
}
// Returns any error message found during compilation.
std::string GetErrorMessage() const {
if (!compilation_result_) {
return "";
}
return shaderc_result_get_error_message(compilation_result_);
}
// Returns the compilation status, indicating whether the compilation
// succeeded, or failed due to some reasons, like invalid shader stage or
// compilation errors.
shaderc_compilation_status GetCompilationStatus() const {
if (!compilation_result_) {
return shaderc_compilation_status_null_result_object;
}
return shaderc_result_get_compilation_status(compilation_result_);
}
// Returns a random access (contiguous) iterator pointing to the start
// of the compilation output. It is valid for the lifetime of this object.
// If there is no compilation result, then returns nullptr.
const_iterator cbegin() const {
if (!compilation_result_) return nullptr;
return reinterpret_cast<const_iterator>(
shaderc_result_get_bytes(compilation_result_));
}
// Returns a random access (contiguous) iterator pointing to the end of
// the compilation output. It is valid for the lifetime of this object.
// If there is no compilation result, then returns nullptr.
const_iterator cend() const {
if (!compilation_result_) return nullptr;
return cbegin() +
shaderc_result_get_length(compilation_result_) /
sizeof(OutputElementType);
}
// Returns the same iterator as cbegin().
const_iterator begin() const { return cbegin(); }
// Returns the same iterator as cend().
const_iterator end() const { return cend(); }
// Returns the number of warnings generated during the compilation.
size_t GetNumWarnings() const {
if (!compilation_result_) {
return 0;
}
return shaderc_result_get_num_warnings(compilation_result_);
}
// Returns the number of errors generated during the compilation.
size_t GetNumErrors() const {
if (!compilation_result_) {
return 0;
}
return shaderc_result_get_num_errors(compilation_result_);
}
private:
CompilationResult(const CompilationResult& other) = delete;
CompilationResult& operator=(const CompilationResult& other) = delete;
shaderc_compilation_result_t compilation_result_;
};
// A compilation result for a SPIR-V binary module, which is an array
// of uint32_t words.
using SpvCompilationResult = CompilationResult<uint32_t>;
// A compilation result in SPIR-V assembly syntax.
using AssemblyCompilationResult = CompilationResult<char>;
// Preprocessed source text.
using PreprocessedSourceCompilationResult = CompilationResult<char>;
// Contains any options that can have default values for a compilation.
class CompileOptions {
public:
CompileOptions() { options_ = shaderc_compile_options_initialize(); }
~CompileOptions() { shaderc_compile_options_release(options_); }
CompileOptions(const CompileOptions& other) {
options_ = shaderc_compile_options_clone(other.options_);
}
CompileOptions(CompileOptions&& other) {
options_ = other.options_;
other.options_ = nullptr;
}
// Adds a predefined macro to the compilation options. It behaves the same as
// shaderc_compile_options_add_macro_definition in shaderc.h.
void AddMacroDefinition(const char* name, size_t name_length,
const char* value, size_t value_length) {
shaderc_compile_options_add_macro_definition(options_, name, name_length,
value, value_length);
}
// Adds a valueless predefined macro to the compilation options.
void AddMacroDefinition(const std::string& name) {
AddMacroDefinition(name.c_str(), name.size(), nullptr, 0u);
}
// Adds a predefined macro to the compilation options.
void AddMacroDefinition(const std::string& name, const std::string& value) {
AddMacroDefinition(name.c_str(), name.size(), value.c_str(), value.size());
}
// Sets the compiler mode to generate debug information in the output.
void SetGenerateDebugInfo() {
shaderc_compile_options_set_generate_debug_info(options_);
}
// Sets the compiler optimization level to the given level. Only the last one
// takes effect if multiple calls of this function exist.
void SetOptimizationLevel(shaderc_optimization_level level) {
shaderc_compile_options_set_optimization_level(options_, level);
}
// A C++ version of the libshaderc includer interface.
class IncluderInterface {
public:
// Handles shaderc_include_resolver_fn callbacks.
virtual shaderc_include_result* GetInclude(const char* requested_source,
shaderc_include_type type,
const char* requesting_source,
size_t include_depth) = 0;
// 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
// described in shaderc_compile_options_set_include_callbacks(). Callbacks
// are routed to this includer's methods.
void SetIncluder(std::unique_ptr<IncluderInterface>&& includer) {
includer_ = std::move(includer);
shaderc_compile_options_set_include_callbacks(
options_,
[](void* user_data, const char* requested_source, int type,
const char* requesting_source, size_t include_depth) {
auto* sub_includer = static_cast<IncluderInterface*>(user_data);
return sub_includer->GetInclude(
requested_source, static_cast<shaderc_include_type>(type),
requesting_source, include_depth);
},
[](void* user_data, shaderc_include_result* include_result) {
auto* sub_includer = static_cast<IncluderInterface*>(user_data);
return sub_includer->ReleaseInclude(include_result);
},
includer_.get());
}
// Forces the GLSL language version and profile to a given pair. The version
// number is the same as would appear in the #version annotation in the
// source. Version and profile specified here overrides the #version
// annotation in the source. Use profile: 'shaderc_profile_none' for GLSL
// versions that do not define profiles, e.g. versions below 150.
void SetForcedVersionProfile(int version, shaderc_profile profile) {
shaderc_compile_options_set_forced_version_profile(options_, version,
profile);
}
// Sets the compiler mode to suppress warnings. Note this option overrides
// warnings-as-errors mode. When both suppress-warnings and warnings-as-errors
// modes are turned on, warning messages will be inhibited, and will not be
// emitted as error message.
void SetSuppressWarnings() {
shaderc_compile_options_set_suppress_warnings(options_);
}
// Sets the source language. The default is GLSL.
void SetSourceLanguage(shaderc_source_language lang) {
shaderc_compile_options_set_source_language(options_, lang);
}
// 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. 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);
}
// Sets the target SPIR-V version. The generated module will use this version
// of SPIR-V. Each target environment determines what versions of SPIR-V
// it can consume. Defaults to the highest version of SPIR-V 1.0 which is
// required to be supported by the target environment. E.g. Default to SPIR-V
// 1.0 for Vulkan 1.0 and SPIR-V 1.3 for Vulkan 1.1.
void SetTargetSpirv(shaderc_spirv_version version) {
shaderc_compile_options_set_target_spirv(options_, version);
}
// Sets the compiler mode to make all warnings into errors. Note the
// suppress-warnings mode overrides this option, i.e. if both
// warning-as-errors and suppress-warnings modes are set on, warnings will not
// be emitted as error message.
void SetWarningsAsErrors() {
shaderc_compile_options_set_warnings_as_errors(options_);
}
// Sets a resource limit.
void SetLimit(shaderc_limit limit, int value) {
shaderc_compile_options_set_limit(options_, limit, value);
}
// Sets whether the compiler should automatically assign bindings to uniforms
// that aren't already explicitly bound in the shader source.
void SetAutoBindUniforms(bool auto_bind) {
shaderc_compile_options_set_auto_bind_uniforms(options_, auto_bind);
}
// Sets whether the compiler should automatically remove sampler variables
// and convert image variables to combined image sampler variables.
void SetAutoSampledTextures(bool auto_sampled) {
shaderc_compile_options_set_auto_combined_image_sampler(options_,
auto_sampled);
}
// Sets whether the compiler should use HLSL IO mapping rules for bindings.
// Defaults to false.
void SetHlslIoMapping(bool hlsl_iomap) {
shaderc_compile_options_set_hlsl_io_mapping(options_, hlsl_iomap);
}
// Sets whether the compiler should determine block member offsets using HLSL
// packing rules instead of standard GLSL rules. Defaults to false. Only
// affects GLSL compilation. HLSL rules are always used when compiling HLSL.
void SetHlslOffsets(bool hlsl_offsets) {
shaderc_compile_options_set_hlsl_offsets(options_, hlsl_offsets);
}
// Sets the base binding number used for for a uniform resource type when
// automatically assigning bindings. For GLSL compilation, sets the lowest
// automatically assigned number. For HLSL compilation, the regsiter number
// assigned to the resource is added to this specified base.
void SetBindingBase(shaderc_uniform_kind kind, uint32_t base) {
shaderc_compile_options_set_binding_base(options_, kind, base);
}
// Like SetBindingBase, but only takes effect when compiling a given shader
// stage. The stage is assumed to be one of vertex, fragment, tessellation
// evaluation, tesselation control, geometry, or compute.
void SetBindingBaseForStage(shaderc_shader_kind shader_kind,
shaderc_uniform_kind kind, uint32_t base) {
shaderc_compile_options_set_binding_base_for_stage(options_, shader_kind,
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,
const std::string& reg,
const std::string& set,
const std::string& binding) {
shaderc_compile_options_set_hlsl_register_set_and_binding_for_stage(
options_, shader_kind, reg.c_str(), set.c_str(), binding.c_str());
}
// Sets a descriptor set and binding for an HLSL register in any stage.
// Copies the parameter strings.
void SetHlslRegisterSetAndBinding(const std::string& reg,
const std::string& set,
const std::string& binding) {
shaderc_compile_options_set_hlsl_register_set_and_binding(
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);
}
// Sets whether the compiler should invert position.Y output in vertex shader.
void SetInvertY(bool enable) {
shaderc_compile_options_set_invert_y(options_, enable);
}
// Sets whether the compiler should generates code for max an min which,
// if given a NaN operand, will return the other operand. Similarly, the
// clamp builtin will favour the non-NaN operands, as if clamp were
// implemented as a composition of max and min.
void SetNanClamp(bool enable) {
shaderc_compile_options_set_nan_clamp(options_, enable);
}
private:
CompileOptions& operator=(const CompileOptions& other) = delete;
shaderc_compile_options_t options_;
std::unique_ptr<IncluderInterface> includer_;
friend class Compiler;
};
// The compilation context for compiling source to SPIR-V.
class Compiler {
public:
Compiler() : compiler_(shaderc_compiler_initialize()) {}
~Compiler() { shaderc_compiler_release(compiler_); }
Compiler(Compiler&& other) {
compiler_ = other.compiler_;
other.compiler_ = nullptr;
}
bool IsValid() const { return compiler_ != nullptr; }
// Compiles the given source GLSL and returns a SPIR-V binary module
// compilation result.
// The source_text parameter must be a valid pointer.
// The source_text_size parameter must be the length of the source text.
// The shader_kind parameter either forces the compilation to be done with a
// specified shader kind, or hint the compiler how to determine the exact
// shader kind. If the shader kind is set to shaderc_glslc_infer_from_source,
// the compiler will try to deduce the shader kind from the source string and
// a failure in this proess will generate an error. Currently only #pragma
// annotation is supported. If the shader kind is set to one of the default
// shader kinds, the compiler will fall back to the specified default shader
// kind in case it failed to deduce the shader kind from the source string.
// The input_file_name is a null-termintated string. It is used as a tag to
// identify the source string in cases like emitting error messages. It
// doesn't have to be a 'file name'.
// The entry_point_name parameter is a null-terminated string specifying
// the entry point name for HLSL compilation. For GLSL compilation, the
// entry point name is assumed to be "main".
// The compilation is passed any options specified in the CompileOptions
// parameter.
// It is valid for the returned CompilationResult object to outlive this
// compiler object.
// Note when the options_ has disassembly mode or preprocessing only mode set
// on, the returned CompilationResult will hold a text string, instead of a
// SPIR-V binary generated with default options.
SpvCompilationResult CompileGlslToSpv(const char* source_text,
size_t source_text_size,
shaderc_shader_kind shader_kind,
const char* input_file_name,
const char* entry_point_name,
const CompileOptions& options) const {
shaderc_compilation_result_t compilation_result = shaderc_compile_into_spv(
compiler_, source_text, source_text_size, shader_kind, input_file_name,
entry_point_name, options.options_);
return SpvCompilationResult(compilation_result);
}
// Compiles the given source shader and returns a SPIR-V binary module
// compilation result.
// Like the first CompileGlslToSpv method but assumes the entry point name
// is "main".
SpvCompilationResult CompileGlslToSpv(const char* source_text,
size_t source_text_size,
shaderc_shader_kind shader_kind,
const char* input_file_name,
const CompileOptions& options) const {
return CompileGlslToSpv(source_text, source_text_size, shader_kind,
input_file_name, "main", options);
}
// Compiles the given source GLSL and returns a SPIR-V binary module
// compilation result.
// Like the previous CompileGlslToSpv method but uses default options.
SpvCompilationResult CompileGlslToSpv(const char* source_text,
size_t source_text_size,
shaderc_shader_kind shader_kind,
const char* input_file_name) const {
shaderc_compilation_result_t compilation_result =
shaderc_compile_into_spv(compiler_, source_text, source_text_size,
shader_kind, input_file_name, "main", nullptr);
return SpvCompilationResult(compilation_result);
}
// Compiles the given source shader and returns a SPIR-V binary module
// compilation result.
// Like the first CompileGlslToSpv method but the source is provided as
// a std::string, and we assume the entry point is "main".
SpvCompilationResult CompileGlslToSpv(const std::string& source_text,
shaderc_shader_kind shader_kind,
const char* input_file_name,
const CompileOptions& options) const {
return CompileGlslToSpv(source_text.data(), source_text.size(), shader_kind,
input_file_name, options);
}
// Compiles the given source shader and returns a SPIR-V binary module
// compilation result.
// Like the first CompileGlslToSpv method but the source is provided as
// a std::string.
SpvCompilationResult CompileGlslToSpv(const std::string& source_text,
shaderc_shader_kind shader_kind,
const char* input_file_name,
const char* entry_point_name,
const CompileOptions& options) const {
return CompileGlslToSpv(source_text.data(), source_text.size(), shader_kind,
input_file_name, entry_point_name, options);
}
// Compiles the given source GLSL and returns a SPIR-V binary module
// compilation result.
// Like the previous CompileGlslToSpv method but assumes the entry point
// name is "main".
SpvCompilationResult CompileGlslToSpv(const std::string& source_text,
shaderc_shader_kind shader_kind,
const char* input_file_name) const {
return CompileGlslToSpv(source_text.data(), source_text.size(), shader_kind,
input_file_name);
}
// Assembles the given SPIR-V assembly and returns a SPIR-V binary module
// compilation result.
// The assembly should follow the syntax defined in the SPIRV-Tools project
// (https://github.com/KhronosGroup/SPIRV-Tools/blob/master/syntax.md).
// It is valid for the returned CompilationResult object to outlive this
// compiler object.
// The assembling will pick options suitable for assembling specified in the
// CompileOptions parameter.
SpvCompilationResult AssembleToSpv(const char* source_assembly,
size_t source_assembly_size,
const CompileOptions& options) const {
return SpvCompilationResult(shaderc_assemble_into_spv(
compiler_, source_assembly, source_assembly_size, options.options_));
}
// Assembles the given SPIR-V assembly and returns a SPIR-V binary module
// compilation result.
// Like the first AssembleToSpv method but uses the default compiler options.
SpvCompilationResult AssembleToSpv(const char* source_assembly,
size_t source_assembly_size) const {
return SpvCompilationResult(shaderc_assemble_into_spv(
compiler_, source_assembly, source_assembly_size, nullptr));
}
// Assembles the given SPIR-V assembly and returns a SPIR-V binary module
// compilation result.
// Like the first AssembleToSpv method but the source is provided as a
// std::string.
SpvCompilationResult AssembleToSpv(const std::string& source_assembly,
const CompileOptions& options) const {
return SpvCompilationResult(
shaderc_assemble_into_spv(compiler_, source_assembly.data(),
source_assembly.size(), options.options_));
}
// Assembles the given SPIR-V assembly and returns a SPIR-V binary module
// compilation result.
// Like the first AssembleToSpv method but the source is provided as a
// std::string and also uses default compiler options.
SpvCompilationResult AssembleToSpv(const std::string& source_assembly) const {
return SpvCompilationResult(shaderc_assemble_into_spv(
compiler_, source_assembly.data(), source_assembly.size(), nullptr));
}
// Compiles the given source GLSL and returns the SPIR-V assembly text
// compilation result.
// Options are similar to the first CompileToSpv method.
AssemblyCompilationResult CompileGlslToSpvAssembly(
const char* source_text, size_t source_text_size,
shaderc_shader_kind shader_kind, const char* input_file_name,
const char* entry_point_name, const CompileOptions& options) const {
shaderc_compilation_result_t compilation_result =
shaderc_compile_into_spv_assembly(
compiler_, source_text, source_text_size, shader_kind,
input_file_name, entry_point_name, options.options_);
return AssemblyCompilationResult(compilation_result);
}
// Compiles the given source GLSL and returns the SPIR-V assembly text
// compilation result.
// Similare to the previous method, but assumes entry point name is "main".
AssemblyCompilationResult CompileGlslToSpvAssembly(
const char* source_text, size_t source_text_size,
shaderc_shader_kind shader_kind, const char* input_file_name,
const CompileOptions& options) const {
return CompileGlslToSpvAssembly(source_text, source_text_size, shader_kind,
input_file_name, "main", options);
}
// Compiles the given source GLSL and returns the SPIR-V assembly text
// result. Like the first CompileGlslToSpvAssembly method but the source
// is provided as a std::string. Options are otherwise similar to
// the first CompileToSpv method.
AssemblyCompilationResult CompileGlslToSpvAssembly(
const std::string& source_text, shaderc_shader_kind shader_kind,
const char* input_file_name, const char* entry_point_name,
const CompileOptions& options) const {
return CompileGlslToSpvAssembly(source_text.data(), source_text.size(),
shader_kind, input_file_name,
entry_point_name, options);
}
// Compiles the given source GLSL and returns the SPIR-V assembly text
// result. Like the previous CompileGlslToSpvAssembly method but assumes
// the entry point name is "main".
AssemblyCompilationResult CompileGlslToSpvAssembly(
const std::string& source_text, shaderc_shader_kind shader_kind,
const char* input_file_name, const CompileOptions& options) const {
return CompileGlslToSpvAssembly(source_text, shader_kind, input_file_name,
"main", options);
}
// Preprocesses the given source GLSL and returns the preprocessed
// source text as a compilation result.
// Options are similar to the first CompileToSpv method.
PreprocessedSourceCompilationResult PreprocessGlsl(
const char* source_text, size_t source_text_size,
shaderc_shader_kind shader_kind, const char* input_file_name,
const CompileOptions& options) const {
shaderc_compilation_result_t compilation_result =
shaderc_compile_into_preprocessed_text(
compiler_, source_text, source_text_size, shader_kind,
input_file_name, "main", options.options_);
return PreprocessedSourceCompilationResult(compilation_result);
}
// Preprocesses the given source GLSL and returns text result. Like the first
// PreprocessGlsl method but the source is provided as a std::string.
// Options are otherwise similar to the first CompileToSpv method.
PreprocessedSourceCompilationResult PreprocessGlsl(
const std::string& source_text, shaderc_shader_kind shader_kind,
const char* input_file_name, const CompileOptions& options) const {
return PreprocessGlsl(source_text.data(), source_text.size(), shader_kind,
input_file_name, options);
}
private:
Compiler(const Compiler&) = delete;
Compiler& operator=(const Compiler& other) = delete;
shaderc_compiler_t compiler_;
};
} // namespace shaderc
#endif // SHADERC_SHADERC_HPP_

View File

@ -1,39 +0,0 @@
// 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.
#ifndef SHADERC_STATUS_H_
#define SHADERC_STATUS_H_
#ifdef __cplusplus
extern "C" {
#endif
// Indicate the status of a compilation.
typedef enum {
shaderc_compilation_status_success = 0,
shaderc_compilation_status_invalid_stage = 1, // error stage deduction
shaderc_compilation_status_compilation_error = 2,
shaderc_compilation_status_internal_error = 3, // unexpected failure
shaderc_compilation_status_null_result_object = 4,
shaderc_compilation_status_invalid_assembly = 5,
shaderc_compilation_status_validation_error = 6,
shaderc_compilation_status_transformation_error = 7,
shaderc_compilation_status_configuration_error = 8,
} shaderc_compilation_status;
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // SHADERC_STATUS_H_

View File

@ -1,37 +0,0 @@
// 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.
#ifndef SHADERC_VISIBILITY_H_
#define SHADERC_VISIBILITY_H_
// SHADERC_EXPORT tags symbol that will be exposed by the shared libraries.
#if defined(SHADERC_SHAREDLIB)
#if defined(_WIN32)
#if defined(SHADERC_IMPLEMENTATION)
#define SHADERC_EXPORT __declspec(dllexport)
#else
#define SHADERC_EXPORT __declspec(dllimport)
#endif
#else
#if defined(SHADERC_IMPLEMENTATION)
#define SHADERC_EXPORT __attribute__((visibility("default")))
#else
#define SHADERC_EXPORT
#endif
#endif
#else
#define SHADERC_EXPORT
#endif
#endif // SHADERC_VISIBILITY_H_

View File

@ -1,413 +0,0 @@
// Copyright 2015 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.
#ifndef COMMON_SHADERS_FOR_TESTS_H_
#define COMMON_SHADERS_FOR_TESTS_H_
#ifdef __cplusplus
extern "C" {
#endif
// The minimal shader, without a version directive.
const char kMinimalShaderWithoutVersion[] = "void main(){}";
// The minimal shader, with a version directive.
const char kMinimalShader[] =
"#version 140\n"
"void main(){}";
const char kMinimalHlslShader[] =
"float4 EntryPoint(uint index : SV_VERTEXID) : SV_POSITION\n"
"{ return float4(1.0, 2.0, 3.0, 4.0); }";
const char kMinimalShaderWithMacro[] =
"#version 140\n"
"#define E main\n"
"void E(){}\n";
// The minimal shader that needs valueless predefinition of 'E' to compile.
const char kValuelessPredefinitionShader[] =
"#version 140\n"
"#ifdef E\n"
"void main(){}\n"
"#else\n"
"#error\n"
"#endif";
// By default the compiler will emit a warning on line 2 complaining
// that 'float' is a deprecated attribute in version 130. Use verison 140
// because some versions of glslang will error out for a too-low version
// when generating SPIR-V.
const char kDeprecatedAttributeShader[] =
"#version 400\n"
"layout(location = 0) attribute float x;\n"
"void main() {}\n";
// By default the compiler will emit a warning as version 550 is an unknown
// version.
const char kMinimalUnknownVersionShader[] =
"#version 550\n"
"void main() {}\n";
// gl_ClipDistance doesn't exist in es profile (at least until 3.10).
const char kCoreVertShaderWithoutVersion[] =
"void main() {\n"
"gl_ClipDistance[0] = 5.;\n"
"}\n";
// Generated debug information should contain the name of the vector:
// debug_info_sample.
const char kMinimalDebugInfoShader[] =
"#version 140\n"
"void main(){\n"
"vec2 debug_info_sample = vec2(1.0,1.0);\n"
"}\n";
// Compiler should generate two errors.
const char kTwoErrorsShader[] =
"#version 150\n"
"#error\n"
"#error\n"
"void main(){}\n";
// Compiler should generate two warnings.
const char kTwoWarningsShader[] =
"#version 400\n"
"layout(location = 0) attribute float x;\n"
"layout(location = 1) attribute float y;\n"
"void main(){}\n";
// A shader that compiles under OpenGL compatibility profile rules,
// but not OpenGL core profile rules.
const char kOpenGLCompatibilityFragmentShader[] =
R"(#version 100
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
void main() { int t = gl_VertexID; })";
// Empty 310 es shader. It is valid for vertex, fragment, compute shader kind.
const char kEmpty310ESShader[] =
"#version 310 es\n"
"void main() {}\n";
// Vertex only shader.
const char kVertexOnlyShader[] =
"#version 310 es\n"
"void main() {\n"
" gl_Position = vec4(1.);\n"
"}";
// TessControl only shader.
const char kTessControlOnlyShader[] =
"#version 440 core\n"
"layout(vertices = 3) out;\n"
"void main() { }";
// TessEvaluation only shader.
const char kTessEvaluationOnlyShader[] =
"#version 440 core\n"
"layout(triangles) in;\n"
"void main() { }";
// Geometry only shader.
const char kGeometryOnlyShader[] =
"#version 150 core\n"
"layout (triangles) in;\n"
"layout (line_strip, max_vertices = 4) out;\n"
"void main() { }";
// Vertex only shader with #pragma annotation.
const char kVertexOnlyShaderWithPragma[] =
"#version 310 es\n"
"#pragma shader_stage(vertex)\n"
"void main() {\n"
" gl_Position = vec4(1.);\n"
"}";
// Fragment only shader with #pragma annotation.
const char kFragmentOnlyShaderWithPragma[] =
"#version 310 es\n"
"#pragma shader_stage(fragment)\n"
"void main() {\n"
" gl_FragDepth = 10.;\n"
"}";
// TessControl only shader with #pragma annotation.
const char kTessControlOnlyShaderWithPragma[] =
"#version 440 core\n"
"#pragma shader_stage(tesscontrol)\n"
"layout(vertices = 3) out;\n"
"void main() { }";
// TessEvaluation only shader with #pragma annotation.
const char kTessEvaluationOnlyShaderWithPragma[] =
"#version 440 core\n"
"#pragma shader_stage(tesseval)\n"
"layout(triangles) in;\n"
"void main() { }";
// Geometry only shader with #pragma annotation.
const char kGeometryOnlyShaderWithPragma[] =
"#version 150 core\n"
"#pragma shader_stage(geometry)\n"
"layout (triangles) in;\n"
"layout (line_strip, max_vertices = 4) out;\n"
"void main() { }";
// Compute only shader with #pragma annotation.
const char kComputeOnlyShaderWithPragma[] =
"#version 310 es\n"
"#pragma shader_stage(compute)\n"
"void main() {\n"
" uvec3 temp = gl_WorkGroupID;\n"
"}";
// NV mesh shader without #pragma.
const char kNVMeshShader[] =
"#version 450\n"
"#extension GL_NV_mesh_shader : enable\n"
"layout(local_size_x=8) in;\n"
"layout(max_vertices=5) out;\n"
"layout(max_primitives=10) out;\n"
"layout(triangles) out;\n"
"void main() {\n"
" gl_MeshVerticesNV[gl_LocalInvocationID.x].gl_Position = vec4(0.0);\n"
"}\n";
// NV mesh shader with #pragma annotation.
const char kNVMeshShaderWithPragma[] =
"#version 450\n"
"#extension GL_NV_mesh_shader : enable\n"
"#pragma shader_stage(mesh)\n"
"layout(local_size_x=8) in;\n"
"layout(max_vertices=5) out;\n"
"layout(max_primitives=10) out;\n"
"layout(triangles) out;\n"
"void main() {\n"
" gl_MeshVerticesNV[gl_LocalInvocationID.x].gl_Position = vec4(0.0);\n"
"}\n";
// NV task shader without #pragma annotation.
const char kNVTaskShader[] =
"#version 450\n"
"#extension GL_NV_mesh_shader : enable\n"
"layout(local_size_x=8) in;\n"
"void main() {\n"
" gl_TaskCountNV = 2;\n"
"}\n";
// NV task shader with #pragma annotation.
const char kNVTaskShaderWithPragma[] =
"#version 450\n"
"#extension GL_NV_mesh_shader : enable\n"
"#pragma shader_stage(task)\n"
"layout(local_size_x=8) in;\n"
"void main() {\n"
" gl_TaskCountNV = 2;\n"
"}\n";
// Vertex only shader with invalid #pragma annotation.
const char kVertexOnlyShaderWithInvalidPragma[] =
"#version 310 es\n"
"#pragma shader_stage(fragment)\n"
"void main() {\n"
" gl_Position = vec4(1.);\n"
"}";
// Parts of a valid disassembly of a minimal shader. We only check certain
// parts since Glslang code generation changes in incidental ways.
const char* kMinimalShaderDisassemblySubstrings[] = {
"; SPIR-V\n"
"; Version: 1.0\n"
"; Generator: Google Shaderc over Glslang; 10\n"
"; Bound:",
" OpCapability Shader\n",
" %1 = OpExtInstImport \"GLSL.std.450\"\n",
" OpMemoryModel Logical GLSL450\n",
" OpReturn\n",
" OpFunctionEnd\n"};
const char* kMinimalShaderDebugInfoDisassemblySubstrings[] = {
"; SPIR-V\n"
"; Version: 1.0\n"
"; Generator: Google Shaderc over Glslang; 10\n"
"; Bound:",
" OpCapability Shader\n",
" %2 = OpExtInstImport \"GLSL.std.450\"\n",
" OpMemoryModel Logical GLSL450\n",
" OpReturn\n",
" OpFunctionEnd\n"};
const char kMinimalShaderAssembly[] = R"(
; SPIR-V
; Version: 1.0
; Generator: Google Shaderc over Glslang; 10
; Bound: 6
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %4 "main"
OpSource ESSL 310
OpName %4 "main"
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%4 = OpFunction %2 None %3
%5 = OpLabel
OpReturn
OpFunctionEnd)";
const char kShaderWithUniformsWithoutBindings[] =
R"(#version 450
#extension GL_ARB_sparse_texture2 : enable
uniform texture2D my_tex;
uniform sampler my_sam;
layout(rgba32f) uniform image2D my_img;
layout(rgba32f) uniform imageBuffer my_imbuf;
uniform block { float x; float y; } my_ubo;
void main() {
texture(sampler2D(my_tex,my_sam),vec2(1.0));
vec4 t;
sparseImageLoadARB(my_img,ivec2(0),t);
imageLoad(my_imbuf,42);
float x = my_ubo.x;
})";
// A GLSL vertex shader with a weirdly packed block.
const char kGlslShaderWeirdPacking[] =
R"(#version 450
layout(set=0, binding=0)
buffer B { float x; vec3 foo; } my_ssbo;
void main() { my_ssbo.x = 1.0; })";
// A HLSL fragment shader with a weirdly packed block.
const char kHlslFragShaderWithRegisters[] =
R"(Buffer<float> t4 : register(t4);
Buffer<float> t5 : register(t5);
float4 main() : SV_Target0 {
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(); })";
// A GLSL task shader using a regular barrier.
const char kGlslShaderTaskBarrier[] =
R"(#version 450
#extension GL_NV_mesh_shader : enable
layout(local_size_x = 32) in;
void main() { barrier(); })";
// A GLSL task shader using the Subgroups feature.
const char kGlslShaderTaskSubgroupBarrier[] =
R"(#version 450
#extension GL_NV_mesh_shader : enable
#extension GL_KHR_shader_subgroup_basic : enable
layout(local_size_x = 32) in;
void main() { subgroupBarrier(); })";
// A GLSL mesh shader using a regular barrier.
const char kGlslShaderMeshBarrier[] =
R"(#version 450
#extension GL_NV_mesh_shader : enable
layout(local_size_x = 32) in;
layout(max_vertices=81) out;
layout(max_primitives=32) out;
layout(triangles) out;
void main() { barrier(); })";
// A GLSL mesh shader using the Subgroups feature.
const char kGlslShaderMeshSubgroupBarrier[] =
R"(#version 450
#extension GL_NV_mesh_shader : enable
#extension GL_KHR_shader_subgroup_basic : enable
layout(local_size_x = 32) in;
layout(max_vertices=81) out;
layout(max_primitives=32) out;
layout(triangles) out;
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);
})";
const char kHlslWaveActiveSumeComputeShader[] =
R"(struct S { uint val; uint result; };
[[vk::binding(0,0)]]
RWStructuredBuffer<S> MyBuffer;
[numthreads(32, 1, 1)]
void main(uint3 id : SV_DispatchThreadID) {
MyBuffer[id.x].result = WaveActiveSum(MyBuffer[id.x].val);
})";
const char kHlslMemLayoutResourceSelect[] =
R"(cbuffer Foo { float a; float3 b; }
[[vk::binding(0,0)]]
Texture2D Tex;
[[vk::binding(1,0)]]
SamplerState Sampler1;
[[vk::binding(2,0)]]
SamplerState Sampler2;
static const int val = 42;
float4 main() : SV_Target {
SamplerState samp;
if (val > 5)
samp = Sampler1;
else
samp = Sampler2;
return Tex.Sample(samp, float2(0.5, 0.5)) + float4(a, b);
})";
const char kGlslShaderWithClamp[] =
R"(#version 450
layout(location=0) in vec4 i;
layout(location=0) out vec4 o;
void main() { o = clamp(i, vec4(0.5), vec4(1.0)); }
)";
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // COMMON_SHADERS_FOR_TESTS_H_

View File

@ -1,794 +0,0 @@
// Copyright 2015 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.
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <memory>
#include <sstream>
#include <vector>
#include "libshaderc_util/compiler.h"
#include "libshaderc_util/counting_includer.h"
#include "libshaderc_util/resources.h"
#include "libshaderc_util/spirv_tools_wrapper.h"
#include "libshaderc_util/version_profile.h"
#include "shaderc_private.h"
#include "spirv/unified1/spirv.hpp"
#if (defined(_MSC_VER) && !defined(_CPPUNWIND)) || !defined(__EXCEPTIONS)
#define TRY_IF_EXCEPTIONS_ENABLED
#define CATCH_IF_EXCEPTIONS_ENABLED(X) if (0)
#else
#define TRY_IF_EXCEPTIONS_ENABLED try
#define CATCH_IF_EXCEPTIONS_ENABLED(X) catch (X)
#endif
namespace {
// Returns shader stage (ie: vertex, fragment, etc.) in response to forced
// shader kinds. If the shader kind is not a forced kind, returns EshLangCount
// to let #pragma annotation or shader stage deducer determine the stage to
// use.
EShLanguage GetForcedStage(shaderc_shader_kind kind) {
switch (kind) {
case shaderc_glsl_vertex_shader:
return EShLangVertex;
case shaderc_glsl_fragment_shader:
return EShLangFragment;
case shaderc_glsl_compute_shader:
return EShLangCompute;
case shaderc_glsl_geometry_shader:
return EShLangGeometry;
case shaderc_glsl_tess_control_shader:
return EShLangTessControl;
case shaderc_glsl_tess_evaluation_shader:
return EShLangTessEvaluation;
case shaderc_glsl_raygen_shader:
return EShLangRayGenNV;
case shaderc_glsl_anyhit_shader:
return EShLangAnyHitNV;
case shaderc_glsl_closesthit_shader:
return EShLangClosestHitNV;
case shaderc_glsl_miss_shader:
return EShLangMissNV;
case shaderc_glsl_intersection_shader:
return EShLangIntersectNV;
case shaderc_glsl_callable_shader:
return EShLangCallableNV;
case shaderc_glsl_task_shader:
return EShLangTaskNV;
case shaderc_glsl_mesh_shader:
return EShLangMeshNV;
case shaderc_glsl_infer_from_source:
case shaderc_glsl_default_vertex_shader:
case shaderc_glsl_default_fragment_shader:
case shaderc_glsl_default_compute_shader:
case shaderc_glsl_default_geometry_shader:
case shaderc_glsl_default_tess_control_shader:
case shaderc_glsl_default_tess_evaluation_shader:
case shaderc_glsl_default_raygen_shader:
case shaderc_glsl_default_anyhit_shader:
case shaderc_glsl_default_closesthit_shader:
case shaderc_glsl_default_miss_shader:
case shaderc_glsl_default_intersection_shader:
case shaderc_glsl_default_callable_shader:
case shaderc_glsl_default_task_shader:
case shaderc_glsl_default_mesh_shader:
case shaderc_spirv_assembly:
return EShLangCount;
}
assert(0 && "Unhandled shaderc_shader_kind");
return EShLangCount;
}
// A wrapper functor class to be used as stage deducer for libshaderc_util
// Compile() interface. When the given shader kind is one of the default shader
// kinds, this functor will be called if #pragma is not found in the source
// code. And it returns the corresponding shader stage. When the shader kind is
// a forced shader kind, this functor won't be called and it simply returns
// EShLangCount to make the syntax correct. When the shader kind is set to
// shaderc_glsl_deduce_from_pragma, this functor also returns EShLangCount, but
// the compiler should emit error if #pragma annotation is not found in this
// case.
class StageDeducer {
public:
explicit StageDeducer(
shaderc_shader_kind kind = shaderc_glsl_infer_from_source)
: kind_(kind), error_(false){}
// The method that underlying glslang will call to determine the shader stage
// to be used in current compilation. It is called only when there is neither
// forced shader kind (or say stage, in the view of glslang), nor #pragma
// annotation in the source code. This method transforms an user defined
// 'default' shader kind to the corresponding shader stage. As this is the
// last trial to determine the shader stage, failing to find the corresponding
// shader stage will record an error.
// Note that calling this method more than once during one compilation will
// have the error recorded for the previous call been overwriten by the next
// call.
EShLanguage operator()(std::ostream* /*error_stream*/,
const shaderc_util::string_piece& /*error_tag*/) {
EShLanguage stage = GetDefaultStage(kind_);
if (stage == EShLangCount) {
error_ = true;
} else {
error_ = false;
}
return stage;
}
// Returns true if there is error during shader stage deduction.
bool error() const { return error_; }
private:
// Gets the corresponding shader stage for a given 'default' shader kind. All
// other kinds are mapped to EShLangCount which should not be used.
EShLanguage GetDefaultStage(shaderc_shader_kind kind) const {
switch (kind) {
case shaderc_glsl_vertex_shader:
case shaderc_glsl_fragment_shader:
case shaderc_glsl_compute_shader:
case shaderc_glsl_geometry_shader:
case shaderc_glsl_tess_control_shader:
case shaderc_glsl_tess_evaluation_shader:
case shaderc_glsl_infer_from_source:
case shaderc_glsl_raygen_shader:
case shaderc_glsl_anyhit_shader:
case shaderc_glsl_closesthit_shader:
case shaderc_glsl_miss_shader:
case shaderc_glsl_intersection_shader:
case shaderc_glsl_callable_shader:
case shaderc_glsl_task_shader:
case shaderc_glsl_mesh_shader:
return EShLangCount;
case shaderc_glsl_default_vertex_shader:
return EShLangVertex;
case shaderc_glsl_default_fragment_shader:
return EShLangFragment;
case shaderc_glsl_default_compute_shader:
return EShLangCompute;
case shaderc_glsl_default_geometry_shader:
return EShLangGeometry;
case shaderc_glsl_default_tess_control_shader:
return EShLangTessControl;
case shaderc_glsl_default_tess_evaluation_shader:
return EShLangTessEvaluation;
case shaderc_glsl_default_raygen_shader:
return EShLangRayGenNV;
case shaderc_glsl_default_anyhit_shader:
return EShLangAnyHitNV;
case shaderc_glsl_default_closesthit_shader:
return EShLangClosestHitNV;
case shaderc_glsl_default_miss_shader:
return EShLangMissNV;
case shaderc_glsl_default_intersection_shader:
return EShLangIntersectNV;
case shaderc_glsl_default_callable_shader:
return EShLangCallableNV;
case shaderc_glsl_default_task_shader:
return EShLangTaskNV;
case shaderc_glsl_default_mesh_shader:
return EShLangMeshNV;
case shaderc_spirv_assembly:
return EShLangCount;
}
assert(0 && "Unhandled shaderc_shader_kind");
return EShLangCount;
}
shaderc_shader_kind kind_;
bool error_;
};
// A bridge between the libshaderc includer and libshaderc_util includer.
class InternalFileIncluder : public shaderc_util::CountingIncluder {
public:
InternalFileIncluder(const shaderc_include_resolve_fn resolver,
const shaderc_include_result_release_fn result_releaser,
void* user_data)
: resolver_(resolver),
result_releaser_(result_releaser),
user_data_(user_data){}
InternalFileIncluder()
: resolver_(nullptr), result_releaser_(nullptr), user_data_(nullptr){}
private:
// Check the validity of the callbacks.
bool AreValidCallbacks() const {
return resolver_ != nullptr && result_releaser_ != nullptr;
}
// Maps CountingIncluder IncludeType value to a shaderc_include_type
// value.
shaderc_include_type GetIncludeType(IncludeType type) {
switch (type) {
case IncludeType::Local:
return shaderc_include_type_relative;
case IncludeType::System:
return shaderc_include_type_standard;
default:
break;
}
assert(0 && "Unhandled IncludeType");
return shaderc_include_type_relative;
}
// Resolves an include request for the requested source of the given
// type in the context of the specified requesting source. On success,
// returns a newly allocated IncludeResponse containing the fully resolved
// name of the requested source and the contents of that source.
// On failure, returns a newly allocated IncludeResponse where the
// resolved name member is an empty string, and the contents members
// contains error details.
virtual glslang::TShader::Includer::IncludeResult* include_delegate(
const char* requested_source, const char* requesting_source,
IncludeType type, size_t include_depth) override {
if (!AreValidCallbacks()) {
static const char kUnexpectedIncludeError[] =
"#error unexpected include directive";
return new glslang::TShader::Includer::IncludeResult{
"", kUnexpectedIncludeError, strlen(kUnexpectedIncludeError),
nullptr};
}
shaderc_include_result* include_result =
resolver_(user_data_, requested_source, GetIncludeType(type),
requesting_source, include_depth);
// Make a glslang IncludeResult from a shaderc_include_result. The
// user_data member of the IncludeResult is a pointer to the
// shaderc_include_result object, so we can later release the latter.
return new glslang::TShader::Includer::IncludeResult{
std::string(include_result->source_name,
include_result->source_name_length),
include_result->content, include_result->content_length,
include_result};
}
// Releases the given IncludeResult.
virtual void release_delegate(
glslang::TShader::Includer::IncludeResult* result) override {
if (result && result_releaser_) {
result_releaser_(user_data_,
static_cast<shaderc_include_result*>(result->userData));
}
delete result;
}
const shaderc_include_resolve_fn resolver_;
const shaderc_include_result_release_fn result_releaser_;
void* user_data_;
};
// Converts the target env to the corresponding one in shaderc_util::Compiler.
shaderc_util::Compiler::TargetEnv GetCompilerTargetEnv(shaderc_target_env env) {
switch (env) {
case shaderc_target_env_opengl:
return shaderc_util::Compiler::TargetEnv::OpenGL;
case shaderc_target_env_opengl_compat:
return shaderc_util::Compiler::TargetEnv::OpenGLCompat;
case shaderc_target_env_webgpu:
assert(false);
break;
case shaderc_target_env_vulkan:
default:
break;
}
return shaderc_util::Compiler::TargetEnv::Vulkan;
}
shaderc_util::Compiler::TargetEnvVersion GetCompilerTargetEnvVersion(
uint32_t version_number) {
using namespace shaderc_util;
if (static_cast<uint32_t>(Compiler::TargetEnvVersion::Vulkan_1_0) ==
version_number) {
return Compiler::TargetEnvVersion::Vulkan_1_0;
}
if (static_cast<uint32_t>(Compiler::TargetEnvVersion::Vulkan_1_1) ==
version_number) {
return Compiler::TargetEnvVersion::Vulkan_1_1;
}
if (static_cast<uint32_t>(Compiler::TargetEnvVersion::Vulkan_1_2) ==
version_number) {
return Compiler::TargetEnvVersion::Vulkan_1_2;
}
if (static_cast<uint32_t>(Compiler::TargetEnvVersion::Vulkan_1_3) ==
version_number) {
return Compiler::TargetEnvVersion::Vulkan_1_3;
}
if (static_cast<uint32_t>(Compiler::TargetEnvVersion::OpenGL_4_5) ==
version_number) {
return Compiler::TargetEnvVersion::OpenGL_4_5;
}
return Compiler::TargetEnvVersion::Default;
}
// 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;
#include "libshaderc_util/resources.inc"
#undef RESOURCE
default:
break;
}
assert(0 && "Should not have reached here");
return static_cast<shaderc_util::Compiler::Limit>(0);
}
// Returns the Compiler::UniformKind for the given shaderc_uniform_kind.
shaderc_util::Compiler::UniformKind GetUniformKind(shaderc_uniform_kind kind) {
switch (kind) {
case shaderc_uniform_kind_texture:
return shaderc_util::Compiler::UniformKind::Texture;
case shaderc_uniform_kind_sampler:
return shaderc_util::Compiler::UniformKind::Sampler;
case shaderc_uniform_kind_image:
return shaderc_util::Compiler::UniformKind::Image;
case shaderc_uniform_kind_buffer:
return shaderc_util::Compiler::UniformKind::Buffer;
case shaderc_uniform_kind_storage_buffer:
return shaderc_util::Compiler::UniformKind::StorageBuffer;
case shaderc_uniform_kind_unordered_access_view:
return shaderc_util::Compiler::UniformKind::UnorderedAccessView;
}
assert(0 && "Should not have reached here");
return static_cast<shaderc_util::Compiler::UniformKind>(0);
}
// Returns the Compiler::Stage for generic stage values in shaderc_shader_kind.
shaderc_util::Compiler::Stage GetStage(shaderc_shader_kind kind) {
switch (kind) {
case shaderc_vertex_shader:
return shaderc_util::Compiler::Stage::Vertex;
case shaderc_fragment_shader:
return shaderc_util::Compiler::Stage::Fragment;
case shaderc_compute_shader:
return shaderc_util::Compiler::Stage::Compute;
case shaderc_tess_control_shader:
return shaderc_util::Compiler::Stage::TessControl;
case shaderc_tess_evaluation_shader:
return shaderc_util::Compiler::Stage::TessEval;
case shaderc_geometry_shader:
return shaderc_util::Compiler::Stage::Geometry;
default:
break;
}
assert(0 && "Should not have reached here");
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;
void* include_user_data = nullptr;
};
shaderc_compile_options_t shaderc_compile_options_initialize() {
return new (std::nothrow) shaderc_compile_options;
}
shaderc_compile_options_t shaderc_compile_options_clone(
const shaderc_compile_options_t options) {
if (!options) {
return shaderc_compile_options_initialize();
}
return new (std::nothrow) shaderc_compile_options(*options);
}
void shaderc_compile_options_release(shaderc_compile_options_t options) {
delete options;
}
void shaderc_compile_options_add_macro_definition(
shaderc_compile_options_t options, const char* name, size_t name_length,
const char* value, size_t value_length) {
options->compiler.AddMacroDefinition(name, name_length, value, value_length);
}
void shaderc_compile_options_set_source_language(
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;
options->compiler.SetSourceLanguage(lang);
}
void shaderc_compile_options_set_generate_debug_info(
shaderc_compile_options_t options) {
options->compiler.SetGenerateDebugInfo();
}
void shaderc_compile_options_set_optimization_level(
shaderc_compile_options_t options, shaderc_optimization_level level) {
auto opt_level = shaderc_util::Compiler::OptimizationLevel::Zero;
switch (level) {
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;
}
options->compiler.SetOptimizationLevel(opt_level);
}
void shaderc_compile_options_set_forced_version_profile(
shaderc_compile_options_t options, int version, shaderc_profile profile) {
// Transfer the profile parameter from public enum type to glslang internal
// enum type. No default case here so that compiler will complain if new enum
// member is added later but not handled here.
switch (profile) {
case shaderc_profile_none:
options->compiler.SetForcedVersionProfile(version, ENoProfile);
break;
case shaderc_profile_core:
options->compiler.SetForcedVersionProfile(version, ECoreProfile);
break;
case shaderc_profile_compatibility:
options->compiler.SetForcedVersionProfile(version, ECompatibilityProfile);
break;
case shaderc_profile_es:
options->compiler.SetForcedVersionProfile(version, EEsProfile);
break;
}
}
void shaderc_compile_options_set_include_callbacks(
shaderc_compile_options_t options, shaderc_include_resolve_fn resolver,
shaderc_include_result_release_fn result_releaser, void* user_data) {
options->include_resolver = resolver;
options->include_result_releaser = result_releaser;
options->include_user_data = user_data;
}
void shaderc_compile_options_set_suppress_warnings(
shaderc_compile_options_t options) {
options->compiler.SetSuppressWarnings();
}
void shaderc_compile_options_set_target_env(shaderc_compile_options_t options,
shaderc_target_env target,
uint32_t version) {
options->target_env = target;
options->compiler.SetTargetEnv(GetCompilerTargetEnv(target),
GetCompilerTargetEnvVersion(version));
}
void shaderc_compile_options_set_target_spirv(shaderc_compile_options_t options,
shaderc_spirv_version ver) {
// We made the values match, so we can get away with a static cast.
options->compiler.SetTargetSpirv(
static_cast<shaderc_util::Compiler::SpirvVersion>(ver));
}
void shaderc_compile_options_set_warnings_as_errors(
shaderc_compile_options_t options) {
options->compiler.SetWarningsAsErrors();
}
void shaderc_compile_options_set_limit(shaderc_compile_options_t options,
shaderc_limit limit, int value) {
options->compiler.SetLimit(CompilerLimit(limit), value);
}
void shaderc_compile_options_set_auto_bind_uniforms(
shaderc_compile_options_t options, bool auto_bind) {
options->compiler.SetAutoBindUniforms(auto_bind);
}
void shaderc_compile_options_set_auto_combined_image_sampler(
shaderc_compile_options_t options, bool upgrade) {
options->compiler.SetAutoCombinedImageSampler(upgrade);
}
void shaderc_compile_options_set_hlsl_io_mapping(
shaderc_compile_options_t options, bool hlsl_iomap) {
options->compiler.SetHlslIoMapping(hlsl_iomap);
}
void shaderc_compile_options_set_hlsl_offsets(shaderc_compile_options_t options,
bool hlsl_offsets) {
options->compiler.SetHlslOffsets(hlsl_offsets);
}
void shaderc_compile_options_set_binding_base(shaderc_compile_options_t options,
shaderc_uniform_kind kind,
uint32_t base) {
options->compiler.SetAutoBindingBase(GetUniformKind(kind), base);
}
void shaderc_compile_options_set_binding_base_for_stage(
shaderc_compile_options_t options, shaderc_shader_kind shader_kind,
shaderc_uniform_kind kind, uint32_t base) {
options->compiler.SetAutoBindingBaseForStage(GetStage(shader_kind),
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) {
options->compiler.SetHlslRegisterSetAndBindingForStage(GetStage(shader_kind),
reg, set, binding);
}
void shaderc_compile_options_set_hlsl_register_set_and_binding(
shaderc_compile_options_t options, const char* reg, const char* set,
const char* binding) {
options->compiler.SetHlslRegisterSetAndBinding(reg, set, binding);
}
void shaderc_compile_options_set_hlsl_functionality1(
shaderc_compile_options_t options, bool enable) {
options->compiler.EnableHlslFunctionality1(enable);
}
void shaderc_compile_options_set_invert_y(
shaderc_compile_options_t options, bool enable) {
options->compiler.EnableInvertY(enable);
}
void shaderc_compile_options_set_nan_clamp(shaderc_compile_options_t options,
bool enable) {
options->compiler.SetNanClamp(enable);
}
shaderc_compiler_t shaderc_compiler_initialize() {
shaderc_compiler_t compiler = new (std::nothrow) shaderc_compiler;
if (compiler) {
compiler->initializer.reset(new shaderc_util::GlslangInitializer);
}
return compiler;
}
void shaderc_compiler_release(shaderc_compiler_t compiler) {
delete compiler;
}
namespace {
shaderc_compilation_result_t CompileToSpecifiedOutputType(
const shaderc_compiler_t compiler, const char* source_text,
size_t source_text_size, shaderc_shader_kind shader_kind,
const char* input_file_name, const char* entry_point_name,
const shaderc_compile_options_t additional_options,
shaderc_util::Compiler::OutputType output_type) {
auto* result = new (std::nothrow) shaderc_compilation_result_vector;
if (!result) return nullptr;
if (!input_file_name) {
result->messages = "Input file name string was null.";
result->num_errors = 1;
result->compilation_status = shaderc_compilation_status_compilation_error;
return result;
}
result->compilation_status = shaderc_compilation_status_invalid_stage;
bool compilation_succeeded = false; // In case we exit early.
std::vector<uint32_t> compilation_output_data;
size_t compilation_output_data_size_in_bytes = 0u;
if (!compiler->initializer) return result;
TRY_IF_EXCEPTIONS_ENABLED {
std::stringstream errors;
size_t total_warnings = 0;
size_t total_errors = 0;
std::string input_file_name_str(input_file_name);
EShLanguage forced_stage = GetForcedStage(shader_kind);
shaderc_util::string_piece source_string =
shaderc_util::string_piece(source_text, source_text + source_text_size);
StageDeducer stage_deducer(shader_kind);
if (additional_options) {
InternalFileIncluder includer(additional_options->include_resolver,
additional_options->include_result_releaser,
additional_options->include_user_data);
// Depends on return value optimization to avoid extra copy.
std::tie(compilation_succeeded, compilation_output_data,
compilation_output_data_size_in_bytes) =
additional_options->compiler.Compile(
source_string, forced_stage, input_file_name_str, entry_point_name,
// stage_deducer has a flag: error_, which we need to check later.
// We need to make this a reference wrapper, so that std::function
// won't make a copy for this callable object.
std::ref(stage_deducer), includer, output_type, &errors,
&total_warnings, &total_errors);
} else {
// Compile with default options.
InternalFileIncluder includer;
std::tie(compilation_succeeded, compilation_output_data,
compilation_output_data_size_in_bytes) =
shaderc_util::Compiler().Compile(
source_string, forced_stage, input_file_name_str, entry_point_name,
std::ref(stage_deducer), includer, output_type, &errors,
&total_warnings, &total_errors);
}
result->messages = errors.str();
result->SetOutputData(std::move(compilation_output_data));
result->output_data_size = compilation_output_data_size_in_bytes;
result->num_warnings = total_warnings;
result->num_errors = total_errors;
if (compilation_succeeded) {
result->compilation_status = shaderc_compilation_status_success;
} else {
// Check whether the error is caused by failing to deduce the shader
// stage. If it is the case, set the error type to shader kind error.
// Otherwise, set it to compilation error.
result->compilation_status =
stage_deducer.error() ? shaderc_compilation_status_invalid_stage
: shaderc_compilation_status_compilation_error;
}
}
CATCH_IF_EXCEPTIONS_ENABLED(...) {
result->compilation_status = shaderc_compilation_status_internal_error;
}
return result;
}
} // anonymous namespace
shaderc_compilation_result_t shaderc_compile_into_spv(
const shaderc_compiler_t compiler, const char* source_text,
size_t source_text_size, shaderc_shader_kind shader_kind,
const char* input_file_name, const char* entry_point_name,
const shaderc_compile_options_t additional_options) {
return CompileToSpecifiedOutputType(
compiler, source_text, source_text_size, shader_kind, input_file_name,
entry_point_name, additional_options,
shaderc_util::Compiler::OutputType::SpirvBinary);
}
shaderc_compilation_result_t shaderc_compile_into_spv_assembly(
const shaderc_compiler_t compiler, const char* source_text,
size_t source_text_size, shaderc_shader_kind shader_kind,
const char* input_file_name, const char* entry_point_name,
const shaderc_compile_options_t additional_options) {
return CompileToSpecifiedOutputType(
compiler, source_text, source_text_size, shader_kind, input_file_name,
entry_point_name, additional_options,
shaderc_util::Compiler::OutputType::SpirvAssemblyText);
}
shaderc_compilation_result_t shaderc_compile_into_preprocessed_text(
const shaderc_compiler_t compiler, const char* source_text,
size_t source_text_size, shaderc_shader_kind shader_kind,
const char* input_file_name, const char* entry_point_name,
const shaderc_compile_options_t additional_options) {
return CompileToSpecifiedOutputType(
compiler, source_text, source_text_size, shader_kind, input_file_name,
entry_point_name, additional_options,
shaderc_util::Compiler::OutputType::PreprocessedText);
}
shaderc_compilation_result_t shaderc_assemble_into_spv(
const shaderc_compiler_t compiler, const char* source_assembly,
size_t source_assembly_size,
const shaderc_compile_options_t additional_options) {
auto* result = new (std::nothrow) shaderc_compilation_result_spv_binary;
if (!result) return nullptr;
result->compilation_status = shaderc_compilation_status_invalid_assembly;
if (!compiler->initializer) return result;
if (source_assembly == nullptr) return result;
TRY_IF_EXCEPTIONS_ENABLED {
spv_binary assembling_output_data = nullptr;
std::string errors;
const auto target_env = additional_options ? additional_options->target_env
: shaderc_target_env_default;
const uint32_t target_env_version =
additional_options ? additional_options->target_env_version : 0;
const bool assembling_succeeded = shaderc_util::SpirvToolsAssemble(
GetCompilerTargetEnv(target_env),
GetCompilerTargetEnvVersion(target_env_version),
{source_assembly, source_assembly + source_assembly_size},
&assembling_output_data, &errors);
result->num_errors = !assembling_succeeded;
if (assembling_succeeded) {
result->SetOutputData(assembling_output_data);
result->output_data_size =
assembling_output_data->wordCount * sizeof(uint32_t);
result->compilation_status = shaderc_compilation_status_success;
} else {
result->messages = std::move(errors);
result->compilation_status = shaderc_compilation_status_invalid_assembly;
}
}
CATCH_IF_EXCEPTIONS_ENABLED(...) {
result->compilation_status = shaderc_compilation_status_internal_error;
}
return result;
}
size_t shaderc_result_get_length(const shaderc_compilation_result_t result) {
return result->output_data_size;
}
size_t shaderc_result_get_num_warnings(
const shaderc_compilation_result_t result) {
return result->num_warnings;
}
size_t shaderc_result_get_num_errors(
const shaderc_compilation_result_t result) {
return result->num_errors;
}
const char* shaderc_result_get_bytes(
const shaderc_compilation_result_t result) {
return result->GetBytes();
}
void shaderc_result_release(shaderc_compilation_result_t result) {
delete result;
}
const char* shaderc_result_get_error_message(
const shaderc_compilation_result_t result) {
return result->messages.c_str();
}
shaderc_compilation_status shaderc_result_get_compilation_status(
const shaderc_compilation_result_t result) {
return result->compilation_status;
}
void shaderc_get_spv_version(unsigned int* version, unsigned int* revision) {
*version = spv::Version;
*revision = spv::Revision;
}
bool shaderc_parse_version_profile(const char* str, int* version,
shaderc_profile* profile) {
EProfile glslang_profile;
bool success = shaderc_util::ParseVersionProfile(
std::string(str, strlen(str)), version, &glslang_profile);
if (!success) return false;
switch (glslang_profile) {
case EEsProfile:
*profile = shaderc_profile_es;
return true;
case ECoreProfile:
*profile = shaderc_profile_core;
return true;
case ECompatibilityProfile:
*profile = shaderc_profile_compatibility;
return true;
case ENoProfile:
*profile = shaderc_profile_none;
return true;
case EBadProfile:
case EProfileCount:
return false;
}
// Shouldn't reach here, all profile enum should be handled above.
// Be strict to return false.
return false;
}

View File

@ -1,54 +0,0 @@
// Copyright 2016 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.
#include "shaderc/shaderc.h"
#include <assert.h>
#include <string.h>
// Because we want to test this as a plain old C file, we cannot use
// gtest, so just run a simple smoke test.
int main() {
const char* test_program =
"#version 310 es\n"
"layout(location = 0) in highp vec4 vtxColor;\n"
"layout(location = 0) out highp vec4 outColor;\n"
"void main() {\n"
" outColor = vtxColor;"
"}\n";
shaderc_compiler_t compiler;
shaderc_compilation_result_t result;
shaderc_compile_options_t options;
compiler = shaderc_compiler_initialize();
options = shaderc_compile_options_initialize();
shaderc_compile_options_add_macro_definition(options, "FOO", 3, "1", 1);
result = shaderc_compile_into_spv(
compiler, test_program, strlen(test_program),
shaderc_glsl_fragment_shader, "a.glsl", "main", options);
assert(result);
if (shaderc_result_get_compilation_status(result) !=
shaderc_compilation_status_success) {
// Early exit on failure.
return -1;
}
shaderc_result_release(result);
shaderc_compile_options_release(options);
shaderc_compiler_release(compiler);
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,139 +0,0 @@
// Copyright 2015 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.
#ifndef LIBSHADERC_SRC_SHADERC_PRIVATE_H_
#define LIBSHADERC_SRC_SHADERC_PRIVATE_H_
#include <cassert>
#include <cstdint>
#include <string>
#include <vector>
#include "shaderc/shaderc.h"
#include "libshaderc_util/compiler.h"
#include "spirv-tools/libspirv.h"
// Described in shaderc.h.
struct shaderc_compilation_result {
virtual ~shaderc_compilation_result() {}
// Returns the data from this compilation as a sequence of bytes.
virtual const char* GetBytes() const = 0;
// The size of the output data in term of bytes.
size_t output_data_size = 0;
// Compilation messages.
std::string messages;
// Number of errors.
size_t num_errors = 0;
// Number of warnings.
size_t num_warnings = 0;
// Compilation status.
shaderc_compilation_status compilation_status =
shaderc_compilation_status_null_result_object;
};
// Compilation result class using a vector for holding the compilation
// output data.
class shaderc_compilation_result_vector : public shaderc_compilation_result {
public:
~shaderc_compilation_result_vector() = default;
void SetOutputData(std::vector<uint32_t>&& data) {
output_data_ = std::move(data);
}
const char* GetBytes() const override {
return reinterpret_cast<const char*>(output_data_.data());
}
private:
// Compilation output data. In normal compilation mode, it contains the
// compiled SPIR-V binary code. In disassembly and preprocessing-only mode, it
// contains a null-terminated string which is the text output. For text
// output, extra bytes with value 0x00 might be appended to complete the last
// uint32_t element.
std::vector<uint32_t> output_data_;
};
// Compilation result class using a spv_binary for holding the compilation
// output data.
class shaderc_compilation_result_spv_binary
: public shaderc_compilation_result {
public:
~shaderc_compilation_result_spv_binary() { spvBinaryDestroy(output_data_); }
void SetOutputData(spv_binary data) { output_data_ = data; }
const char* GetBytes() const override {
return reinterpret_cast<const char*>(output_data_->code);
}
private:
spv_binary output_data_ = nullptr;
};
namespace shaderc_util {
class GlslangInitializer;
}
struct shaderc_compiler {
std::unique_ptr<shaderc_util::GlslangInitializer> initializer;
};
// Converts a shader stage from shaderc_shader_kind into a shaderc_util::Compiler::Stage.
// This is only valid for a specifically named shader stage, e.g. vertex through fragment,
// or compute.
inline shaderc_util::Compiler::Stage shaderc_convert_specific_stage(
shaderc_shader_kind kind) {
switch (kind) {
case shaderc_vertex_shader:
return shaderc_util::Compiler::Stage::Vertex;
case shaderc_fragment_shader:
return shaderc_util::Compiler::Stage::Fragment;
case shaderc_tess_control_shader:
return shaderc_util::Compiler::Stage::TessControl;
case shaderc_tess_evaluation_shader:
return shaderc_util::Compiler::Stage::TessEval;
case shaderc_geometry_shader:
return shaderc_util::Compiler::Stage::Geometry;
case shaderc_compute_shader:
return shaderc_util::Compiler::Stage::Compute;
case shaderc_raygen_shader:
return shaderc_util::Compiler::Stage::RayGenNV;
case shaderc_intersection_shader:
return shaderc_util::Compiler::Stage::IntersectNV;
case shaderc_anyhit_shader:
return shaderc_util::Compiler::Stage::AnyHitNV;
case shaderc_closesthit_shader:
return shaderc_util::Compiler::Stage::ClosestHitNV;
case shaderc_miss_shader:
return shaderc_util::Compiler::Stage::MissNV;
case shaderc_callable_shader:
return shaderc_util::Compiler::Stage::CallableNV;
case shaderc_task_shader:
return shaderc_util::Compiler::Stage::TaskNV;
case shaderc_mesh_shader:
return shaderc_util::Compiler::Stage::MeshNV;
default:
// We don't care about the other kinds.
break;
}
// This should not occur.
assert(false && "Should have specified a specific stage");
return shaderc_util::Compiler::Stage::TessEval;
}
#endif // LIBSHADERC_SRC_SHADERC_PRIVATE_H_

View File

@ -1,50 +0,0 @@
// Copyright 2017 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.
#include <gmock/gmock.h>
#include "shaderc_private.h"
namespace {
TEST(ConvertSpecificStage, Exhaustive) {
EXPECT_EQ(shaderc_util::Compiler::Stage::Vertex,
shaderc_convert_specific_stage(shaderc_vertex_shader));
EXPECT_EQ(shaderc_util::Compiler::Stage::Fragment,
shaderc_convert_specific_stage(shaderc_fragment_shader));
EXPECT_EQ(shaderc_util::Compiler::Stage::TessControl,
shaderc_convert_specific_stage(shaderc_tess_control_shader));
EXPECT_EQ(shaderc_util::Compiler::Stage::TessEval,
shaderc_convert_specific_stage(shaderc_tess_evaluation_shader));
EXPECT_EQ(shaderc_util::Compiler::Stage::Geometry,
shaderc_convert_specific_stage(shaderc_geometry_shader));
EXPECT_EQ(shaderc_util::Compiler::Stage::Compute,
shaderc_convert_specific_stage(shaderc_compute_shader));
EXPECT_EQ(shaderc_util::Compiler::Stage::RayGenNV,
shaderc_convert_specific_stage(shaderc_raygen_shader));
EXPECT_EQ(shaderc_util::Compiler::Stage::AnyHitNV,
shaderc_convert_specific_stage(shaderc_anyhit_shader));
EXPECT_EQ(shaderc_util::Compiler::Stage::ClosestHitNV,
shaderc_convert_specific_stage(shaderc_closesthit_shader));
EXPECT_EQ(shaderc_util::Compiler::Stage::IntersectNV,
shaderc_convert_specific_stage(shaderc_intersection_shader));
EXPECT_EQ(shaderc_util::Compiler::Stage::MissNV,
shaderc_convert_specific_stage(shaderc_miss_shader));
EXPECT_EQ(shaderc_util::Compiler::Stage::CallableNV,
shaderc_convert_specific_stage(shaderc_callable_shader));
EXPECT_EQ(shaderc_util::Compiler::Stage::TaskNV,
shaderc_convert_specific_stage(shaderc_task_shader));
EXPECT_EQ(shaderc_util::Compiler::Stage::MeshNV,
shaderc_convert_specific_stage(shaderc_mesh_shader));
}
} // anonymous namespace

File diff suppressed because it is too large Load Diff

View File

@ -1,32 +0,0 @@
# Copyright 2020 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.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:=shaderc_util
LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti -DENABLE_HLSL=1
LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)/include
LOCAL_SRC_FILES:=src/args.cc \
src/compiler.cc \
src/file_finder.cc \
src/io_shaderc.cc \
src/message.cc \
src/resources.cc \
src/shader_stage.cc \
src/spirv_tools_wrapper.cc \
src/version_profile.cc
LOCAL_STATIC_LIBRARIES:=SPIRV SPIRV-Tools-opt
LOCAL_C_INCLUDES:=$(LOCAL_PATH)/include
include $(BUILD_STATIC_LIBRARY)

View File

@ -1,89 +0,0 @@
# Copyright 2020 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.
project(libshaderc_util)
add_library(shaderc_util STATIC
include/libshaderc_util/counting_includer.h
include/libshaderc_util/file_finder.h
include/libshaderc_util/format.h
include/libshaderc_util/io_shaderc.h
include/libshaderc_util/mutex.h
include/libshaderc_util/message.h
include/libshaderc_util/resources.h
include/libshaderc_util/spirv_tools_wrapper.h
include/libshaderc_util/string_piece.h
include/libshaderc_util/universal_unistd.h
include/libshaderc_util/version_profile.h
src/args.cc
src/compiler.cc
src/file_finder.cc
src/io_shaderc.cc
src/message.cc
src/resources.cc
src/shader_stage.cc
src/spirv_tools_wrapper.cc
src/version_profile.cc
)
shaderc_default_compile_options(shaderc_util)
target_include_directories(shaderc_util
PUBLIC include PRIVATE ${glslang_SOURCE_DIR})
# We use parts of Glslang's HLSL compilation interface, which
# now requires this preprocessor definition.
add_definitions(-DENABLE_HLSL)
find_package(Threads)
target_link_libraries(shaderc_util PRIVATE
glslang OSDependent OGLCompiler HLSL glslang SPIRV
SPIRV-Tools-opt ${CMAKE_THREAD_LIBS_INIT})
shaderc_add_tests(
TEST_PREFIX shaderc_util
LINK_LIBS shaderc_util
TEST_NAMES
counting_includer
string_piece
format
file_finder
io_shaderc
message
mutex
version_profile)
if(${SHADERC_ENABLE_TESTS})
target_include_directories(shaderc_util_counting_includer_test
PRIVATE ${glslang_SOURCE_DIR})
target_include_directories(shaderc_util_version_profile_test
PRIVATE ${glslang_SOURCE_DIR})
endif()
shaderc_add_tests(
TEST_PREFIX shaderc_util
LINK_LIBS shaderc_util
INCLUDE_DIRS
${glslang_SOURCE_DIR}
${spirv-tools_SOURCE_DIR}/include
TEST_NAMES
compiler)
# This target copies content of testdata into the build directory.
add_custom_target(testdata COMMAND
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/testdata/copy-to-build.cmake
COMMENT "Copy testdata into build directory")
if(${SHADERC_ENABLE_TESTS})
add_dependencies(shaderc_util_file_finder_test testdata)
add_dependencies(shaderc_util_io_shaderc_test testdata)
endif()

View File

@ -1,41 +0,0 @@
// Copyright 2019 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.
#ifndef LIBSHADERC_UTIL_INC_ARGS_H
#define LIBSHADERC_UTIL_INC_ARGS_H
#include <cstdint>
#include <string>
#include "libshaderc_util/string_piece.h"
namespace shaderc_util {
// Gets the option argument for the option at *index in argv in a way consistent
// with clang/gcc. On success, returns true and writes the parsed argument into
// *option_argument. Returns false if any errors occur. After calling this
// function, *index will be the index of the last command line argument
// consumed.
bool GetOptionArgument(int argc, char** argv, int* index,
const std::string& option,
string_piece* option_argument);
// Parses the given string as a number of the specified type. Returns true
// if parsing succeeded, and stores the parsed value via |value|.
// (I've worked out the general case for this in
// SPIRV-Tools source/util/parse_number.h. -- dneto)
bool ParseUint32(const std::string& str, uint32_t* value);
} // namespace shaderc_util
#endif // LIBSHADERC_UTIL_INC_ARGS_H

View File

@ -1,621 +0,0 @@
// Copyright 2015 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.
#ifndef LIBSHADERC_UTIL_INC_COMPILER_H
#define LIBSHADERC_UTIL_INC_COMPILER_H
#include <array>
#include <cassert>
#include <functional>
#include <mutex>
#include <ostream>
#include <string>
#include <unordered_map>
#include <utility>
#include "glslang/Public/ShaderLang.h"
#include "counting_includer.h"
#include "file_finder.h"
#include "mutex.h"
#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
// spirv_tools_wrapper.h, so cannot include spirv_tools_wrapper.h here.
enum class PassId;
// Initializes glslang on creation, and destroys it on completion.
// Used to tie gslang process operations to object lifetimes.
// Additionally initialization/finalization of glslang is not thread safe, so
// synchronizes these operations.
class GlslangInitializer {
public:
GlslangInitializer();
~GlslangInitializer();
private:
static unsigned int initialize_count_;
// Using a bare pointer here to avoid any global class construction at the
// beginning of the execution.
static std::mutex* glslang_mutex_;
};
// Maps macro names to their definitions. Stores string_pieces, so the
// underlying strings must outlive it.
using MacroDictionary = std::unordered_map<std::string, std::string>;
// Holds all of the state required to compile source GLSL into SPIR-V.
class Compiler {
public:
// Source language
enum class SourceLanguage {
GLSL, // The default
HLSL,
};
// Target environment.
enum class TargetEnv {
Vulkan, // Default to Vulkan 1.0
OpenGL, // Default to OpenGL 4.5
OpenGLCompat, // Support removed. Generates error if used.
};
// Target environment versions. These numbers match those used by Glslang.
enum class TargetEnvVersion : uint32_t {
Default = 0, // Default for the corresponding target environment
// For Vulkan, use numbering scheme from vulkan.h
Vulkan_1_0 = ((1 << 22)), // Vulkan 1.0
Vulkan_1_1 = ((1 << 22) | (1 << 12)), // Vulkan 1.1
Vulkan_1_2 = ((1 << 22) | (2 << 12)), // Vulkan 1.2
Vulkan_1_3 = ((1 << 22) | (3 << 12)), // Vulkan 1.2
// For OpenGL, use the numbering from #version in shaders.
OpenGL_4_5 = 450,
};
// SPIR-V version.
enum class SpirvVersion : uint32_t {
v1_0 = 0x010000u,
v1_1 = 0x010100u,
v1_2 = 0x010200u,
v1_3 = 0x010300u,
v1_4 = 0x010400u,
v1_5 = 0x010500u,
v1_6 = 0x010600u,
};
enum class OutputType {
SpirvBinary, // A binary module, as defined by the SPIR-V specification.
SpirvAssemblyText, // Assembly syntax defined by the SPIRV-Tools project.
PreprocessedText, // Preprocessed source code.
};
// Supported optimization levels.
enum class OptimizationLevel {
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.
enum class Limit {
#define RESOURCE(NAME, FIELD, CNAME) NAME,
#include "resources.inc"
#undef RESOURCE
};
// Types of uniform variables.
enum class UniformKind {
// Image, and image buffer.
Image = 0,
// Pure sampler.
Sampler = 1,
// Sampled texture in GLSL.
// Shader Resource View, for HLSL. (Read-only image or storage buffer.)
Texture = 2,
// Uniform Buffer Object, or UBO, in GLSL.
// Also a Cbuffer in HLSL.
Buffer = 3,
// Shader Storage Buffer Object, or SSBO
StorageBuffer = 4,
// Uniform Access View, in HLSL. (Writable storage image or storage
// buffer.)
UnorderedAccessView = 5,
};
enum { kNumUniformKinds = int(UniformKind::UnorderedAccessView) + 1 };
// Shader pipeline stage.
// TODO(dneto): Replaces interface uses of EShLanguage with this enum.
enum class Stage {
Vertex,
TessEval,
TessControl,
Geometry,
Fragment,
Compute,
RayGenNV,
IntersectNV,
AnyHitNV,
ClosestHitNV,
MissNV,
CallableNV,
TaskNV,
MeshNV,
StageEnd,
};
enum { kNumStages = int(Stage::StageEnd) };
// Returns a std::array of all the Stage values.
const std::array<Stage, kNumStages>& stages() const {
static std::array<Stage, kNumStages> values{{
Stage::Vertex,
Stage::TessEval,
Stage::TessControl,
Stage::Geometry,
Stage::Fragment,
Stage::Compute,
Stage::RayGenNV,
Stage::IntersectNV,
Stage::AnyHitNV,
Stage::ClosestHitNV,
Stage::MissNV,
Stage::CallableNV,
Stage::TaskNV,
Stage::MeshNV,
}};
return values;
}
// Creates an default compiler instance targeting at Vulkan environment. Uses
// version 110 and no profile specification as the default for GLSL.
Compiler()
// The default version for glsl is 110, or 100 if you are using an es
// profile. But we want to default to a non-es profile.
: default_version_(110),
default_profile_(ENoProfile),
force_version_profile_(false),
warnings_as_errors_(false),
suppress_warnings_(false),
generate_debug_info_(false),
enabled_opt_passes_(),
target_env_(TargetEnv::Vulkan),
target_env_version_(TargetEnvVersion::Default),
target_spirv_version_(SpirvVersion::v1_0),
target_spirv_version_is_forced_(false),
source_language_(SourceLanguage::GLSL),
limits_(kDefaultTBuiltInResource),
auto_bind_uniforms_(false),
auto_combined_image_sampler_(false),
auto_binding_base_(),
auto_map_locations_(false),
hlsl_iomap_(false),
hlsl_offsets_(false),
hlsl_legalization_enabled_(true),
hlsl_functionality1_enabled_(false),
invert_y_enabled_(false),
nan_clamp_(false),
hlsl_explicit_bindings_() {}
// Requests that the compiler place debug information into the object code,
// such as identifier names and line numbers.
void SetGenerateDebugInfo();
// Sets the optimization level to the given level. Only the last one takes
// effect if multiple calls of this method exist.
void SetOptimizationLevel(OptimizationLevel level);
// Enables or disables HLSL legalization passes.
void EnableHlslLegalization(bool hlsl_legalization_enabled);
// Enables or disables extension SPV_GOOGLE_hlsl_functionality1
void EnableHlslFunctionality1(bool enable);
// Enables or disables invert position.Y output in vertex shader.
void EnableInvertY(bool enable);
// Sets whether the compiler generates code for max and min builtins which,
// if given a NaN operand, will return the other operand. Also, the clamp
// builtin will favour the non-NaN operands, as if clamp were implemented
// as a composition of max and min.
void SetNanClamp(bool enable);
// When a warning is encountered it treat it as an error.
void SetWarningsAsErrors();
// Any warning message generated is suppressed before it is output.
void SetSuppressWarnings();
// Adds an implicit macro definition obeyed by subsequent CompileShader()
// calls. The macro and definition should be passed in with their char*
// pointer and their lengths. They can be modified or deleted after this
// function has returned.
void AddMacroDefinition(const char* macro, size_t macro_length,
const char* definition, size_t definition_length);
// Sets the target environment, including version. The version value should
// be 0 or one of the values from TargetEnvVersion. The default 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,
TargetEnvVersion version = TargetEnvVersion::Default);
// Sets the target version of SPIR-V. The module will use this version
// of SPIR-V. Defaults to the highest version of SPIR-V required to be
// supported by the target environment. E.g. default to SPIR-V 1.0 for
// Vulkan 1.0, and SPIR-V 1.3 for Vulkan 1.1.
void SetTargetSpirv(SpirvVersion version);
// Sets the souce language.
void SetSourceLanguage(SourceLanguage lang);
// Forces (without any verification) the default version and profile for
// subsequent CompileShader() calls.
void SetForcedVersionProfile(int version, EProfile profile);
// Sets a resource limit.
void SetLimit(Limit limit, int value);
// Returns the current limit.
int GetLimit(Limit limit) const;
// Set whether the compiler automatically assigns bindings to
// uniform variables that don't have explicit bindings.
void SetAutoBindUniforms(bool auto_bind) { auto_bind_uniforms_ = auto_bind; }
// Sets whether the compiler should automatically remove sampler variables
// and convert image variables to combined image-sampler variables.
void SetAutoCombinedImageSampler(bool auto_combine) {
auto_combined_image_sampler_ = auto_combine;
}
// Sets the lowest binding number used when automatically assigning bindings
// for uniform resources of the given type, for all shader stages. The default
// base is zero.
void SetAutoBindingBase(UniformKind kind, uint32_t base) {
for (auto stage : stages()) {
SetAutoBindingBaseForStage(stage, kind, base);
}
}
// Sets the lowest binding number used when automatically assigning bindings
// for uniform resources of the given type for a specific shader stage. The
// default base is zero.
void SetAutoBindingBaseForStage(Stage stage, UniformKind kind,
uint32_t base) {
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; }
// Use HLSL rules for offsets in "transparent" memory. These allow for
// tighter packing of some combinations of types than standard GLSL packings.
void SetHlslOffsets(bool hlsl_offsets) { hlsl_offsets_ = hlsl_offsets; }
// Sets an explicit set and binding for the given HLSL register.
void SetHlslRegisterSetAndBinding(const std::string& reg,
const std::string& set,
const std::string& binding) {
for (auto stage : stages()) {
SetHlslRegisterSetAndBindingForStage(stage, reg, set, binding);
}
}
// Sets an explicit set and binding for the given HLSL register in the given
// shader stage. For example,
// SetHlslRegisterSetAndBinding(Stage::Fragment, "t1", "4", "5")
// means register "t1" in a fragment shader should map to binding 5 in set 4.
// (Glslang wants this data as strings, not ints or enums.) The string data is
// copied.
void SetHlslRegisterSetAndBindingForStage(Stage stage, const std::string& reg,
const std::string& set,
const std::string& binding) {
hlsl_explicit_bindings_[static_cast<int>(stage)].push_back(reg);
hlsl_explicit_bindings_[static_cast<int>(stage)].push_back(set);
hlsl_explicit_bindings_[static_cast<int>(stage)].push_back(binding);
}
// Compiles the shader source in the input_source_string parameter.
//
// If the forced_shader stage parameter is not EShLangCount then
// the shader is assumed to be of the given stage.
//
// For HLSL compilation, entry_point_name is the null-terminated string for
// the entry point. For GLSL compilation, entry_point_name is ignored, and
// compilation assumes the entry point is named "main".
//
// The stage_callback function will be called if a shader_stage has
// not been forced and the stage can not be determined
// from the shader text. Any #include directives are parsed with the given
// includer.
//
// The initializer parameter must be a valid GlslangInitializer object.
// Acquire will be called on the initializer and the result will be
// destroyed before the function ends.
//
// The output_type parameter determines what kind of output should be
// produced.
//
// Any error messages are written as if the file name were error_tag.
// Any errors are written to the error_stream parameter.
// total_warnings and total_errors are incremented once for every
// warning or error encountered respectively.
//
// Returns a tuple consisting of three fields. 1) a boolean which is true when
// the compilation succeeded, and false otherwise; 2) a vector of 32-bit words
// which contains the compilation output data, either compiled SPIR-V binary
// code, or the text string generated in preprocessing-only or disassembly
// mode; 3) the size of the output data in bytes. When the output is SPIR-V
// binary code, the size is the number of bytes of valid data in the vector.
// If the output is a text string, the size equals the length of that string.
std::tuple<bool, std::vector<uint32_t>, size_t> Compile(
const string_piece& input_source_string, EShLanguage forced_shader_stage,
const std::string& error_tag, const char* entry_point_name,
const std::function<EShLanguage(std::ostream* error_stream,
const string_piece& error_tag)>&
stage_callback,
CountingIncluder& includer, OutputType output_type,
std::ostream* error_stream, size_t* total_warnings, size_t* total_errors) const;
static EShMessages GetDefaultRules() {
return static_cast<EShMessages>(EShMsgSpvRules | EShMsgVulkanRules |
EShMsgCascadingErrors);
}
protected:
// Preprocesses a shader whose filename is filename and content is
// shader_source. If preprocessing is successful, returns true, the
// preprocessed shader, and any warning message as a tuple. Otherwise,
// returns false, an empty string, and error messages as a tuple.
//
// The error_tag parameter is the name to use for outputting errors.
// The shader_source parameter is the input shader's source text.
// The shader_preamble parameter is a context-specific preamble internally
// prepended to shader_text without affecting the validity of its #version
// position.
//
// Any #include directives are processed with the given includer.
//
// If force_version_profile_ is set, the shader's version/profile is forced
// to be default_version_/default_profile_ regardless of the #version
// directive in the source code.
std::tuple<bool, std::string, std::string> PreprocessShader(
const std::string& error_tag, const string_piece& shader_source,
const string_piece& shader_preamble, CountingIncluder& includer) const;
// Cleans up the preamble in a given preprocessed shader.
//
// The error_tag parameter is the name to be given for the main file.
// The pound_extension parameter is the #extension directive we prepended to
// the original shader source code via preamble.
// The num_include_directives parameter is the number of #include directives
// appearing in the original shader source code.
// The is_for_next_line means whether the #line sets the line number for the
// next line.
//
// If no #include directive is used in the shader source code, we can safely
// delete the #extension directive we injected via preamble. Otherwise, we
// need to adjust it if there exists a #version directive in the original
// shader source code.
std::string CleanupPreamble(const string_piece& preprocessed_shader,
const string_piece& error_tag,
const string_piece& pound_extension,
int num_include_directives,
bool is_for_next_line) const;
// Determines version and profile from command line, or the source code.
// Returns the decoded version and profile pair on success. Otherwise,
// returns (0, ENoProfile).
std::pair<int, EProfile> DeduceVersionProfile(
const std::string& preprocessed_shader) const;
// Determines the shader stage from pragmas embedded in the source text if
// possible. In the returned pair, the glslang EShLanguage is the shader
// stage deduced. If no #pragma directives for shader stage exist, it's
// EShLangCount. If errors occur, the second element in the pair is the
// error message. Otherwise, it's an empty string.
std::pair<EShLanguage, std::string> GetShaderStageFromSourceCode(
string_piece filename, const std::string& preprocessed_shader) const;
// Determines version and profile from command line, or the source code.
// Returns the decoded version and profile pair on success. Otherwise,
// returns (0, ENoProfile).
std::pair<int, EProfile> DeduceVersionProfile(
const std::string& preprocessed_shader);
// Gets version and profile specification from the given preprocessedshader.
// Returns the decoded version and profile pair on success. Otherwise,
// returns (0, ENoProfile).
std::pair<int, EProfile> GetVersionProfileFromSourceCode(
const std::string& preprocessed_shader) const;
// Version to use when force_version_profile_ is true.
int default_version_;
// Profile to use when force_version_profile_ is true.
EProfile default_profile_;
// When true, use the default version and profile from eponymous data members.
bool force_version_profile_;
// Macro definitions that must be available to reference in the shader source.
MacroDictionary predefined_macros_;
// When true, treat warnings as errors.
bool warnings_as_errors_;
// Supress warnings when true.
bool suppress_warnings_;
// When true, compilation will generate debug info with the binary SPIR-V
// output.
bool generate_debug_info_;
// Optimization passes to be applied.
std::vector<PassId> enabled_opt_passes_;
// The target environment to compile with. This controls the glslang
// EshMessages bitmask, which determines which dialect of GLSL and which
// SPIR-V codegen semantics are used. This impacts the warning & error
// messages as well as the set of available builtins, as per the
// 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.
TargetEnvVersion target_env_version_;
// The SPIR-V version to be used for the generated module. Defaults to 1.0.
SpirvVersion target_spirv_version_;
// True if the user explicitly set the target SPIR-V version.
bool target_spirv_version_is_forced_;
// The source language. Defaults to GLSL.
SourceLanguage source_language_;
// The resource limits to be used.
TBuiltInResource limits_;
// True if the compiler should automatically bind uniforms that don't
// have explicit bindings.
bool auto_bind_uniforms_;
// True if the compiler should automatically remove sampler variables
// and convert image variables to combined image-sampler variables.
bool auto_combined_image_sampler_;
// The base binding number per uniform type, per stage, used when automatically
// binding uniforms that don't hzve explicit bindings in the shader source.
// 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_;
// True if the compiler should determine block member offsets using HLSL
// packing rules instead of standard GLSL rules.
bool hlsl_offsets_;
// True if the compiler should perform legalization optimization passes if
// source language is HLSL.
bool hlsl_legalization_enabled_;
// True if the compiler should support extension SPV_GOOGLE_hlsl_functionality1.
bool hlsl_functionality1_enabled_;
// True if the compiler should invert position.Y output in vertex shader.
bool invert_y_enabled_;
// True if the compiler generates code for max and min builtins which,
// if given a NaN operand, will return the other operand. Also, the clamp
// builtin will favour the non-NaN operands, as if clamp were implemented
// as a composition of max and min.
bool nan_clamp_;
// 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.
std::vector<std::string> hlsl_explicit_bindings_[kNumStages];
};
// Converts a string to a vector of uint32_t by copying the content of a given
// string to the vector and returns it. Appends '\0' at the end if extra bytes
// are required to complete the last element.
std::vector<uint32_t> ConvertStringToVector(const std::string& str);
// Converts a valid Glslang shader stage value to a Compiler::Stage value.
inline Compiler::Stage ConvertToStage(EShLanguage stage) {
switch (stage) {
case EShLangVertex:
return Compiler::Stage::Vertex;
case EShLangTessControl:
return Compiler::Stage::TessEval;
case EShLangTessEvaluation:
return Compiler::Stage::TessControl;
case EShLangGeometry:
return Compiler::Stage::Geometry;
case EShLangFragment:
return Compiler::Stage::Fragment;
case EShLangCompute:
return Compiler::Stage::Compute;
case EShLangRayGenNV:
return Compiler::Stage::RayGenNV;
case EShLangIntersectNV:
return Compiler::Stage::IntersectNV;
case EShLangAnyHitNV:
return Compiler::Stage::AnyHitNV;
case EShLangClosestHitNV:
return Compiler::Stage::ClosestHitNV;
case EShLangMissNV:
return Compiler::Stage::MissNV;
case EShLangCallableNV:
return Compiler::Stage::CallableNV;
case EShLangTaskNV:
return Compiler::Stage::TaskNV;
case EShLangMeshNV:
return Compiler::Stage::MeshNV;
default:
break;
}
assert(false && "Invalid case");
return Compiler::Stage::Compute;
}
// A GlslangClientInfo captures target client version and desired SPIR-V
// version.
struct GlslangClientInfo {
GlslangClientInfo() {}
GlslangClientInfo(const std::string& e, glslang::EShClient c,
glslang::EShTargetClientVersion cv,
glslang::EShTargetLanguage l,
glslang::EShTargetLanguageVersion lv)
: error(e),
client(c),
client_version(cv),
target_language(l),
target_language_version(lv) {}
std::string error; // Empty if ok, otherwise contains the error message.
glslang::EShClient client = glslang::EShClientNone;
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(
const std::string& error_tag, // Indicates source location, for errors.
shaderc_util::Compiler::TargetEnv env,
shaderc_util::Compiler::TargetEnvVersion env_version,
shaderc_util::Compiler::SpirvVersion spv_version,
bool spv_version_is_forced);
} // namespace shaderc_util
#endif // LIBSHADERC_UTIL_INC_COMPILER_H

View File

@ -1,101 +0,0 @@
// Copyright 2015 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.
#ifndef LIBSHADERC_UTIL_COUNTING_INCLUDER_H
#define LIBSHADERC_UTIL_COUNTING_INCLUDER_H
#include <atomic>
#include "glslang/Public/ShaderLang.h"
#include "libshaderc_util/mutex.h"
namespace shaderc_util {
// An Includer that counts how many #include directives it saw.
// Inclusions are internally serialized, but releasing a previous result
// can occur concurrently.
class CountingIncluder : public glslang::TShader::Includer {
public:
// Done as .store(0) instead of in the initializer list for the following
// reasons:
// Clang > 3.6 will complain about it if it is written as ({0}).
// VS2013 fails if it is written as {0}.
// G++-4.8 does not correctly support std::atomic_init.
CountingIncluder() {
num_include_directives_.store(0);
}
enum class IncludeType {
System, // Only do < > include search
Local, // Only do " " include search
};
// Resolves an include request for a source by name, type, and name of the
// requesting source. For the semantics of the result, see the base class.
// Also increments num_include_directives and returns the results of
// include_delegate(filename). Subclasses should override include_delegate()
// instead of this method. Inclusions are serialized.
glslang::TShader::Includer::IncludeResult* includeSystem(
const char* requested_source, const char* requesting_source,
size_t include_depth) final {
++num_include_directives_;
include_mutex_.lock();
auto result = include_delegate(requested_source, requesting_source,
IncludeType::System, include_depth);
include_mutex_.unlock();
return result;
}
// Like includeSystem, but for "local" include search.
glslang::TShader::Includer::IncludeResult* includeLocal(
const char* requested_source, const char* requesting_source,
size_t include_depth) final {
++num_include_directives_;
include_mutex_.lock();
auto result = include_delegate(requested_source, requesting_source,
IncludeType::Local, include_depth);
include_mutex_.unlock();
return result;
}
// Releases the given IncludeResult.
void releaseInclude(glslang::TShader::Includer::IncludeResult* result) final {
release_delegate(result);
}
int num_include_directives() const { return num_include_directives_.load(); }
private:
// Invoked by this class to provide results to
// glslang::TShader::Includer::include.
virtual glslang::TShader::Includer::IncludeResult* include_delegate(
const char* requested_source, const char* requesting_source,
IncludeType type, size_t include_depth) = 0;
// Release the given IncludeResult.
virtual void release_delegate(
glslang::TShader::Includer::IncludeResult* result) = 0;
// The number of #include directive encountered.
std::atomic_int num_include_directives_;
// A mutex to protect against concurrent inclusions. We can't trust
// our delegates to be safe for concurrent inclusions.
shaderc_util::mutex include_mutex_;
};
}
#endif // LIBSHADERC_UTIL_COUNTING_INCLUDER_H

View File

@ -1,26 +0,0 @@
// 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.
#ifndef LIBSHADERC_UTIL_EXCEPTIONS_H_
#define LIBSHADERC_UTIL_EXCEPTIONS_H_
#if (defined(_MSC_VER) && !defined(_CPPUNWIND)) || !defined(__EXCEPTIONS)
#define TRY_IF_EXCEPTIONS_ENABLED
#define CATCH_IF_EXCEPTIONS_ENABLED(X) if (0)
#else
#define TRY_IF_EXCEPTIONS_ENABLED try
#define CATCH_IF_EXCEPTIONS_ENABLED(X) catch (X)
#endif
#endif // LIBSHADERC_UTIL_EXCEPTIONS_H_

View File

@ -1,57 +0,0 @@
// Copyright 2015 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.
#ifndef LIBSHADERC_UTIL_SRC_FILE_FINDER_H_
#define LIBSHADERC_UTIL_SRC_FILE_FINDER_H_
#include <string>
#include <vector>
namespace shaderc_util {
// Finds files within a search path.
class FileFinder {
public:
// Searches for a read-openable file based on filename, which must be
// non-empty. The search is attempted on filename prefixed by each element of
// search_path() in turn. The first hit is returned, or an empty string if
// there are no hits. Search attempts treat their argument the way
// std::fopen() treats its filename argument, ignoring whether the path is
// absolute or relative.
//
// If a search_path() element is non-empty and not ending in a slash, then a
// slash is inserted between it and filename before its search attempt. An
// empty string in search_path() means that the filename is tried as-is.
std::string FindReadableFilepath(const std::string& filename) const;
// Searches for a read-openable file based on filename, which must be
// non-empty. The search is first attempted as a path relative to
// the requesting_file parameter. If no file is found relative to the
// requesting_file then this acts as FindReadableFilepath does. If
// requesting_file does not contain a '/' or a '\' character then it is
// assumed to be a filename and the request will be relative to the
// current directory.
std::string FindRelativeReadableFilepath(const std::string& requesting_file,
const std::string& filename) const;
// Search path for Find(). Users may add/remove elements as desired.
std::vector<std::string>& search_path() { return search_path_; }
private:
std::vector<std::string> search_path_;
};
} // namespace shaderc_util
#endif // LIBSHADERC_UTIL_SRC_FILE_FINDER_H_

View File

@ -1,36 +0,0 @@
// Copyright 2015 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.
#ifndef LIBSHADERC_UTIL_FORMAT_H_
#define LIBSHADERC_UTIL_FORMAT_H_
#include <sstream>
namespace shaderc_util {
// Returns a string containing <prefix><key><infix><value><postfix> for every
// key-value entry in map.
template <typename Map>
std::string format(const Map& map, const std::string& prefix,
const std::string& infix, const std::string& postfix) {
std::stringstream s;
for (const auto& pair : map) {
s << prefix << pair.first << infix << pair.second << postfix;
}
return s.str();
}
} // namespace shaderc_util
#endif // LIBSHADERC_UTIL_FORMAT_H_

View File

@ -1,69 +0,0 @@
// Copyright 2015 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.
#ifndef LIBSHADERC_UTIL_IO_H_
#define LIBSHADERC_UTIL_IO_H_
#include <string>
#include <vector>
#include "string_piece.h"
namespace shaderc_util {
// Returns true if the given path is an absolute path.
bool IsAbsolutePath(const std::string& path);
// A helper function to return the base file name from either absolute path or
// relative path representation of a file. It keeps the component from the last
// '/' or '\' to the end of the given string. If the component is '..' or '.',
// returns an empty string. If '/' or '\' is the last char of the given string,
// also returns an empty string.
// e.g.: dir_a/dir_b/file_c.vert => file_c.vert
// dir_a/dir_b/.. => <empty string>
// dir_a/dir_b/. => <empty string>
// dir_a/dirb/c/ => <empty string>
// Note that this method doesn't check whether the given path is a valid one or
// not.
std::string GetBaseFileName(const std::string& file_path);
// Reads all of the characters in a given file into input_data. Outputs an
// error message to std::cerr if the file could not be read and returns false if
// there was an error. If the input_file is "-", then input is read from
// std::cin.
bool ReadFile(const std::string& input_file_name,
std::vector<char>* input_data);
// Returns and initializes the file_stream parameter if the output_filename
// refers to a file, or returns &std::cout if the output_filename is "-".
// Returns nullptr and emits an error message to err if the file could
// not be opened for writing. If the output refers to a file, and the open
// failed for writing, file_stream is left with its fail_bit set.
std::ostream* GetOutputStream(const string_piece& output_filename,
std::ofstream* file_stream, std::ostream* err);
// Writes output_data to a file, overwriting if it exists. If output_file_name
// is "-", writes to std::cout.
bool WriteFile(std::ostream* output_stream, const string_piece& output_data);
// Flush the standard output stream and set it to binary mode. Subsequent
// output will not translate newlines to carriage-return newline pairs.
void FlushAndSetBinaryModeOnStdout();
// Flush the standard output stream and set it to text mode. Subsequent
// output will translate newlines to carriage-return newline pairs.
void FlushAndSetTextModeOnStdout();
} // namespace shaderc_util
#endif // LIBSHADERC_UTIL_IO_H_

View File

@ -1,86 +0,0 @@
// Copyright 2015 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.
#ifndef LIBSHADERC_UTIL_SRC_MESSAGE_H_
#define LIBSHADERC_UTIL_SRC_MESSAGE_H_
#include "libshaderc_util/string_piece.h"
namespace shaderc_util {
// TODO(antiagainst): document the differences of the following message types.
enum class MessageType {
Warning,
Error,
ErrorSummary,
WarningSummary,
GlobalWarning,
GlobalError,
Unknown,
Ignored
};
// Given a glslang warning/error message, processes it in the following way and
// returns its message type.
//
// * Places the source name into the source_name parameter, if found.
// Otherwise, clears the source_name parameter.
// * Places the line number into the line_number parameter, if found.
// Otherwise, clears the line_number parameter.
// * Places the rest of the message (the text past warning/error prefix, source
// name, and line number) into the rest parameter.
//
// If warnings_as_errors is set to true, then all warnings will be treated as
// errors.
// If suppress_warnings is set to true, then no warnings will be emitted. This
// takes precedence over warnings_as_errors.
//
// Examples:
// "ERROR: 0:2: Message"
// source_name="0", line_number="2", rest="Message"
// "Warning, Message"
// source_name="", line_number="", rest="Message"
// "ERROR: 2 errors found."
// source_name="2", line_number="", rest="errors found".
//
// Note that filenames can contain colons:
// "ERROR: foo:bar.comp.hlsl:2: 'a' : unknown variable"
MessageType ParseGlslangOutput(const shaderc_util::string_piece& message,
bool warnings_as_errors, bool suppress_warnings,
shaderc_util::string_piece* source_name,
shaderc_util::string_piece* line_number,
shaderc_util::string_piece* rest);
// Filters error_messages received from glslang, and outputs, to error_stream,
// any that are not ignored in a clang like format. If the warnings_as_errors
// boolean is set, then all warnings will be treated as errors. If the
// suppress_warnings boolean is set then any warning messages are ignored. This
// takes precedence over warnings_as_errors. Increments total_warnings and
// total_errors based on the message types.
// Returns true if no new errors were found when parsing the messages.
// "<command line>" will substitute "-1" appearing at the string name/number
// segment.
bool PrintFilteredErrors(const shaderc_util::string_piece& file_name,
std::ostream* error_stream, bool warnings_as_errors,
bool suppress_warnings, const char* error_list,
size_t* total_warnings, size_t* total_errors);
// Outputs, to error_stream, the number of warnings and errors if there are
// any.
void OutputMessages(std::ostream* error_stream, size_t total_warnings,
size_t total_errors);
} // namespace glslc
#endif // LIBSHADERC_UTIL_SRC_MESSAGE_H_

View File

@ -1,107 +0,0 @@
// Copyright 2015 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.
#ifndef LIBSHADERC_UTIL_INC_MUTEX_H
#define LIBSHADERC_UTIL_INC_MUTEX_H
// shaderc_util::mutex will be defined and specialized
// depending on the platform that is being compiled.
// It is more or less conformant to the C++11 specification of std::mutex.
// However it does not implement try_lock.
#ifdef _WIN32
// windows.h #defines min and max if we don't define this.
// this means things like std::min and std::max break
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
namespace shaderc_util {
// As the name suggests, this mutex class is for running on windows.
// It conforms to the c++11 mutex implementation, and should be a
// drop in replacement.
class windows_mutex {
public:
using native_handle_type = HANDLE;
windows_mutex() { mutex_ = CreateMutex(nullptr, false, nullptr); }
~windows_mutex() {
if (mutex_ != INVALID_HANDLE_VALUE) {
CloseHandle(mutex_);
}
}
windows_mutex(const windows_mutex&) = delete;
windows_mutex& operator=(const windows_mutex&) = delete;
// Locks this mutex, waiting until the mutex is unlocked if it is not already.
// It is not valid to lock a mutex that has already been locked.
void lock() { WaitForSingleObject(mutex_, INFINITE); }
// Unlocks this mutex. It is invalid to unlock a mutex that this thread
// has not already locked.
void unlock() { ReleaseMutex(mutex_); }
// Returns the native handle for this mutex. In this case a HANDLE object.
native_handle_type native_handle() { return mutex_; }
private:
HANDLE mutex_;
};
using mutex = windows_mutex;
}
#else
#include <pthread.h>
#include <memory>
namespace shaderc_util {
// As the name suggests, this mutex class is for running with pthreads.
// It conforms to the c++11 mutex implementation, and should be a
// drop in replacement.
class posix_mutex {
public:
using native_handle_type = pthread_mutex_t*;
posix_mutex() { pthread_mutex_init(&mutex_, nullptr); }
~posix_mutex() { pthread_mutex_destroy(&mutex_); }
posix_mutex(const posix_mutex&) = delete;
posix_mutex& operator=(const posix_mutex&) = delete;
// Locks this mutex, waiting until the mutex is unlocked if it is not already.
// It is not valid to lock a mutex that has already been locked.
void lock() { pthread_mutex_lock(&mutex_); }
// Unlocks this mutex. It is invalid to unlock a mutex that this thread
// has not already locked.
void unlock() { pthread_mutex_unlock(&mutex_); }
// Returns the native handle for this mutex. In this case a pthread_mutex_t*.
native_handle_type native_handle() { return &mutex_; }
private:
pthread_mutex_t mutex_;
};
using mutex = posix_mutex;
}
#endif
#endif // LIBSHADERC_UTIL_INC_MUTEX_H

View File

@ -1,30 +0,0 @@
// Copyright 2015 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.
#ifndef LIBSHADERC_UTIL_RESOURCES_H_
#define LIBSHADERC_UTIL_RESOURCES_H_
// We want TBuiltInResource
#include "glslang/Include/ResourceLimits.h"
namespace shaderc_util {
using TBuiltInResource = ::TBuiltInResource;
// A set of suitable defaults.
extern const TBuiltInResource kDefaultTBuiltInResource;
} // namespace shaderc_util
#endif // LIBSHADERC_UTIL_RESOURCES_H_

View File

@ -1,107 +0,0 @@
// Copyright 2016 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.
// These are the resource limits in a glslang::TBuiltInResource.
// The first field is the string name to be used in a configuration setting.
// The second field is the fieldname in TBuiltInResource.
// The third field is the enum name fragment for shaderc_limit.
//
// TODO(dneto): Consider using a single list of names, but use a Python script
// to generate *this* file. The original data file would have the first field,
// then generate the second field by lowering the case of the first letter, and
// generate the third field by taking the second field, and converting a
// lower-to-upper case transition into an underscore with lower-case.
RESOURCE(MaxLights,maxLights,max_lights)
RESOURCE(MaxClipPlanes,maxClipPlanes,max_clip_planes)
RESOURCE(MaxTextureUnits,maxTextureUnits,max_texture_units)
RESOURCE(MaxTextureCoords,maxTextureCoords,max_texture_coords)
RESOURCE(MaxVertexAttribs,maxVertexAttribs,max_vertex_attribs)
RESOURCE(MaxVertexUniformComponents,maxVertexUniformComponents,max_vertex_uniform_components)
RESOURCE(MaxVaryingFloats,maxVaryingFloats,max_varying_floats)
RESOURCE(MaxVertexTextureImageUnits,maxVertexTextureImageUnits,max_vertex_texture_image_units)
RESOURCE(MaxCombinedTextureImageUnits,maxCombinedTextureImageUnits,max_combined_texture_image_units)
RESOURCE(MaxTextureImageUnits,maxTextureImageUnits,max_texture_image_units)
RESOURCE(MaxFragmentUniformComponents,maxFragmentUniformComponents,max_fragment_uniform_components)
RESOURCE(MaxDrawBuffers,maxDrawBuffers,max_draw_buffers)
RESOURCE(MaxVertexUniformVectors,maxVertexUniformVectors,max_vertex_uniform_vectors)
RESOURCE(MaxVaryingVectors,maxVaryingVectors,max_varying_vectors)
RESOURCE(MaxFragmentUniformVectors,maxFragmentUniformVectors,max_fragment_uniform_vectors)
RESOURCE(MaxVertexOutputVectors,maxVertexOutputVectors,max_vertex_output_vectors)
RESOURCE(MaxFragmentInputVectors,maxFragmentInputVectors,max_fragment_input_vectors)
RESOURCE(MinProgramTexelOffset,minProgramTexelOffset,min_program_texel_offset)
RESOURCE(MaxProgramTexelOffset,maxProgramTexelOffset,max_program_texel_offset)
RESOURCE(MaxClipDistances,maxClipDistances,max_clip_distances)
RESOURCE(MaxComputeWorkGroupCountX,maxComputeWorkGroupCountX,max_compute_work_group_count_x)
RESOURCE(MaxComputeWorkGroupCountY,maxComputeWorkGroupCountY,max_compute_work_group_count_y)
RESOURCE(MaxComputeWorkGroupCountZ,maxComputeWorkGroupCountZ,max_compute_work_group_count_z)
RESOURCE(MaxComputeWorkGroupSizeX,maxComputeWorkGroupSizeX,max_compute_work_group_size_x)
RESOURCE(MaxComputeWorkGroupSizeY,maxComputeWorkGroupSizeY,max_compute_work_group_size_y)
RESOURCE(MaxComputeWorkGroupSizeZ,maxComputeWorkGroupSizeZ,max_compute_work_group_size_z)
RESOURCE(MaxComputeUniformComponents,maxComputeUniformComponents,max_compute_uniform_components)
RESOURCE(MaxComputeTextureImageUnits,maxComputeTextureImageUnits,max_compute_texture_image_units)
RESOURCE(MaxComputeImageUniforms,maxComputeImageUniforms,max_compute_image_uniforms)
RESOURCE(MaxComputeAtomicCounters,maxComputeAtomicCounters,max_compute_atomic_counters)
RESOURCE(MaxComputeAtomicCounterBuffers,maxComputeAtomicCounterBuffers,max_compute_atomic_counter_buffers)
RESOURCE(MaxVaryingComponents,maxVaryingComponents,max_varying_components)
RESOURCE(MaxVertexOutputComponents,maxVertexOutputComponents,max_vertex_output_components)
RESOURCE(MaxGeometryInputComponents,maxGeometryInputComponents,max_geometry_input_components)
RESOURCE(MaxGeometryOutputComponents,maxGeometryOutputComponents,max_geometry_output_components)
RESOURCE(MaxFragmentInputComponents,maxFragmentInputComponents,max_fragment_input_components)
RESOURCE(MaxImageUnits,maxImageUnits,max_image_units)
RESOURCE(MaxCombinedImageUnitsAndFragmentOutputs,maxCombinedImageUnitsAndFragmentOutputs,max_combined_image_units_and_fragment_outputs)
RESOURCE(MaxCombinedShaderOutputResources,maxCombinedShaderOutputResources,max_combined_shader_output_resources)
RESOURCE(MaxImageSamples,maxImageSamples,max_image_samples)
RESOURCE(MaxVertexImageUniforms,maxVertexImageUniforms,max_vertex_image_uniforms)
RESOURCE(MaxTessControlImageUniforms,maxTessControlImageUniforms,max_tess_control_image_uniforms)
RESOURCE(MaxTessEvaluationImageUniforms,maxTessEvaluationImageUniforms,max_tess_evaluation_image_uniforms)
RESOURCE(MaxGeometryImageUniforms,maxGeometryImageUniforms,max_geometry_image_uniforms)
RESOURCE(MaxFragmentImageUniforms,maxFragmentImageUniforms,max_fragment_image_uniforms)
RESOURCE(MaxCombinedImageUniforms,maxCombinedImageUniforms,max_combined_image_uniforms)
RESOURCE(MaxGeometryTextureImageUnits,maxGeometryTextureImageUnits,max_geometry_texture_image_units)
RESOURCE(MaxGeometryOutputVertices,maxGeometryOutputVertices,max_geometry_output_vertices)
RESOURCE(MaxGeometryTotalOutputComponents,maxGeometryTotalOutputComponents,max_geometry_total_output_components)
RESOURCE(MaxGeometryUniformComponents,maxGeometryUniformComponents,max_geometry_uniform_components)
RESOURCE(MaxGeometryVaryingComponents,maxGeometryVaryingComponents,max_geometry_varying_components)
RESOURCE(MaxTessControlInputComponents,maxTessControlInputComponents,max_tess_control_input_components)
RESOURCE(MaxTessControlOutputComponents,maxTessControlOutputComponents,max_tess_control_output_components)
RESOURCE(MaxTessControlTextureImageUnits,maxTessControlTextureImageUnits,max_tess_control_texture_image_units)
RESOURCE(MaxTessControlUniformComponents,maxTessControlUniformComponents,max_tess_control_uniform_components)
RESOURCE(MaxTessControlTotalOutputComponents,maxTessControlTotalOutputComponents,max_tess_control_total_output_components)
RESOURCE(MaxTessEvaluationInputComponents,maxTessEvaluationInputComponents,max_tess_evaluation_input_components)
RESOURCE(MaxTessEvaluationOutputComponents,maxTessEvaluationOutputComponents,max_tess_evaluation_output_components)
RESOURCE(MaxTessEvaluationTextureImageUnits,maxTessEvaluationTextureImageUnits,max_tess_evaluation_texture_image_units)
RESOURCE(MaxTessEvaluationUniformComponents,maxTessEvaluationUniformComponents,max_tess_evaluation_uniform_components)
RESOURCE(MaxTessPatchComponents,maxTessPatchComponents,max_tess_patch_components)
RESOURCE(MaxPatchVertices,maxPatchVertices,max_patch_vertices)
RESOURCE(MaxTessGenLevel,maxTessGenLevel,max_tess_gen_level)
RESOURCE(MaxViewports,maxViewports,max_viewports)
RESOURCE(MaxVertexAtomicCounters,maxVertexAtomicCounters,max_vertex_atomic_counters)
RESOURCE(MaxTessControlAtomicCounters,maxTessControlAtomicCounters,max_tess_control_atomic_counters)
RESOURCE(MaxTessEvaluationAtomicCounters,maxTessEvaluationAtomicCounters,max_tess_evaluation_atomic_counters)
RESOURCE(MaxGeometryAtomicCounters,maxGeometryAtomicCounters,max_geometry_atomic_counters)
RESOURCE(MaxFragmentAtomicCounters,maxFragmentAtomicCounters,max_fragment_atomic_counters)
RESOURCE(MaxCombinedAtomicCounters,maxCombinedAtomicCounters,max_combined_atomic_counters)
RESOURCE(MaxAtomicCounterBindings,maxAtomicCounterBindings,max_atomic_counter_bindings)
RESOURCE(MaxVertexAtomicCounterBuffers,maxVertexAtomicCounterBuffers,max_vertex_atomic_counter_buffers)
RESOURCE(MaxTessControlAtomicCounterBuffers,maxTessControlAtomicCounterBuffers,max_tess_control_atomic_counter_buffers)
RESOURCE(MaxTessEvaluationAtomicCounterBuffers,maxTessEvaluationAtomicCounterBuffers,max_tess_evaluation_atomic_counter_buffers)
RESOURCE(MaxGeometryAtomicCounterBuffers,maxGeometryAtomicCounterBuffers,max_geometry_atomic_counter_buffers)
RESOURCE(MaxFragmentAtomicCounterBuffers,maxFragmentAtomicCounterBuffers,max_fragment_atomic_counter_buffers)
RESOURCE(MaxCombinedAtomicCounterBuffers,maxCombinedAtomicCounterBuffers,max_combined_atomic_counter_buffers)
RESOURCE(MaxAtomicCounterBufferSize,maxAtomicCounterBufferSize,max_atomic_counter_buffer_size)
RESOURCE(MaxTransformFeedbackBuffers,maxTransformFeedbackBuffers,max_transform_feedback_buffers)
RESOURCE(MaxTransformFeedbackInterleavedComponents,maxTransformFeedbackInterleavedComponents,max_transform_feedback_interleaved_components)
RESOURCE(MaxCullDistances,maxCullDistances,max_cull_distances)
RESOURCE(MaxCombinedClipAndCullDistances,maxCombinedClipAndCullDistances,max_combined_clip_and_cull_distances)
RESOURCE(MaxSamples,maxSamples,max_samples)

View File

@ -1,36 +0,0 @@
// Copyright 2015 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.
#ifndef LIBSHADERC_UTIL_SHADER_STAGE_H_
#define LIBSHADERC_UTIL_SHADER_STAGE_H_
#include <ostream>
#include <string>
#include <utility>
#include <vector>
#include "glslang/Public/ShaderLang.h"
#include "libshaderc_util/string_piece.h"
namespace shaderc_util {
// Given a string representing a stage, returns the glslang EShLanguage for it.
// If the stage string is not recognized, returns EShLangCount.
EShLanguage MapStageNameToLanguage(
const shaderc_util::string_piece& stage_name);
} // namespace shaderc_util
#endif // LIBSHADERC_UTIL_SHADER_STAGE_H_

View File

@ -1,67 +0,0 @@
// Copyright 2016 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.
#ifndef LIBSHADERC_UTIL_INC_SPIRV_TOOLS_WRAPPER_H
#define LIBSHADERC_UTIL_INC_SPIRV_TOOLS_WRAPPER_H
#include <string>
#include <vector>
#include "spirv-tools/libspirv.hpp"
#include "libshaderc_util/compiler.h"
#include "libshaderc_util/string_piece.h"
namespace shaderc_util {
// Assembles the given assembly. On success, returns true, writes the assembled
// binary to *binary, and clears *errors. Otherwise, writes the error message
// into *errors.
bool SpirvToolsAssemble(Compiler::TargetEnv env,
Compiler::TargetEnvVersion version,
const string_piece assembly, spv_binary* binary,
std::string* errors);
// Disassembles the given binary. Returns true and writes the disassembled text
// to *text_or_error if successful. Otherwise, writes the error message to
// *text_or_error.
bool SpirvToolsDisassemble(Compiler::TargetEnv env,
Compiler::TargetEnvVersion version,
const std::vector<uint32_t>& binary,
std::string* text_or_error);
// 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,
kCompactIds,
};
// Optimizes the given binary. Passes are registered in the exact order as shown
// in enabled_passes, without de-duplication. Returns true and writes the
// optimized binary back to *binary if successful. Otherwise, writes errors to
// *errors and the content of binary may be in an invalid state.
bool SpirvToolsOptimize(Compiler::TargetEnv env,
Compiler::TargetEnvVersion version,
const std::vector<PassId>& enabled_passes,
std::vector<uint32_t>* binary, std::string* errors);
} // namespace shaderc_util
#endif // LIBSHADERC_UTIL_INC_SPIRV_TOOLS_WRAPPER_H

View File

@ -1,357 +0,0 @@
// Copyright 2015 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.
#ifndef LIBSHADERC_UTIL_STRING_PIECE_H_
#define LIBSHADERC_UTIL_STRING_PIECE_H_
#include <cassert>
#include <cstring>
#include <ostream>
#include <vector>
namespace shaderc_util {
// Provides a read-only view into a string (cstring or std::string).
// This must be created after the string in question, and cannot
// outlive the memory of the string in question.
// Any operations that may modify the location or size of the
// original data render the associated string_piece invalid.
class string_piece {
public:
typedef const char* iterator;
static const size_t npos = -1;
string_piece() {}
string_piece(const char* begin, const char* end) : begin_(begin), end_(end) {
assert((begin == nullptr) == (end == nullptr) &&
"either both begin and end must be nullptr or neither must be");
}
string_piece(const char* string) : begin_(string), end_(string) {
if (string) {
end_ += strlen(string);
}
}
string_piece(const std::string& str) {
if (!str.empty()) {
begin_ = &(str.front());
end_ = &(str.back()) + 1;
}
}
string_piece(const string_piece& other) {
begin_ = other.begin_;
end_ = other.end_;
}
string_piece& operator=(const string_piece& other) = default;
// Clears the string_piece removing any reference to the original string.
void clear() {
begin_ = nullptr;
end_ = nullptr;
}
// Returns a pointer to the data contained in the underlying string.
// If there is no underlying string, returns a nullptr.
const char* data() const { return begin_; }
// Returns an std::string copy of the internal data.
std::string str() const { return std::string(begin_, end_); }
// Returns a string_piece that points to a substring in the original string.
string_piece substr(size_t pos, size_t len = npos) const {
assert(len == npos || pos + len <= size());
return string_piece(begin_ + pos, len == npos ? end_ : begin_ + pos + len);
}
// Takes any function object predicate that takes a char and returns a
// boolean.
// Returns the index of the first element that does not return true for the
// predicate.
// Returns string_piece::npos if all elements match.
template <typename T>
size_t find_first_not_matching(T callee) {
for (auto it = begin_; it != end_; ++it) {
if (!callee(*it)) {
return it - begin_;
}
}
return npos;
}
// Returns the index of the first character that does not match any character
// in the input string_piece.
// The search only includes characters at or after position pos.
// Returns string_piece::npos if all match.
size_t find_first_not_of(const string_piece& to_search,
size_t pos = 0) const {
if (pos >= size()) {
return npos;
}
for (auto it = begin_ + pos; it != end_; ++it) {
if (to_search.find_first_of(*it) == npos) {
return it - begin_;
}
}
return npos;
}
// Returns find_first_not_of(str, pos) where str is a string_piece
// containing only to_search.
size_t find_first_not_of(char to_search, size_t pos = 0) const {
return find_first_not_of(string_piece(&to_search, &to_search + 1), pos);
}
// Returns the index of the first character that matches any character in the
// input string_piece.
// The search only includes characters at or after position pos.
// Returns string_piece::npos if there is no match.
size_t find_first_of(const string_piece& to_search, size_t pos = 0) const {
if (pos >= size()) {
return npos;
}
for (auto it = begin_ + pos; it != end_; ++it) {
for (char c : to_search) {
if (c == *it) {
return it - begin_;
}
}
}
return npos;
}
// Returns find_first_of(str, pos) where str is a string_piece
// containing only to_search.
size_t find_first_of(char to_search, size_t pos = 0) const {
return find_first_of(string_piece(&to_search, &to_search + 1), pos);
}
// Returns the index of the last character that matches any character in the
// input string_piece.
// The search only includes characters at or before position pos.
// Returns string_piece::npos if there is no match.
size_t find_last_of(const string_piece& to_search, size_t pos = npos) const {
if (empty()) return npos;
if (pos >= size()) {
pos = size();
}
auto it = begin_ + pos + 1;
do {
--it;
if (to_search.find_first_of(*it) != npos) {
return it - begin_;
}
} while (it != begin_);
return npos;
}
// Returns find_last_of(str, pos) where str is a string_piece
// containing only to_search.
size_t find_last_of(char to_search, size_t pos = npos) const {
return find_last_of(string_piece(&to_search, &to_search + 1), pos);
}
// Returns the index of the last character that does not match any character
// in the input string_piece.
// The search only includes characters at or before position pos.
// Returns string_piece::npos if there is no match.
size_t find_last_not_of(const string_piece& to_search,
size_t pos = npos) const {
if (empty()) return npos;
if (pos >= size()) {
pos = size();
}
auto it = begin_ + pos + 1;
do {
--it;
if (to_search.find_first_of(*it) == npos) {
return it - begin_;
}
} while (it != begin_);
return npos;
}
// Returns find_last_not_of(str, pos) where str is a string_piece
// containing only to_search.
size_t find_last_not_of(char to_search, size_t pos = 0) const {
return find_last_not_of(string_piece(&to_search, &to_search + 1), pos);
}
// Continuously removes characters appearing in chars_to_strip from the left.
string_piece lstrip(const string_piece& chars_to_strip) const {
iterator begin = begin_;
for (; begin < end_; ++begin)
if (chars_to_strip.find_first_of(*begin) == npos) break;
if (begin >= end_) return string_piece();
return string_piece(begin, end_);
}
// Continuously removes characters appearing in chars_to_strip from the right.
string_piece rstrip(const string_piece& chars_to_strip) const {
iterator end = end_;
for (; begin_ < end; --end)
if (chars_to_strip.find_first_of(*(end - 1)) == npos) break;
if (begin_ >= end) return string_piece();
return string_piece(begin_, end);
}
// Continuously removes characters appearing in chars_to_strip from both
// sides.
string_piece strip(const string_piece& chars_to_strip) const {
return lstrip(chars_to_strip).rstrip(chars_to_strip);
}
string_piece strip_whitespace() const { return strip(" \t\n\r\f\v"); }
// Returns the character at index i in the string_piece.
const char& operator[](size_t i) const { return *(begin_ + i); }
// Standard comparison operator.
bool operator==(const string_piece& other) const {
// Either end_ and _begin_ are nullptr or neither of them are.
assert(((end_ == nullptr) == (begin_ == nullptr)));
assert(((other.end_ == nullptr) == (other.begin_ == nullptr)));
if (size() != other.size()) {
return false;
}
return (memcmp(begin_, other.begin_, end_ - begin_) == 0);
}
bool operator!=(const string_piece& other) const {
return !operator==(other);
}
// Returns an iterator to the first element.
iterator begin() const { return begin_; }
// Returns an iterator to one past the last element.
iterator end() const { return end_; }
const char& front() const {
assert(!empty());
return *begin_;
}
const char& back() const {
assert(!empty());
return *(end_ - 1);
}
// Returns true is this string_piece starts with the same
// characters as other.
bool starts_with(const string_piece& other) const {
const char* iter = begin_;
const char* other_iter = other.begin();
while (iter != end_ && other_iter != other.end()) {
if (*iter++ != *other_iter++) {
return false;
}
}
return other_iter == other.end();
}
// Returns the index of the start of the first substring that matches
// the input string_piece.
// The search only includes substrings starting at or after position pos.
// Returns npos if the string cannot be found.
size_t find(const string_piece& substr, size_t pos = 0) const {
if (empty()) return npos;
if (pos >= size()) return npos;
if (substr.empty()) return 0;
for (auto it = begin_ + pos;
end() - it >= static_cast<decltype(end() - it)>(substr.size()); ++it) {
if (string_piece(it, end()).starts_with(substr)) return it - begin_;
}
return npos;
}
// Returns the index of the start of the first character that matches
// the input character.
// The search only includes substrings starting at or after position pos.
// Returns npos if the character cannot be found.
size_t find(char character, size_t pos = 0) const {
return find_first_of(character, pos);
}
// Returns true if the string_piece is empty.
bool empty() const { return begin_ == end_; }
// Returns the number of characters in the string_piece.
size_t size() const { return end_ - begin_; }
// Returns a vector of string_pieces representing delimiter delimited
// fields found. If the keep_delimiter parameter is true, then each
// delimiter character is kept with the string to its left.
std::vector<string_piece> get_fields(char delimiter,
bool keep_delimiter = false) const {
std::vector<string_piece> fields;
size_t first = 0;
size_t field_break = find_first_of(delimiter);
while (field_break != npos) {
fields.push_back(substr(first, field_break - first + keep_delimiter));
first = field_break + 1;
field_break = find_first_of(delimiter, first);
}
if (size() - first > 0) {
fields.push_back(substr(first, size() - first));
}
return fields;
}
friend std::ostream& operator<<(std::ostream& os, const string_piece& piece);
private:
// It is expected that begin_ and end_ will both be null or
// they will both point to valid pieces of memory, but it is invalid
// to have one of them being nullptr and the other not.
string_piece::iterator begin_ = nullptr;
string_piece::iterator end_ = nullptr;
};
inline std::ostream& operator<<(std::ostream& os, const string_piece& piece) {
// Either end_ and _begin_ are nullptr or neither of them are.
assert(((piece.end_ == nullptr) == (piece.begin_ == nullptr)));
if (piece.end_ != piece.begin_) {
os.write(piece.begin_, piece.end_ - piece.begin_);
}
return os;
}
inline bool operator==(const char* first, const string_piece second) {
return second == first;
}
inline bool operator!=(const char* first, const string_piece second) {
return !operator==(first, second);
}
}
namespace std {
template <>
struct hash<shaderc_util::string_piece> {
size_t operator()(const shaderc_util::string_piece& piece) const {
// djb2 algorithm.
size_t hash = 5381;
for (char c : piece) {
hash = ((hash << 5) + hash) + c;
}
return hash;
}
};
}
#endif // LIBSHADERC_UTIL_STRING_PIECE_H_

View File

@ -1,32 +0,0 @@
// Copyright 2015 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.
#ifndef LIBSHADERC_UTIL_UNIVERSAL_UNISTD_H_
#define LIBSHADERC_UTIL_UNIVERSAL_UNISTD_H_
#ifndef _MSC_VER
#include <unistd.h>
#else
// Minimal set of <unistd> needed to compile on windows.
#include <io.h>
#define access _access
// https://msdn.microsoft.com/en-us/library/1w06ktdy.aspx
// Defines these constants.
#define R_OK 4
#define W_OK 2
#endif //_MSC_VER
#endif // LIBSHADERC_UTIL_UNIVERSAL_UNISTD_H_

View File

@ -1,61 +0,0 @@
// Copyright 2015 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.
#ifndef LIBSHADERC_UTIL_INC_VERSION_PROFILE_H_
#define LIBSHADERC_UTIL_INC_VERSION_PROFILE_H_
#include <string>
#include "glslang/MachineIndependent/Versions.h"
namespace shaderc_util {
// Returns true if the given version is an accepted GLSL (ES) version.
inline bool IsKnownVersion(int version) {
switch (version) {
case 100:
case 110:
case 120:
case 130:
case 140:
case 150:
case 300:
case 310:
case 320:
case 330:
case 400:
case 410:
case 420:
case 430:
case 440:
case 450:
case 460:
return true;
default:
break;
}
return false;
}
// Given a string version_profile containing both version and profile, decodes
// it and puts the decoded version in version, decoded profile in profile.
// Returns true if decoding is successful and version and profile are accepted.
// This does not validate the version number against the profile. For example,
// "460es" doesn't make sense (yet), but is still accepted.
bool ParseVersionProfile(const std::string& version_profile, int* version,
EProfile* profile);
} // namespace shaderc_util
#endif // LIBSHADERC_UTIL_INC_VERSION_PROFILE_H_

View File

@ -1,62 +0,0 @@
// Copyright 2019 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.
#include "libshaderc_util/args.h"
#include <iomanip>
#include <sstream>
namespace shaderc_util {
bool GetOptionArgument(int argc, char** argv, int* index,
const std::string& option,
string_piece* option_argument) {
const string_piece arg = argv[*index];
assert(arg.starts_with(option));
if (arg.size() != option.size()) {
*option_argument = arg.substr(option.size());
return true;
}
if (option.back() == '=') {
*option_argument = "";
return true;
}
if (++(*index) >= argc) return false;
*option_argument = argv[*index];
return true;
}
bool ParseUint32(const std::string& str, uint32_t* value) {
std::istringstream iss(str);
iss >> std::setbase(0);
iss >> *value;
// We should have read something.
bool ok = !str.empty() && !iss.bad();
// It should have been all the text.
ok = ok && iss.eof();
// It should have been in range.
ok = ok && !iss.fail();
// Work around a bugs in various C++ standard libraries.
// Count any negative number as an error, including "-0".
ok = ok && (str[0] != '-');
return ok;
}
} // namespace shaderc_util

View File

@ -1,785 +0,0 @@
// Copyright 2015 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.
#include "libshaderc_util/compiler.h"
#include <cstdint>
#include <iomanip>
#include <sstream>
#include <thread>
#include <tuple>
#include "SPIRV/GlslangToSpv.h"
#include "libshaderc_util/format.h"
#include "libshaderc_util/io_shaderc.h"
#include "libshaderc_util/message.h"
#include "libshaderc_util/resources.h"
#include "libshaderc_util/shader_stage.h"
#include "libshaderc_util/spirv_tools_wrapper.h"
#include "libshaderc_util/string_piece.h"
#include "libshaderc_util/version_profile.h"
namespace {
using shaderc_util::string_piece;
// For use with glslang parsing calls.
const bool kNotForwardCompatible = false;
// Returns true if #line directive sets the line number for the next line in the
// given version and profile.
inline bool LineDirectiveIsForNextLine(int version, EProfile profile) {
return profile == EEsProfile || version >= 330;
}
// Returns a #line directive whose arguments are line and filename.
inline std::string GetLineDirective(int line, const string_piece& filename) {
return "#line " + std::to_string(line) + " \"" + filename.str() + "\"\n";
}
// Given a canonicalized #line directive (starting exactly with "#line", using
// single spaces to separate different components, and having an optional
// newline at the end), returns the line number and string name/number. If no
// string name/number is provided, the second element in the returned pair is an
// empty string_piece. Behavior is undefined if the directive parameter is not a
// canonicalized #line directive.
std::pair<int, string_piece> DecodeLineDirective(string_piece directive) {
const string_piece kLineDirective = "#line ";
assert(directive.starts_with(kLineDirective));
directive = directive.substr(kLineDirective.size());
const int line = std::atoi(directive.data());
const size_t space_loc = directive.find_first_of(' ');
if (space_loc == string_piece::npos) return std::make_pair(line, "");
directive = directive.substr(space_loc);
directive = directive.strip("\" \n");
return std::make_pair(line, directive);
}
// Returns the Glslang message rules for the given target environment,
// source language, and whether we want HLSL offset rules. We assume
// only valid combinations are used.
EShMessages GetMessageRules(shaderc_util::Compiler::TargetEnv env,
shaderc_util::Compiler::SourceLanguage lang,
bool hlsl_offsets, bool debug_info) {
using shaderc_util::Compiler;
EShMessages result = EShMsgCascadingErrors;
if (lang == Compiler::SourceLanguage::HLSL) {
result = static_cast<EShMessages>(result | EShMsgReadHlsl);
}
switch (env) {
case Compiler::TargetEnv::OpenGLCompat:
// The compiler will have already errored out before now.
// But we need to handle this enum.
break;
case Compiler::TargetEnv::OpenGL:
result = static_cast<EShMessages>(result | EShMsgSpvRules);
break;
case Compiler::TargetEnv::Vulkan:
result =
static_cast<EShMessages>(result | EShMsgSpvRules | EShMsgVulkanRules);
break;
}
if (hlsl_offsets) {
result = static_cast<EShMessages>(result | EShMsgHlslOffsets);
}
if (debug_info) {
result = static_cast<EShMessages>(result | EShMsgDebugInfo);
}
return result;
}
} // anonymous namespace
namespace shaderc_util {
unsigned int GlslangInitializer::initialize_count_ = 0;
std::mutex* GlslangInitializer::glslang_mutex_ = nullptr;
GlslangInitializer::GlslangInitializer() {
static std::mutex first_call_mutex;
// If this is the first call, glslang_mutex_ needs to be created, but in
// thread safe manner.
{
const std::lock_guard<std::mutex> first_call_lock(first_call_mutex);
if (glslang_mutex_ == nullptr) {
glslang_mutex_ = new std::mutex();
}
}
const std::lock_guard<std::mutex> glslang_lock(*glslang_mutex_);
if (initialize_count_ == 0) {
glslang::InitializeProcess();
}
initialize_count_++;
}
GlslangInitializer::~GlslangInitializer() {
const std::lock_guard<std::mutex> glslang_lock(*glslang_mutex_);
initialize_count_--;
if (initialize_count_ == 0) {
glslang::FinalizeProcess();
// There is no delete for glslang_mutex_ here, because we cannot guarantee
// there isn't a caller waiting for glslang_mutex_ in GlslangInitializer().
//
// This means that this class does leak one std::mutex worth of memory after
// the final instance is destroyed, but this allows us to defer allocating
// and constructing until we are sure we need to.
}
}
void Compiler::SetLimit(Compiler::Limit limit, int value) {
switch (limit) {
#define RESOURCE(NAME, FIELD, CNAME) \
case Limit::NAME: \
limits_.FIELD = value; \
break;
#include "libshaderc_util/resources.inc"
#undef RESOURCE
}
}
int Compiler::GetLimit(Compiler::Limit limit) const {
switch (limit) {
#define RESOURCE(NAME, FIELD, CNAME) \
case Limit::NAME: \
return limits_.FIELD;
#include "libshaderc_util/resources.inc"
#undef RESOURCE
}
return 0; // Unreachable
}
std::tuple<bool, std::vector<uint32_t>, size_t> Compiler::Compile(
const string_piece& input_source_string, EShLanguage forced_shader_stage,
const std::string& error_tag, const char* entry_point_name,
const std::function<EShLanguage(std::ostream* error_stream,
const string_piece& error_tag)>&
stage_callback,
CountingIncluder& includer, OutputType output_type,
std::ostream* error_stream, size_t* total_warnings, size_t* total_errors) const {
// Compilation results to be returned:
// Initialize the result tuple as a failed compilation. In error cases, we
// should return result_tuple directly without setting its members.
auto result_tuple =
std::make_tuple(false, std::vector<uint32_t>(), (size_t)0u);
// Get the reference of the members of the result tuple. We should set their
// values for succeeded compilation before returning the result tuple.
bool& succeeded = std::get<0>(result_tuple);
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(
error_tag, target_env_, target_env_version_,
target_spirv_version_, target_spirv_version_is_forced_);
if (!target_client_info.error.empty()) {
*error_stream << target_client_info.error;
*total_warnings = 0;
*total_errors = 1;
return result_tuple;
}
EShLanguage used_shader_stage = forced_shader_stage;
const std::string macro_definitions =
shaderc_util::format(predefined_macros_, "#define ", " ", "\n");
const std::string pound_extension =
"#extension GL_GOOGLE_include_directive : enable\n";
const std::string preamble = macro_definitions + pound_extension;
std::string preprocessed_shader;
// If only preprocessing, we definitely need to preprocess. Otherwise, if
// we don't know the stage until now, we need the preprocessed shader to
// deduce the shader stage.
if (output_type == OutputType::PreprocessedText ||
used_shader_stage == EShLangCount) {
bool success;
std::string glslang_errors;
std::tie(success, preprocessed_shader, glslang_errors) =
PreprocessShader(error_tag, input_source_string, preamble, includer);
success &= PrintFilteredErrors(error_tag, error_stream, warnings_as_errors_,
/* suppress_warnings = */ true,
glslang_errors.c_str(), total_warnings,
total_errors);
if (!success) return result_tuple;
// Because of the behavior change of the #line directive, the #line
// directive introducing each file's content must use the syntax for the
// specified version. So we need to probe this shader's version and
// profile.
int version;
EProfile profile;
std::tie(version, profile) = DeduceVersionProfile(preprocessed_shader);
const bool is_for_next_line = LineDirectiveIsForNextLine(version, profile);
preprocessed_shader =
CleanupPreamble(preprocessed_shader, error_tag, pound_extension,
includer.num_include_directives(), is_for_next_line);
if (output_type == OutputType::PreprocessedText) {
// Set the values of the result tuple.
succeeded = true;
compilation_output_data = ConvertStringToVector(preprocessed_shader);
compilation_output_data_size_in_bytes = preprocessed_shader.size();
return result_tuple;
} else if (used_shader_stage == EShLangCount) {
std::string errors;
std::tie(used_shader_stage, errors) =
GetShaderStageFromSourceCode(error_tag, preprocessed_shader);
if (!errors.empty()) {
*error_stream << errors;
return result_tuple;
}
if (used_shader_stage == EShLangCount) {
if ((used_shader_stage = stage_callback(error_stream, error_tag)) ==
EShLangCount) {
return result_tuple;
}
}
}
}
// Parsing requires its own Glslang symbol tables.
glslang::TShader shader(used_shader_stage);
const char* shader_strings = input_source_string.data();
const int shader_lengths = static_cast<int>(input_source_string.size());
const char* string_names = error_tag.c_str();
shader.setStringsWithLengthsAndNames(&shader_strings, &shader_lengths,
&string_names, 1);
shader.setPreamble(preamble.c_str());
shader.setEntryPoint(entry_point_name);
shader.setAutoMapBindings(auto_bind_uniforms_);
if (auto_combined_image_sampler_) {
shader.setTextureSamplerTransformMode(EShTexSampTransUpgradeTextureRemoveSampler);
}
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.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();
}
shader.setInvertY(invert_y_enabled_);
shader.setNanMinMaxClamp(nan_clamp_);
const EShMessages rules =
GetMessageRules(target_env_, source_language_, hlsl_offsets_,
generate_debug_info_);
bool success = shader.parse(&limits_, default_version_, default_profile_,