Android Build Tools
This commit is contained in:
76
Android/android-ndk-r27d/sources/third_party/shaderc/Android.mk
vendored
Normal file
76
Android/android-ndk-r27d/sources/third_party/shaderc/Android.mk
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
# 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)))
|
||||
316
Android/android-ndk-r27d/sources/third_party/shaderc/CHANGES
vendored
Normal file
316
Android/android-ndk-r27d/sources/third_party/shaderc/CHANGES
vendored
Normal file
@ -0,0 +1,316 @@
|
||||
Revision history for Shaderc
|
||||
|
||||
v2022.3 2022-10-12
|
||||
- #1264: Implement defaults for SPV_EXT_mesh_shader builtins
|
||||
- Update SPIRV-Tools to v2022.4
|
||||
|
||||
v2022.2 2022-08-11
|
||||
- Require CMake 3.14 or later
|
||||
- Support 16bit types in HLSL, via glslc option -fhlsl-16bit-types
|
||||
and associated library API methods. PR #1251
|
||||
- Update glslc tests for newer Glslang debug output
|
||||
- Update SPIRV-Tools v2022.3 plus one patch
|
||||
- Update SPIRV-Headers
|
||||
|
||||
v2022.1 2022-02-03
|
||||
- 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
|
||||
29
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/Android.mk
vendored
Normal file
29
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/Android.mk
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
# 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)
|
||||
72
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/include/shaderc/env.h
vendored
Normal file
72
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/include/shaderc/env.h
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
// 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_
|
||||
589
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/include/shaderc/shaderc.h
vendored
Normal file
589
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/include/shaderc/shaderc.h
vendored
Normal file
@ -0,0 +1,589 @@
|
||||
// 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 16-bit types are supported in HLSL or not.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_hlsl_16bit_types(
|
||||
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_
|
||||
607
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/include/shaderc/shaderc.hpp
vendored
Normal file
607
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/include/shaderc/shaderc.hpp
vendored
Normal file
@ -0,0 +1,607 @@
|
||||
// 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 16-bit types are supported in HLSL or not.
|
||||
void SetHlsl16BitTypes(bool enable) {
|
||||
shaderc_compile_options_set_hlsl_16bit_types(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_
|
||||
39
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/include/shaderc/status.h
vendored
Normal file
39
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/include/shaderc/status.h
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
// 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_
|
||||
37
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/include/shaderc/visibility.h
vendored
Normal file
37
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/include/shaderc/visibility.h
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
// 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_
|
||||
799
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/src/shaderc.cc
vendored
Normal file
799
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/src/shaderc.cc
vendored
Normal file
@ -0,0 +1,799 @@
|
||||
// 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_hlsl_16bit_types(
|
||||
shaderc_compile_options_t options, bool enable) {
|
||||
options->compiler.EnableHlsl16BitTypes(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;
|
||||
}
|
||||
54
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/src/shaderc_c_smoke_test.c
vendored
Normal file
54
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/src/shaderc_c_smoke_test.c
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
// 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;
|
||||
}
|
||||
|
||||
139
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/src/shaderc_private.h
vendored
Normal file
139
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc/src/shaderc_private.h
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
// 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_
|
||||
32
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/Android.mk
vendored
Normal file
32
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/Android.mk
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
# 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)
|
||||
@ -0,0 +1,41 @@
|
||||
// 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
|
||||
@ -0,0 +1,628 @@
|
||||
// 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),
|
||||
hlsl_16bit_types_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 HLSL 16-bit types.
|
||||
void EnableHlsl16BitTypes(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 support 16-bit HLSL types.
|
||||
bool hlsl_16bit_types_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
|
||||
@ -0,0 +1,101 @@
|
||||
// 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
|
||||
@ -0,0 +1,26 @@
|
||||
// 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_
|
||||
@ -0,0 +1,57 @@
|
||||
// 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_
|
||||
@ -0,0 +1,36 @@
|
||||
// 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_
|
||||
@ -0,0 +1,69 @@
|
||||
// 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_
|
||||
@ -0,0 +1,86 @@
|
||||
// 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_
|
||||
107
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/include/libshaderc_util/mutex.h
vendored
Normal file
107
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/include/libshaderc_util/mutex.h
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
// 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
|
||||
@ -0,0 +1,30 @@
|
||||
// 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_
|
||||
@ -0,0 +1,107 @@
|
||||
// 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)
|
||||
@ -0,0 +1,36 @@
|
||||
// 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_
|
||||
@ -0,0 +1,67 @@
|
||||
// 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
|
||||
@ -0,0 +1,357 @@
|
||||
// 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_
|
||||
@ -0,0 +1,32 @@
|
||||
// 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_
|
||||
@ -0,0 +1,61 @@
|
||||
// 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_
|
||||
62
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/args.cc
vendored
Normal file
62
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/args.cc
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
// 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
|
||||
793
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/compiler.cc
vendored
Normal file
793
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/compiler.cc
vendored
Normal file
@ -0,0 +1,793 @@
|
||||
// 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 hlsl_16bit_types,
|
||||
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 (hlsl_16bit_types) {
|
||||
result = static_cast<EShMessages>(result | EShMsgHlslEnable16BitTypes);
|
||||
}
|
||||
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_,
|
||||
hlsl_16bit_types_enabled_, generate_debug_info_);
|
||||
|
||||
bool success = shader.parse(&limits_, default_version_, default_profile_,
|
||||
force_version_profile_, kNotForwardCompatible,
|
||||
rules, includer);
|
||||
|
||||
success &= PrintFilteredErrors(error_tag, error_stream, warnings_as_errors_,
|
||||
suppress_warnings_, shader.getInfoLog(),
|
||||
total_warnings, total_errors);
|
||||
if (!success) return result_tuple;
|
||||
|
||||
glslang::TProgram program;
|
||||
program.addShader(&shader);
|
||||
success = program.link(EShMsgDefault) && program.mapIO();
|
||||
success &= PrintFilteredErrors(error_tag, error_stream, warnings_as_errors_,
|
||||
suppress_warnings_, program.getInfoLog(),
|
||||
total_warnings, total_errors);
|
||||
if (!success) return result_tuple;
|
||||
|
||||
// 'spirv' is an alias for the compilation_output_data. This alias is added
|
||||
// to serve as an input for the call to DissassemblyBinary.
|
||||
std::vector<uint32_t>& spirv = compilation_output_data;
|
||||
glslang::SpvOptions options;
|
||||
options.generateDebugInfo = generate_debug_info_;
|
||||
options.disableOptimizer = true;
|
||||
options.optimizeSize = false;
|
||||
// Note the call to GlslangToSpv also populates compilation_output_data.
|
||||
glslang::GlslangToSpv(*program.getIntermediate(used_shader_stage), spirv,
|
||||
&options);
|
||||
|
||||
// Set the tool field (the top 16-bits) in the generator word to
|
||||
// 'Shaderc over Glslang'.
|
||||
const uint32_t shaderc_generator_word = 13; // From SPIR-V XML Registry
|
||||
const uint32_t generator_word_index = 2; // SPIR-V 2.3: Physical layout
|
||||
assert(spirv.size() > generator_word_index);
|
||||
spirv[generator_word_index] =
|
||||
(spirv[generator_word_index] & 0xffff) | (shaderc_generator_word << 16);
|
||||
|
||||
std::vector<PassId> opt_passes;
|
||||
|
||||
if (hlsl_legalization_enabled_ && source_language_ == SourceLanguage::HLSL) {
|
||||
// If from HLSL, run this passes to "legalize" the SPIR-V for Vulkan
|
||||
// eg. forward and remove memory writes of opaque types.
|
||||
opt_passes.push_back(PassId::kLegalizationPasses);
|
||||
}
|
||||
|
||||
opt_passes.insert(opt_passes.end(), enabled_opt_passes_.begin(),
|
||||
enabled_opt_passes_.end());
|
||||
|
||||
if (!opt_passes.empty()) {
|
||||
std::string opt_errors;
|
||||
if (!SpirvToolsOptimize(target_env_, target_env_version_,
|
||||
opt_passes, &spirv, &opt_errors)) {
|
||||
*error_stream << "shaderc: internal error: compilation succeeded but "
|
||||
"failed to optimize: "
|
||||
<< opt_errors << "\n";
|
||||
return result_tuple;
|
||||
}
|
||||
}
|
||||
|
||||
if (output_type == OutputType::SpirvAssemblyText) {
|
||||
std::string text_or_error;
|
||||
if (!SpirvToolsDisassemble(target_env_, target_env_version_, spirv,
|
||||
&text_or_error)) {
|
||||
*error_stream << "shaderc: internal error: compilation succeeded but "
|
||||
"failed to disassemble: "
|
||||
<< text_or_error << "\n";
|
||||
return result_tuple;
|
||||
}
|
||||
succeeded = true;
|
||||
compilation_output_data = ConvertStringToVector(text_or_error);
|
||||
compilation_output_data_size_in_bytes = text_or_error.size();
|
||||
return result_tuple;
|
||||
} else {
|
||||
succeeded = true;
|
||||
// Note compilation_output_data is already populated in GlslangToSpv().
|
||||
compilation_output_data_size_in_bytes = spirv.size() * sizeof(spirv[0]);
|
||||
return result_tuple;
|
||||
}
|
||||
}
|
||||
|
||||
void Compiler::AddMacroDefinition(const char* macro, size_t macro_length,
|
||||
const char* definition,
|
||||
size_t definition_length) {
|
||||
predefined_macros_[std::string(macro, macro_length)] =
|
||||
definition ? std::string(definition, definition_length) : "";
|
||||
}
|
||||
|
||||
void Compiler::SetTargetEnv(Compiler::TargetEnv env,
|
||||
Compiler::TargetEnvVersion version) {
|
||||
target_env_ = env;
|
||||
target_env_version_ = version;
|
||||
}
|
||||
|
||||
void Compiler::SetTargetSpirv(Compiler::SpirvVersion version) {
|
||||
target_spirv_version_ = version;
|
||||
target_spirv_version_is_forced_ = true;
|
||||
}
|
||||
|
||||
void Compiler::SetSourceLanguage(Compiler::SourceLanguage lang) {
|
||||
source_language_ = lang;
|
||||
}
|
||||
|
||||
void Compiler::SetForcedVersionProfile(int version, EProfile profile) {
|
||||
default_version_ = version;
|
||||
default_profile_ = profile;
|
||||
force_version_profile_ = true;
|
||||
}
|
||||
|
||||
void Compiler::SetWarningsAsErrors() { warnings_as_errors_ = true; }
|
||||
|
||||
void Compiler::SetGenerateDebugInfo() {
|
||||
generate_debug_info_ = true;
|
||||
for (size_t i = 0; i < enabled_opt_passes_.size(); ++i) {
|
||||
if (enabled_opt_passes_[i] == PassId::kStripDebugInfo) {
|
||||
enabled_opt_passes_[i] = PassId::kNullPass;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Compiler::SetOptimizationLevel(Compiler::OptimizationLevel level) {
|
||||
// Clear previous settings first.
|
||||
enabled_opt_passes_.clear();
|
||||
|
||||
switch (level) {
|
||||
case OptimizationLevel::Size:
|
||||
if (!generate_debug_info_) {
|
||||
enabled_opt_passes_.push_back(PassId::kStripDebugInfo);
|
||||
}
|
||||
enabled_opt_passes_.push_back(PassId::kSizePasses);
|
||||
break;
|
||||
case OptimizationLevel::Performance:
|
||||
if (!generate_debug_info_) {
|
||||
enabled_opt_passes_.push_back(PassId::kStripDebugInfo);
|
||||
}
|
||||
enabled_opt_passes_.push_back(PassId::kPerformancePasses);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Compiler::EnableHlslLegalization(bool hlsl_legalization_enabled) {
|
||||
hlsl_legalization_enabled_ = hlsl_legalization_enabled;
|
||||
}
|
||||
|
||||
void Compiler::EnableHlslFunctionality1(bool enable) {
|
||||
hlsl_functionality1_enabled_ = enable;
|
||||
}
|
||||
|
||||
void Compiler::EnableHlsl16BitTypes(bool enable) {
|
||||
hlsl_16bit_types_enabled_ = enable;
|
||||
}
|
||||
|
||||
void Compiler::EnableInvertY(bool enable) { invert_y_enabled_ = enable; }
|
||||
|
||||
void Compiler::SetNanClamp(bool enable) { nan_clamp_ = enable; }
|
||||
|
||||
void Compiler::SetSuppressWarnings() { suppress_warnings_ = true; }
|
||||
|
||||
std::tuple<bool, std::string, std::string> Compiler::PreprocessShader(
|
||||
const std::string& error_tag, const string_piece& shader_source,
|
||||
const string_piece& shader_preamble, CountingIncluder& includer) const {
|
||||
// The stage does not matter for preprocessing.
|
||||
glslang::TShader shader(EShLangVertex);
|
||||
const char* shader_strings = shader_source.data();
|
||||
const int shader_lengths = static_cast<int>(shader_source.size());
|
||||
const char* string_names = error_tag.c_str();
|
||||
shader.setStringsWithLengthsAndNames(&shader_strings, &shader_lengths,
|
||||
&string_names, 1);
|
||||
shader.setPreamble(shader_preamble.data());
|
||||
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()) {
|
||||
return std::make_tuple(false, "", target_client_info.error);
|
||||
}
|
||||
shader.setEnvClient(target_client_info.client,
|
||||
target_client_info.client_version);
|
||||
if (hlsl_functionality1_enabled_) {
|
||||
shader.setEnvTargetHlslFunctionality1();
|
||||
}
|
||||
shader.setInvertY(invert_y_enabled_);
|
||||
shader.setNanMinMaxClamp(nan_clamp_);
|
||||
|
||||
// The preprocessor might be sensitive to the target environment.
|
||||
// So combine the existing rules with the just-give-me-preprocessor-output
|
||||
// flag.
|
||||
const auto rules = static_cast<EShMessages>(
|
||||
EShMsgOnlyPreprocessor |
|
||||
GetMessageRules(target_env_, source_language_, hlsl_offsets_,
|
||||
hlsl_16bit_types_enabled_, false));
|
||||
|
||||
std::string preprocessed_shader;
|
||||
const bool success = shader.preprocess(
|
||||
&limits_, default_version_, default_profile_, force_version_profile_,
|
||||
kNotForwardCompatible, rules, &preprocessed_shader, includer);
|
||||
|
||||
if (success) {
|
||||
return std::make_tuple(true, preprocessed_shader, shader.getInfoLog());
|
||||
}
|
||||
return std::make_tuple(false, "", shader.getInfoLog());
|
||||
}
|
||||
|
||||
std::string Compiler::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 {
|
||||
// Those #define directives in preamble will become empty lines after
|
||||
// preprocessing. We also injected an #extension directive to turn on #include
|
||||
// directive support. In the original preprocessing output from glslang, it
|
||||
// appears before the user source string. We need to do proper adjustment:
|
||||
// * Remove empty lines generated from #define directives in preamble.
|
||||
// * If there is no #include directive in the source code, we do not need to
|
||||
// output the injected #extension directive. Otherwise,
|
||||
// * If there exists a #version directive in the source code, it should be
|
||||
// placed at the first line. Its original line will be filled with an empty
|
||||
// line as placeholder to maintain the code structure.
|
||||
|
||||
const std::vector<string_piece> lines =
|
||||
preprocessed_shader.get_fields('\n', /* keep_delimiter = */ true);
|
||||
|
||||
std::ostringstream output_stream;
|
||||
|
||||
size_t pound_extension_index = lines.size();
|
||||
size_t pound_version_index = lines.size();
|
||||
for (size_t i = 0; i < lines.size(); ++i) {
|
||||
if (lines[i] == pound_extension) {
|
||||
pound_extension_index = std::min(i, pound_extension_index);
|
||||
} else if (lines[i].starts_with("#version")) {
|
||||
// In a preprocessed shader, directives are in a canonical format, so we
|
||||
// can confidently compare to '#version' verbatim, without worrying about
|
||||
// whitespace.
|
||||
pound_version_index = i;
|
||||
if (num_include_directives > 0) output_stream << lines[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
// We know that #extension directive exists and appears before #version
|
||||
// directive (if any).
|
||||
assert(pound_extension_index < lines.size());
|
||||
|
||||
for (size_t i = 0; i < pound_extension_index; ++i) {
|
||||
// All empty lines before the #line directive we injected are generated by
|
||||
// preprocessing preamble. Do not output them.
|
||||
if (lines[i].strip_whitespace().empty()) continue;
|
||||
output_stream << lines[i];
|
||||
}
|
||||
|
||||
if (num_include_directives > 0) {
|
||||
output_stream << pound_extension;
|
||||
// Also output a #line directive for the main file.
|
||||
output_stream << GetLineDirective(is_for_next_line, error_tag);
|
||||
}
|
||||
|
||||
for (size_t i = pound_extension_index + 1; i < lines.size(); ++i) {
|
||||
if (i == pound_version_index) {
|
||||
if (num_include_directives > 0) {
|
||||
output_stream << "\n";
|
||||
} else {
|
||||
output_stream << lines[i];
|
||||
}
|
||||
} else {
|
||||
output_stream << lines[i];
|
||||
}
|
||||
}
|
||||
|
||||
return output_stream.str();
|
||||
}
|
||||
|
||||
std::pair<EShLanguage, std::string> Compiler::GetShaderStageFromSourceCode(
|
||||
string_piece filename, const std::string& preprocessed_shader) const {
|
||||
const string_piece kPragmaShaderStageDirective = "#pragma shader_stage";
|
||||
const string_piece kLineDirective = "#line";
|
||||
|
||||
int version;
|
||||
EProfile profile;
|
||||
std::tie(version, profile) = DeduceVersionProfile(preprocessed_shader);
|
||||
const bool is_for_next_line = LineDirectiveIsForNextLine(version, profile);
|
||||
|
||||
std::vector<string_piece> lines =
|
||||
string_piece(preprocessed_shader).get_fields('\n');
|
||||
// The filename, logical line number (which starts from 1 and is sensitive to
|
||||
// #line directives), and stage value for #pragma shader_stage() directives.
|
||||
std::vector<std::tuple<string_piece, size_t, string_piece>> stages;
|
||||
// The physical line numbers of the first #pragma shader_stage() line and
|
||||
// first non-preprocessing line in the preprocessed shader text.
|
||||
size_t first_pragma_physical_line = lines.size() + 1;
|
||||
size_t first_non_pp_line = lines.size() + 1;
|
||||
|
||||
for (size_t i = 0, logical_line_no = 1; i < lines.size(); ++i) {
|
||||
const string_piece current_line = lines[i].strip_whitespace();
|
||||
if (current_line.starts_with(kPragmaShaderStageDirective)) {
|
||||
const string_piece stage_value =
|
||||
current_line.substr(kPragmaShaderStageDirective.size()).strip("()");
|
||||
stages.emplace_back(filename, logical_line_no, stage_value);
|
||||
first_pragma_physical_line = std::min(first_pragma_physical_line, i + 1);
|
||||
} else if (!current_line.empty() && !current_line.starts_with("#")) {
|
||||
first_non_pp_line = std::min(first_non_pp_line, i + 1);
|
||||
}
|
||||
|
||||
// Update logical line number for the next line.
|
||||
if (current_line.starts_with(kLineDirective)) {
|
||||
string_piece name;
|
||||
std::tie(logical_line_no, name) = DecodeLineDirective(current_line);
|
||||
if (!name.empty()) filename = name;
|
||||
// Note that for core profile, the meaning of #line changed since version
|
||||
// 330. The line number given by #line used to mean the logical line
|
||||
// number of the #line line. Now it means the logical line number of the
|
||||
// next line after the #line line.
|
||||
if (!is_for_next_line) ++logical_line_no;
|
||||
} else {
|
||||
++logical_line_no;
|
||||
}
|
||||
}
|
||||
if (stages.empty()) return std::make_pair(EShLangCount, "");
|
||||
|
||||
std::string error_message;
|
||||
|
||||
const string_piece& first_pragma_filename = std::get<0>(stages[0]);
|
||||
const std::string first_pragma_line = std::to_string(std::get<1>(stages[0]));
|
||||
const string_piece& first_pragma_stage = std::get<2>(stages[0]);
|
||||
|
||||
if (first_pragma_physical_line > first_non_pp_line) {
|
||||
error_message += first_pragma_filename.str() + ":" + first_pragma_line +
|
||||
": error: '#pragma': the first 'shader_stage' #pragma "
|
||||
"must appear before any non-preprocessing code\n";
|
||||
}
|
||||
|
||||
EShLanguage stage = MapStageNameToLanguage(first_pragma_stage);
|
||||
if (stage == EShLangCount) {
|
||||
error_message +=
|
||||
first_pragma_filename.str() + ":" + first_pragma_line +
|
||||
": error: '#pragma': invalid stage for 'shader_stage' #pragma: '" +
|
||||
first_pragma_stage.str() + "'\n";
|
||||
}
|
||||
|
||||
for (size_t i = 1; i < stages.size(); ++i) {
|
||||
const string_piece& current_stage = std::get<2>(stages[i]);
|
||||
if (current_stage != first_pragma_stage) {
|
||||
const string_piece& current_filename = std::get<0>(stages[i]);
|
||||
const std::string current_line = std::to_string(std::get<1>(stages[i]));
|
||||
error_message += current_filename.str() + ":" + current_line +
|
||||
": error: '#pragma': conflicting stages for "
|
||||
"'shader_stage' #pragma: '" +
|
||||
current_stage.str() + "' (was '" +
|
||||
first_pragma_stage.str() + "' at " +
|
||||
first_pragma_filename.str() + ":" + first_pragma_line +
|
||||
")\n";
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_pair(error_message.empty() ? stage : EShLangCount,
|
||||
error_message);
|
||||
}
|
||||
|
||||
std::pair<int, EProfile> Compiler::DeduceVersionProfile(
|
||||
const std::string& preprocessed_shader) const {
|
||||
int version = default_version_;
|
||||
EProfile profile = default_profile_;
|
||||
if (!force_version_profile_) {
|
||||
std::tie(version, profile) =
|
||||
GetVersionProfileFromSourceCode(preprocessed_shader);
|
||||
if (version == 0 && profile == ENoProfile) {
|
||||
version = default_version_;
|
||||
profile = default_profile_;
|
||||
}
|
||||
}
|
||||
return std::make_pair(version, profile);
|
||||
}
|
||||
|
||||
std::pair<int, EProfile> Compiler::GetVersionProfileFromSourceCode(
|
||||
const std::string& preprocessed_shader) const {
|
||||
string_piece pound_version = preprocessed_shader;
|
||||
const size_t pound_version_loc = pound_version.find("#version");
|
||||
if (pound_version_loc == string_piece::npos) {
|
||||
return std::make_pair(0, ENoProfile);
|
||||
}
|
||||
pound_version =
|
||||
pound_version.substr(pound_version_loc + std::strlen("#version"));
|
||||
pound_version = pound_version.substr(0, pound_version.find_first_of("\n"));
|
||||
|
||||
std::string version_profile;
|
||||
for (const auto character : pound_version) {
|
||||
if (character != ' ') version_profile += character;
|
||||
}
|
||||
|
||||
int version;
|
||||
EProfile profile;
|
||||
if (!ParseVersionProfile(version_profile, &version, &profile)) {
|
||||
return std::make_pair(0, ENoProfile);
|
||||
}
|
||||
return std::make_pair(version, profile);
|
||||
}
|
||||
|
||||
// Converts a string to a vector of uint32_t by copying the content of a given
|
||||
// string to a vector<uint32_t> 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) {
|
||||
size_t num_bytes_str = str.size() + 1u;
|
||||
size_t vector_length =
|
||||
(num_bytes_str + sizeof(uint32_t) - 1) / sizeof(uint32_t);
|
||||
std::vector<uint32_t> result_vec(vector_length, 0);
|
||||
std::strncpy(reinterpret_cast<char*>(result_vec.data()), str.c_str(),
|
||||
str.size());
|
||||
return result_vec;
|
||||
}
|
||||
|
||||
GlslangClientInfo GetGlslangClientInfo(
|
||||
const std::string& error_tag, shaderc_util::Compiler::TargetEnv env,
|
||||
shaderc_util::Compiler::TargetEnvVersion env_version,
|
||||
shaderc_util::Compiler::SpirvVersion spv_version,
|
||||
bool spv_version_is_forced) {
|
||||
GlslangClientInfo result;
|
||||
std::ostringstream errs;
|
||||
|
||||
using shaderc_util::Compiler;
|
||||
switch (env) {
|
||||
case Compiler::TargetEnv::Vulkan:
|
||||
result.client = glslang::EShClientVulkan;
|
||||
if (env_version == Compiler::TargetEnvVersion::Default ||
|
||||
env_version == Compiler::TargetEnvVersion::Vulkan_1_0) {
|
||||
result.client_version = glslang::EShTargetVulkan_1_0;
|
||||
} else if (env_version == Compiler::TargetEnvVersion::Vulkan_1_1) {
|
||||
result.client_version = glslang::EShTargetVulkan_1_1;
|
||||
result.target_language_version = glslang::EShTargetSpv_1_3;
|
||||
} else if (env_version == Compiler::TargetEnvVersion::Vulkan_1_2) {
|
||||
result.client_version = glslang::EShTargetVulkan_1_2;
|
||||
result.target_language_version = glslang::EShTargetSpv_1_5;
|
||||
} else if (env_version == Compiler::TargetEnvVersion::Vulkan_1_3) {
|
||||
result.client_version = glslang::EShTargetVulkan_1_3;
|
||||
result.target_language_version = glslang::EShTargetSpv_1_6;
|
||||
} else {
|
||||
errs << "error:" << error_tag << ": Invalid target client version "
|
||||
<< static_cast<uint32_t>(env_version) << " for Vulkan environment "
|
||||
<< int(env);
|
||||
}
|
||||
break;
|
||||
case Compiler::TargetEnv::OpenGLCompat:
|
||||
errs << "error: OpenGL compatibility profile is not supported";
|
||||
break;
|
||||
case Compiler::TargetEnv::OpenGL:
|
||||
result.client = glslang::EShClientOpenGL;
|
||||
if (env_version == Compiler::TargetEnvVersion::Default ||
|
||||
env_version == Compiler::TargetEnvVersion::OpenGL_4_5) {
|
||||
result.client_version = glslang::EShTargetOpenGL_450;
|
||||
} else {
|
||||
errs << "error:" << error_tag << ": Invalid target client version "
|
||||
<< static_cast<uint32_t>(env_version) << " for OpenGL environment "
|
||||
<< int(env);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
errs << "error:" << error_tag << ": Invalid target client environment "
|
||||
<< int(env);
|
||||
break;
|
||||
}
|
||||
|
||||
if (spv_version_is_forced && errs.str().empty()) {
|
||||
switch (spv_version) {
|
||||
case Compiler::SpirvVersion::v1_0:
|
||||
result.target_language_version = glslang::EShTargetSpv_1_0;
|
||||
break;
|
||||
case Compiler::SpirvVersion::v1_1:
|
||||
result.target_language_version = glslang::EShTargetSpv_1_1;
|
||||
break;
|
||||
case Compiler::SpirvVersion::v1_2:
|
||||
result.target_language_version = glslang::EShTargetSpv_1_2;
|
||||
break;
|
||||
case Compiler::SpirvVersion::v1_3:
|
||||
result.target_language_version = glslang::EShTargetSpv_1_3;
|
||||
break;
|
||||
case Compiler::SpirvVersion::v1_4:
|
||||
result.target_language_version = glslang::EShTargetSpv_1_4;
|
||||
break;
|
||||
case Compiler::SpirvVersion::v1_5:
|
||||
result.target_language_version = glslang::EShTargetSpv_1_5;
|
||||
break;
|
||||
case Compiler::SpirvVersion::v1_6:
|
||||
result.target_language_version = glslang::EShTargetSpv_1_6;
|
||||
break;
|
||||
default:
|
||||
errs << "error:" << error_tag << ": Unknown SPIR-V version " << std::hex
|
||||
<< uint32_t(spv_version);
|
||||
break;
|
||||
}
|
||||
}
|
||||
result.error = errs.str();
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace shaderc_util
|
||||
71
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/file_finder.cc
vendored
Normal file
71
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/file_finder.cc
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
// 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/file_finder.h"
|
||||
#include "libshaderc_util/string_piece.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <fstream>
|
||||
#include <ios>
|
||||
|
||||
namespace {
|
||||
|
||||
// Returns "" if path is empty or ends in '/'. Otherwise, returns "/".
|
||||
std::string MaybeSlash(const shaderc_util::string_piece& path) {
|
||||
return (path.empty() || path.back() == '/') ? "" : "/";
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace shaderc_util {
|
||||
|
||||
std::string FileFinder::FindReadableFilepath(
|
||||
const std::string& filename) const {
|
||||
assert(!filename.empty());
|
||||
static const auto for_reading = std::ios_base::in;
|
||||
std::filebuf opener;
|
||||
for (const auto& prefix : search_path_) {
|
||||
const std::string prefixed_filename =
|
||||
prefix + MaybeSlash(prefix) + filename;
|
||||
if (opener.open(prefixed_filename, for_reading)) return prefixed_filename;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string FileFinder::FindRelativeReadableFilepath(
|
||||
const std::string& requesting_file, const std::string& filename) const {
|
||||
assert(!filename.empty());
|
||||
|
||||
string_piece dir_name(requesting_file);
|
||||
|
||||
size_t last_slash = requesting_file.find_last_of("/\\");
|
||||
if (last_slash != std::string::npos) {
|
||||
dir_name = string_piece(requesting_file.c_str(),
|
||||
requesting_file.c_str() + last_slash);
|
||||
}
|
||||
|
||||
if (dir_name.size() == requesting_file.size()) {
|
||||
dir_name.clear();
|
||||
}
|
||||
|
||||
static const auto for_reading = std::ios_base::in;
|
||||
std::filebuf opener;
|
||||
const std::string relative_filename =
|
||||
dir_name.str() + MaybeSlash(dir_name) + filename;
|
||||
if (opener.open(relative_filename, for_reading)) return relative_filename;
|
||||
|
||||
return FindReadableFilepath(filename);
|
||||
}
|
||||
|
||||
} // namespace shaderc_util
|
||||
146
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/io_shaderc.cc
vendored
Normal file
146
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/io_shaderc.cc
vendored
Normal file
@ -0,0 +1,146 @@
|
||||
// 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/io_shaderc.h"
|
||||
|
||||
#include "libshaderc_util/universal_unistd.h"
|
||||
|
||||
#if _WIN32
|
||||
// Need _fileno from stdio.h
|
||||
// Need _O_BINARY and _O_TEXT from fcntl.h
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace {
|
||||
|
||||
// Outputs a descriptive message for errno_value to cerr.
|
||||
// This may be truncated to 1023 bytes on certain platforms.
|
||||
void OutputFileErrorMessage(int errno_value) {
|
||||
#ifdef _MSC_VER
|
||||
// If the error message is more than 1023 bytes it will be truncated.
|
||||
char buffer[1024];
|
||||
strerror_s(buffer, errno_value);
|
||||
std::cerr << ": " << buffer << std::endl;
|
||||
#else
|
||||
std::cerr << ": " << strerror(errno_value) << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace shaderc_util {
|
||||
|
||||
bool IsAbsolutePath(const std::string& path) {
|
||||
if (path.empty()) return false;
|
||||
// Unix-like OS: /path/to/file
|
||||
if (path.front() == '/') return true;
|
||||
// Windows: \\server\user\file
|
||||
if (path.size() > 1 && path[0] == '\\' && path[1] == '\\') {
|
||||
return true;
|
||||
}
|
||||
// Windows: X:\path\to\file
|
||||
if (path.size() > 2 && ::isalpha(path[0]) && path[1] == ':' &&
|
||||
path[2] == '\\') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string GetBaseFileName(const std::string& file_path) {
|
||||
size_t loc_slash = file_path.find_last_of("/\\");
|
||||
std::string base_name =
|
||||
file_path.substr((loc_slash == std::string::npos ? -1 : loc_slash) + 1);
|
||||
if (base_name == ".." || base_name == ".") {
|
||||
base_name = "";
|
||||
}
|
||||
return base_name;
|
||||
}
|
||||
|
||||
bool ReadFile(const std::string& input_file_name,
|
||||
std::vector<char>* input_data) {
|
||||
std::istream* stream = &std::cin;
|
||||
std::ifstream input_file;
|
||||
if (input_file_name != "-") {
|
||||
input_file.open(input_file_name, std::ios_base::binary);
|
||||
stream = &input_file;
|
||||
if (input_file.fail()) {
|
||||
std::cerr << "glslc: error: cannot open input file: '" << input_file_name
|
||||
<< "'";
|
||||
if (access(input_file_name.c_str(), R_OK) != 0) {
|
||||
OutputFileErrorMessage(errno);
|
||||
return false;
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
*input_data = std::vector<char>((std::istreambuf_iterator<char>(*stream)),
|
||||
std::istreambuf_iterator<char>());
|
||||
return true;
|
||||
}
|
||||
|
||||
std::ostream* GetOutputStream(const string_piece& output_filename,
|
||||
std::ofstream* file_stream, std::ostream* err) {
|
||||
std::ostream* stream = &std::cout;
|
||||
if (output_filename != "-") {
|
||||
file_stream->open(output_filename.str(), std::ios_base::binary);
|
||||
stream = file_stream;
|
||||
if (file_stream->fail()) {
|
||||
*err << "glslc: error: cannot open output file: '" << output_filename
|
||||
<< "'";
|
||||
if (access(output_filename.str().c_str(), W_OK) != 0) {
|
||||
OutputFileErrorMessage(errno);
|
||||
return nullptr;
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
bool WriteFile(std::ostream* stream, const string_piece& output_data) {
|
||||
if (output_data.size() > 0) {
|
||||
stream->write(output_data.data(), output_data.size());
|
||||
if (!stream->good()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
stream->flush();
|
||||
return true;
|
||||
}
|
||||
|
||||
void FlushAndSetBinaryModeOnStdout() {
|
||||
std::fflush(stdout);
|
||||
#if _WIN32
|
||||
_setmode(_fileno(stdout), _O_BINARY);
|
||||
#endif
|
||||
}
|
||||
|
||||
void FlushAndSetTextModeOnStdout() {
|
||||
std::fflush(stdout);
|
||||
#if _WIN32
|
||||
_setmode(_fileno(stdout), _O_TEXT);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace shaderc_util
|
||||
293
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/message.cc
vendored
Normal file
293
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/message.cc
vendored
Normal file
@ -0,0 +1,293 @@
|
||||
// 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/message.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
|
||||
namespace shaderc_util {
|
||||
|
||||
namespace {
|
||||
|
||||
// Given a message, deduces and returns its type. If the message type is
|
||||
// recognized, advances *message past the prefix indicating the type. Otherwise,
|
||||
// leaves *message unchanged and returns MessageType::Unknown.
|
||||
MessageType DeduceMessageType(string_piece* message) {
|
||||
static const char kErrorMessage[] = "ERROR: ";
|
||||
static const char kWarningMessage[] = "WARNING: ";
|
||||
static const char kGlobalWarningMessage[] = "Warning, ";
|
||||
|
||||
if (message->starts_with(kErrorMessage)) {
|
||||
*message = message->substr(::strlen(kErrorMessage));
|
||||
return MessageType::Error;
|
||||
} else if (message->starts_with(kWarningMessage)) {
|
||||
*message = message->substr(::strlen(kWarningMessage));
|
||||
return MessageType::Warning;
|
||||
} else if (message->starts_with(kGlobalWarningMessage)) {
|
||||
*message = message->substr(::strlen(kGlobalWarningMessage));
|
||||
return MessageType::GlobalWarning;
|
||||
}
|
||||
return MessageType::Unknown;
|
||||
}
|
||||
|
||||
// Deduces a location specification from the given message. A location
|
||||
// specification is of the form "<source-name>:<line-number>:" and a trailing
|
||||
// space. If the deduction is successful, returns true and updates source_name
|
||||
// and line_number to the deduced source name and line numer respectively. The
|
||||
// prefix standing for the location specification in message is skipped.
|
||||
// Otherwise, returns false and keeps all parameters untouched.
|
||||
bool DeduceLocationSpec(string_piece* message, string_piece* source_name,
|
||||
string_piece* line_number) {
|
||||
if (!message || message->empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// When we find a pattern like this:
|
||||
// colon
|
||||
// digits
|
||||
// colon
|
||||
// space
|
||||
// Then deduce that the source_name is the text before the first colon,
|
||||
// the line number is the digits, and the message is the text after the
|
||||
// second colon.
|
||||
|
||||
const size_t size = message->size();
|
||||
if (size <= 4) {
|
||||
// A valid message must have a colon, a digit, a colon, and a space.
|
||||
return false;
|
||||
}
|
||||
// The last possible position of the first colon.
|
||||
const size_t first_colon_cutoff = size - 4;
|
||||
// The last possible position of the second colon.
|
||||
const size_t next_colon_cutoff = size - 2;
|
||||
|
||||
for (size_t first_colon_pos = message->find_first_of(':'), next_colon_pos = 0;
|
||||
|
||||
// There is a first colon, and it's not too close to the end
|
||||
(first_colon_pos != string_piece::npos) &&
|
||||
(first_colon_pos <= first_colon_cutoff);
|
||||
|
||||
// Try the next pair of colons.
|
||||
first_colon_pos = next_colon_pos) {
|
||||
// We're guaranteed to have at least 3 more characters.
|
||||
// Guarantee progress toward the end of the string.
|
||||
next_colon_pos = message->find_first_of(':', first_colon_pos + 1);
|
||||
if ((next_colon_pos == string_piece::npos) ||
|
||||
(next_colon_pos > next_colon_cutoff)) {
|
||||
// No valid solution.
|
||||
return false;
|
||||
}
|
||||
if (first_colon_pos + 1 == next_colon_pos) {
|
||||
// There is no room for digits.
|
||||
continue;
|
||||
}
|
||||
if ((message->data()[next_colon_pos + 1] != ' ')) {
|
||||
// There is no space character after the second colon.
|
||||
continue;
|
||||
}
|
||||
if (message->find_first_not_of("0123456789", first_colon_pos + 1) ==
|
||||
next_colon_pos) {
|
||||
// We found the first solution.
|
||||
*source_name = message->substr(0, first_colon_pos);
|
||||
*line_number = message->substr(first_colon_pos + 1,
|
||||
next_colon_pos - 1 - first_colon_pos);
|
||||
*message = message->substr(next_colon_pos + 2);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Returns true if the given message is a summary message.
|
||||
bool IsSummaryMessage(const string_piece& message) {
|
||||
const size_t space_loc = message.find_first_of(' ');
|
||||
if (space_loc == string_piece::npos) return false;
|
||||
const string_piece number = message.substr(0, space_loc);
|
||||
const string_piece rest = message.substr(space_loc + 1);
|
||||
if (!std::all_of(number.begin(), number.end(), ::isdigit)) return false;
|
||||
if (!rest.starts_with("compilation errors.")) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
MessageType ParseGlslangOutput(const string_piece& message,
|
||||
bool warnings_as_errors, bool suppress_warnings,
|
||||
string_piece* source_name,
|
||||
string_piece* line_number, string_piece* rest) {
|
||||
string_piece rest_of_message(message);
|
||||
source_name->clear();
|
||||
line_number->clear();
|
||||
rest->clear();
|
||||
|
||||
// The glslang warning/error messages are typically of the following form:
|
||||
// <message-type> <location-specification> <message-body>
|
||||
//
|
||||
// <message-type> can be "WARNING:", "ERROR:", or "Warning, ". "WARNING:"
|
||||
// means a warning message for a certain line, while "Warning, " means a
|
||||
// global one.
|
||||
//
|
||||
// <location-specification> is of the form:
|
||||
// <filename-or-string-number>:<line-number>:
|
||||
// It doesn't exist if the warning/error message is a global one.
|
||||
//
|
||||
// See Glslang's TInfoSink class implementation for details.
|
||||
|
||||
bool is_error = false;
|
||||
|
||||
// Handle <message-type>.
|
||||
switch (DeduceMessageType(&rest_of_message)) {
|
||||
case MessageType::Warning:
|
||||
if (suppress_warnings) return MessageType::Ignored;
|
||||
break;
|
||||
case MessageType::Error:
|
||||
is_error = true;
|
||||
break;
|
||||
case MessageType::GlobalWarning:
|
||||
if (suppress_warnings) return MessageType::Ignored;
|
||||
*rest = rest_of_message;
|
||||
return warnings_as_errors ? MessageType::GlobalError
|
||||
: MessageType::GlobalWarning;
|
||||
case MessageType::Unknown:
|
||||
*rest = rest_of_message;
|
||||
return MessageType::Unknown;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
rest_of_message = rest_of_message.strip_whitespace();
|
||||
if (rest_of_message.empty()) return MessageType::Unknown;
|
||||
|
||||
// Now we have stripped the <message-type>. Try to see if we can find
|
||||
// a <location-specification>.
|
||||
if (DeduceLocationSpec(&rest_of_message, source_name, line_number)) {
|
||||
*rest = rest_of_message;
|
||||
return (is_error || warnings_as_errors) ? MessageType::Error
|
||||
: MessageType::Warning;
|
||||
} else {
|
||||
// No <location-specification>. This is a global warning/error message.
|
||||
// A special kind of global message is summary message, which should
|
||||
// start with a number.
|
||||
*rest = rest_of_message;
|
||||
if (IsSummaryMessage(rest_of_message)) {
|
||||
return (is_error || warnings_as_errors) ? MessageType::ErrorSummary
|
||||
: MessageType::WarningSummary;
|
||||
}
|
||||
return (is_error || warnings_as_errors) ? MessageType::GlobalError
|
||||
: MessageType::GlobalWarning;
|
||||
}
|
||||
return MessageType::Unknown;
|
||||
}
|
||||
|
||||
bool PrintFilteredErrors(const 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) {
|
||||
const char* ignored_error_strings[] = {
|
||||
"Warning, version 310 is not yet complete; most version-specific "
|
||||
"features are present, but some are missing.",
|
||||
"Warning, version 400 is not yet complete; most version-specific "
|
||||
"features are present, but some are missing.",
|
||||
"Warning, version 410 is not yet complete; most version-specific "
|
||||
"features are present, but some are missing.",
|
||||
"Warning, version 420 is not yet complete; most version-specific "
|
||||
"features are present, but some are missing.",
|
||||
"Warning, version 430 is not yet complete; most version-specific "
|
||||
"features are present, but some are missing.",
|
||||
"Warning, version 440 is not yet complete; most version-specific "
|
||||
"features are present, but some are missing.",
|
||||
"Warning, version 450 is not yet complete; most version-specific "
|
||||
"features are present, but some are missing.",
|
||||
"Linked vertex stage:", "Linked fragment stage:",
|
||||
"Linked tessellation control stage:",
|
||||
"Linked tessellation evaluation stage:", "Linked geometry stage:",
|
||||
"Linked compute stage:", ""};
|
||||
size_t existing_total_errors = *total_errors;
|
||||
string_piece error_messages(error_list);
|
||||
for (const string_piece& message : error_messages.get_fields('\n')) {
|
||||
if (std::find(std::begin(ignored_error_strings),
|
||||
std::end(ignored_error_strings),
|
||||
message) == std::end(ignored_error_strings)) {
|
||||
string_piece source_name;
|
||||
string_piece line_number;
|
||||
string_piece rest;
|
||||
const MessageType type =
|
||||
ParseGlslangOutput(message, warnings_as_errors, suppress_warnings,
|
||||
&source_name, &line_number, &rest);
|
||||
string_piece name = file_name;
|
||||
if (!source_name.empty()) {
|
||||
// -1 is the string number for the preamble injected by us.
|
||||
name = source_name == "-1" ? "<command line>" : source_name;
|
||||
}
|
||||
switch (type) {
|
||||
case MessageType::Error:
|
||||
case MessageType::Warning:
|
||||
assert(!name.empty() && !line_number.empty() && !rest.empty());
|
||||
*error_stream << name << ":" << line_number << ": "
|
||||
<< (type == MessageType::Error ? "error: "
|
||||
: "warning: ")
|
||||
<< rest.strip_whitespace() << std::endl;
|
||||
*total_errors += type == MessageType::Error;
|
||||
*total_warnings += type == MessageType::Warning;
|
||||
break;
|
||||
case MessageType::ErrorSummary:
|
||||
case MessageType::WarningSummary:
|
||||
break;
|
||||
case MessageType::GlobalError:
|
||||
case MessageType::GlobalWarning:
|
||||
assert(!rest.empty());
|
||||
*total_errors += type == MessageType::GlobalError;
|
||||
*total_warnings += type == MessageType::GlobalWarning;
|
||||
*error_stream << name << ": "
|
||||
<< (type == MessageType::GlobalError ? "error"
|
||||
: "warning")
|
||||
<< ": " << rest.strip_whitespace() << std::endl;
|
||||
break;
|
||||
case MessageType::Unknown:
|
||||
*error_stream << name << ":";
|
||||
*error_stream << " " << message << std::endl;
|
||||
break;
|
||||
case MessageType::Ignored:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (existing_total_errors == *total_errors);
|
||||
}
|
||||
|
||||
// Outputs the number of warnings and errors if there are any.
|
||||
void OutputMessages(std::ostream* error_stream, size_t total_warnings,
|
||||
size_t total_errors) {
|
||||
if (total_warnings > 0 || total_errors > 0) {
|
||||
if (total_warnings > 0 && total_errors > 0) {
|
||||
*error_stream << total_warnings << " warning"
|
||||
<< (total_warnings > 1 ? "s" : "") << " and "
|
||||
<< total_errors << " error" << (total_errors > 1 ? "s" : "")
|
||||
<< " generated." << std::endl;
|
||||
} else if (total_warnings > 0) {
|
||||
*error_stream << total_warnings << " warning"
|
||||
<< (total_warnings > 1 ? "s" : "") << " generated."
|
||||
<< std::endl;
|
||||
} else if (total_errors > 0) {
|
||||
*error_stream << total_errors << " error" << (total_errors > 1 ? "s" : "")
|
||||
<< " generated." << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace glslc
|
||||
153
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/resources.cc
vendored
Normal file
153
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/resources.cc
vendored
Normal file
@ -0,0 +1,153 @@
|
||||
// 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/resources.h"
|
||||
|
||||
#include "glslang/Include/ResourceLimits.h"
|
||||
|
||||
namespace shaderc_util {
|
||||
|
||||
// These numbers come from the OpenGL 4.4 core profile specification Chapter 23
|
||||
// unless otherwise specified.
|
||||
const TBuiltInResource kDefaultTBuiltInResource = {
|
||||
/*.maxLights = */ 8, // From OpenGL 3.0 table 6.46.
|
||||
/*.maxClipPlanes = */ 6, // From OpenGL 3.0 table 6.46.
|
||||
/*.maxTextureUnits = */ 2, // From OpenGL 3.0 table 6.50.
|
||||
/*.maxTextureCoords = */ 8, // From OpenGL 3.0 table 6.50.
|
||||
/*.maxVertexAttribs = */ 16,
|
||||
/*.maxVertexUniformComponents = */ 4096,
|
||||
/*.maxVaryingFloats = */ 60, // From OpenGLES 3.1 table 6.44.
|
||||
/*.maxVertexTextureImageUnits = */ 16,
|
||||
/*.maxCombinedTextureImageUnits = */ 80,
|
||||
/*.maxTextureImageUnits = */ 16,
|
||||
/*.maxFragmentUniformComponents = */ 1024,
|
||||
|
||||
// glslang has 32 maxDrawBuffers.
|
||||
// Pixel phone Vulkan driver in Android N has 8
|
||||
// maxFragmentOutputAttachments.
|
||||
/*.maxDrawBuffers = */ 8,
|
||||
|
||||
/*.maxVertexUniformVectors = */ 256,
|
||||
/*.maxVaryingVectors = */ 15, // From OpenGLES 3.1 table 6.44.
|
||||
/*.maxFragmentUniformVectors = */ 256,
|
||||
/*.maxVertexOutputVectors = */ 16, // maxVertexOutputComponents / 4
|
||||
/*.maxFragmentInputVectors = */ 15, // maxFragmentInputComponents / 4
|
||||
/*.minProgramTexelOffset = */ -8,
|
||||
/*.maxProgramTexelOffset = */ 7,
|
||||
/*.maxClipDistances = */ 8,
|
||||
/*.maxComputeWorkGroupCountX = */ 65535,
|
||||
/*.maxComputeWorkGroupCountY = */ 65535,
|
||||
/*.maxComputeWorkGroupCountZ = */ 65535,
|
||||
/*.maxComputeWorkGroupSizeX = */ 1024,
|
||||
/*.maxComputeWorkGroupSizeX = */ 1024,
|
||||
/*.maxComputeWorkGroupSizeZ = */ 64,
|
||||
/*.maxComputeUniformComponents = */ 512,
|
||||
/*.maxComputeTextureImageUnits = */ 16,
|
||||
/*.maxComputeImageUniforms = */ 8,
|
||||
/*.maxComputeAtomicCounters = */ 8,
|
||||
/*.maxComputeAtomicCounterBuffers = */ 1, // From OpenGLES 3.1 Table 6.43
|
||||
/*.maxVaryingComponents = */ 60,
|
||||
/*.maxVertexOutputComponents = */ 64,
|
||||
/*.maxGeometryInputComponents = */ 64,
|
||||
/*.maxGeometryOutputComponents = */ 128,
|
||||
/*.maxFragmentInputComponents = */ 128,
|
||||
/*.maxImageUnits = */ 8, // This does not seem to be defined anywhere,
|
||||
// set to ImageUnits.
|
||||
/*.maxCombinedImageUnitsAndFragmentOutputs = */ 8,
|
||||
/*.maxCombinedShaderOutputResources = */ 8,
|
||||
/*.maxImageSamples = */ 0,
|
||||
/*.maxVertexImageUniforms = */ 0,
|
||||
/*.maxTessControlImageUniforms = */ 0,
|
||||
/*.maxTessEvaluationImageUniforms = */ 0,
|
||||
/*.maxGeometryImageUniforms = */ 0,
|
||||
/*.maxFragmentImageUniforms = */ 8,
|
||||
/*.maxCombinedImageUniforms = */ 8,
|
||||
/*.maxGeometryTextureImageUnits = */ 16,
|
||||
/*.maxGeometryOutputVertices = */ 256,
|
||||
/*.maxGeometryTotalOutputComponents = */ 1024,
|
||||
/*.maxGeometryUniformComponents = */ 512,
|
||||
/*.maxGeometryVaryingComponents = */ 60, // Does not seem to be defined
|
||||
// anywhere, set equal to
|
||||
// maxVaryingComponents.
|
||||
/*.maxTessControlInputComponents = */ 128,
|
||||
/*.maxTessControlOutputComponents = */ 128,
|
||||
/*.maxTessControlTextureImageUnits = */ 16,
|
||||
/*.maxTessControlUniformComponents = */ 1024,
|
||||
/*.maxTessControlTotalOutputComponents = */ 4096,
|
||||
/*.maxTessEvaluationInputComponents = */ 128,
|
||||
/*.maxTessEvaluationOutputComponents = */ 128,
|
||||
/*.maxTessEvaluationTextureImageUnits = */ 16,
|
||||
/*.maxTessEvaluationUniformComponents = */ 1024,
|
||||
/*.maxTessPatchComponents = */ 120,
|
||||
/*.maxPatchVertices = */ 32,
|
||||
/*.maxTessGenLevel = */ 64,
|
||||
/*.maxViewports = */ 16,
|
||||
/*.maxVertexAtomicCounters = */ 0,
|
||||
/*.maxTessControlAtomicCounters = */ 0,
|
||||
/*.maxTessEvaluationAtomicCounters = */ 0,
|
||||
/*.maxGeometryAtomicCounters = */ 0,
|
||||
/*.maxFragmentAtomicCounters = */ 8,
|
||||
/*.maxCombinedAtomicCounters = */ 8,
|
||||
/*.maxAtomicCounterBindings = */ 1,
|
||||
/*.maxVertexAtomicCounterBuffers = */ 0, // From OpenGLES 3.1 Table 6.41.
|
||||
|
||||
// ARB_shader_atomic_counters.
|
||||
/*.maxTessControlAtomicCounterBuffers = */ 0,
|
||||
/*.maxTessEvaluationAtomicCounterBuffers = */ 0,
|
||||
/*.maxGeometryAtomicCounterBuffers = */ 0,
|
||||
// /ARB_shader_atomic_counters.
|
||||
|
||||
/*.maxFragmentAtomicCounterBuffers = */ 0, // From OpenGLES 3.1 Table 6.43.
|
||||
/*.maxCombinedAtomicCounterBuffers = */ 1,
|
||||
/*.maxAtomicCounterBufferSize = */ 32,
|
||||
/*.maxTransformFeedbackBuffers = */ 4,
|
||||
/*.maxTransformFeedbackInterleavedComponents = */ 64,
|
||||
/*.maxCullDistances = */ 8, // ARB_cull_distance.
|
||||
/*.maxCombinedClipAndCullDistances = */ 8, // ARB_cull_distance.
|
||||
/*.maxSamples = */ 4,
|
||||
/* .maxMeshOutputVerticesNV = */ 256,
|
||||
/* .maxMeshOutputPrimitivesNV = */ 512,
|
||||
/* .maxMeshWorkGroupSizeX_NV = */ 32,
|
||||
/* .maxMeshWorkGroupSizeY_NV = */ 1,
|
||||
/* .maxMeshWorkGroupSizeZ_NV = */ 1,
|
||||
/* .maxTaskWorkGroupSizeX_NV = */ 32,
|
||||
/* .maxTaskWorkGroupSizeY_NV = */ 1,
|
||||
/* .maxTaskWorkGroupSizeZ_NV = */ 1,
|
||||
/* .maxMeshViewCountNV = */ 4,
|
||||
/* .maxMeshOutputVerticesEXT = */ 256,
|
||||
/* .maxMeshOutputPrimitivesEXT = */ 256,
|
||||
/* .maxMeshWorkGroupSizeX_EXT = */ 128,
|
||||
/* .maxMeshWorkGroupSizeY_EXT = */ 128,
|
||||
/* .maxMeshWorkGroupSizeZ_EXT = */ 128,
|
||||
/* .maxTaskWorkGroupSizeX_EXT = */ 128,
|
||||
/* .maxTaskWorkGroupSizeY_EXT = */ 128,
|
||||
/* .maxTaskWorkGroupSizeZ_EXT = */ 128,
|
||||
/* .maxMeshViewCountEXT = */ 4,
|
||||
/* .maxDualSourceDrawBuffersEXT = */ 1,
|
||||
// This is the glslang TLimits structure.
|
||||
// It defines whether or not the following features are enabled.
|
||||
// We want them to all be enabled.
|
||||
/*.limits = */ {
|
||||
/*.nonInductiveForLoops = */ 1,
|
||||
/*.whileLoops = */ 1,
|
||||
/*.doWhileLoops = */ 1,
|
||||
/*.generalUniformIndexing = */ 1,
|
||||
/*.generalAttributeMatrixVectorIndexing = */ 1,
|
||||
/*.generalVaryingIndexing = */ 1,
|
||||
/*.generalSamplerIndexing = */ 1,
|
||||
/*.generalVariableIndexing = */ 1,
|
||||
/*.generalConstantMatrixVectorIndexing = */ 1,
|
||||
}};
|
||||
|
||||
} // namespace shaderc_util
|
||||
53
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/shader_stage.cc
vendored
Normal file
53
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/shader_stage.cc
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
// 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/shader_stage.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// Maps an identifier to a language.
|
||||
struct LanguageMapping {
|
||||
const char* id;
|
||||
EShLanguage language;
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace shaderc_util {
|
||||
|
||||
EShLanguage MapStageNameToLanguage(const string_piece& stage_name) {
|
||||
const LanguageMapping string_to_stage[] = {
|
||||
{"vertex", EShLangVertex},
|
||||
{"fragment", EShLangFragment},
|
||||
{"tesscontrol", EShLangTessControl},
|
||||
{"tesseval", EShLangTessEvaluation},
|
||||
{"geometry", EShLangGeometry},
|
||||
{"compute", EShLangCompute},
|
||||
{"raygen", EShLangRayGenNV},
|
||||
{"intersect", EShLangIntersectNV},
|
||||
{"anyhit", EShLangAnyHitNV},
|
||||
{"closest", EShLangClosestHitNV},
|
||||
{"miss", EShLangMissNV},
|
||||
{"callable", EShLangCallableNV},
|
||||
{"task", EShLangTaskNV},
|
||||
{"mesh", EShLangMeshNV},
|
||||
};
|
||||
|
||||
for (const auto& entry : string_to_stage) {
|
||||
if (stage_name == entry.id) return entry.language;
|
||||
}
|
||||
return EShLangCount;
|
||||
}
|
||||
|
||||
} // namespace shaderc_util
|
||||
169
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/spirv_tools_wrapper.cc
vendored
Normal file
169
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/spirv_tools_wrapper.cc
vendored
Normal file
@ -0,0 +1,169 @@
|
||||
// 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 "libshaderc_util/spirv_tools_wrapper.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
||||
#include "spirv-tools/optimizer.hpp"
|
||||
|
||||
namespace shaderc_util {
|
||||
|
||||
namespace {
|
||||
|
||||
// Gets the corresponding target environment used in SPIRV-Tools.
|
||||
spv_target_env GetSpirvToolsTargetEnv(Compiler::TargetEnv env,
|
||||
Compiler::TargetEnvVersion version) {
|
||||
switch (env) {
|
||||
case Compiler::TargetEnv::Vulkan:
|
||||
switch (version) {
|
||||
case Compiler::TargetEnvVersion::Default:
|
||||
return SPV_ENV_VULKAN_1_0;
|
||||
case Compiler::TargetEnvVersion::Vulkan_1_0:
|
||||
return SPV_ENV_VULKAN_1_0;
|
||||
case Compiler::TargetEnvVersion::Vulkan_1_1:
|
||||
return SPV_ENV_VULKAN_1_1;
|
||||
case Compiler::TargetEnvVersion::Vulkan_1_2:
|
||||
return SPV_ENV_VULKAN_1_2;
|
||||
case Compiler::TargetEnvVersion::Vulkan_1_3:
|
||||
return SPV_ENV_VULKAN_1_3;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Compiler::TargetEnv::OpenGL:
|
||||
return SPV_ENV_OPENGL_4_5;
|
||||
case Compiler::TargetEnv::OpenGLCompat:
|
||||
// Errors out before getting here. But the compiler wants us to handle
|
||||
// enum anyway.
|
||||
return SPV_ENV_OPENGL_4_5;
|
||||
}
|
||||
assert(false && "unexpected target environment or version");
|
||||
return SPV_ENV_VULKAN_1_0;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
bool SpirvToolsDisassemble(Compiler::TargetEnv env,
|
||||
Compiler::TargetEnvVersion version,
|
||||
const std::vector<uint32_t>& binary,
|
||||
std::string* text_or_error) {
|
||||
spvtools::SpirvTools tools(GetSpirvToolsTargetEnv(env, version));
|
||||
std::ostringstream oss;
|
||||
tools.SetMessageConsumer([&oss](spv_message_level_t, const char*,
|
||||
const spv_position_t& position,
|
||||
const char* message) {
|
||||
oss << position.index << ": " << message;
|
||||
});
|
||||
const bool success =
|
||||
tools.Disassemble(binary, text_or_error,
|
||||
SPV_BINARY_TO_TEXT_OPTION_INDENT |
|
||||
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES);
|
||||
if (!success) {
|
||||
*text_or_error = oss.str();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool SpirvToolsAssemble(Compiler::TargetEnv env,
|
||||
Compiler::TargetEnvVersion version,
|
||||
const string_piece assembly, spv_binary* binary,
|
||||
std::string* errors) {
|
||||
auto spvtools_context =
|
||||
spvContextCreate(GetSpirvToolsTargetEnv(env, version));
|
||||
spv_diagnostic spvtools_diagnostic = nullptr;
|
||||
|
||||
*binary = nullptr;
|
||||
errors->clear();
|
||||
|
||||
const bool success =
|
||||
spvTextToBinary(spvtools_context, assembly.data(), assembly.size(),
|
||||
binary, &spvtools_diagnostic) == SPV_SUCCESS;
|
||||
if (!success) {
|
||||
std::ostringstream oss;
|
||||
oss << spvtools_diagnostic->position.line + 1 << ":"
|
||||
<< spvtools_diagnostic->position.column + 1 << ": "
|
||||
<< spvtools_diagnostic->error;
|
||||
*errors = oss.str();
|
||||
}
|
||||
|
||||
spvDiagnosticDestroy(spvtools_diagnostic);
|
||||
spvContextDestroy(spvtools_context);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool SpirvToolsOptimize(Compiler::TargetEnv env,
|
||||
Compiler::TargetEnvVersion version,
|
||||
const std::vector<PassId>& enabled_passes,
|
||||
std::vector<uint32_t>* binary, std::string* errors) {
|
||||
errors->clear();
|
||||
if (enabled_passes.empty()) return true;
|
||||
if (std::all_of(
|
||||
enabled_passes.cbegin(), enabled_passes.cend(),
|
||||
[](const PassId& pass) { return pass == PassId::kNullPass; })) {
|
||||
return true;
|
||||
}
|
||||
|
||||
spvtools::ValidatorOptions val_opts;
|
||||
// This allows flexible memory layout for HLSL.
|
||||
val_opts.SetSkipBlockLayout(true);
|
||||
// This allows HLSL legalization regarding resources.
|
||||
val_opts.SetRelaxLogicalPointer(true);
|
||||
// This uses relaxed rules for pre-legalized HLSL.
|
||||
val_opts.SetBeforeHlslLegalization(true);
|
||||
|
||||
spvtools::OptimizerOptions opt_opts;
|
||||
opt_opts.set_validator_options(val_opts);
|
||||
opt_opts.set_run_validator(true);
|
||||
|
||||
spvtools::Optimizer optimizer(GetSpirvToolsTargetEnv(env, version));
|
||||
|
||||
std::ostringstream oss;
|
||||
optimizer.SetMessageConsumer(
|
||||
[&oss](spv_message_level_t, const char*, const spv_position_t&,
|
||||
const char* message) { oss << message << "\n"; });
|
||||
|
||||
for (const auto& pass : enabled_passes) {
|
||||
switch (pass) {
|
||||
case PassId::kLegalizationPasses:
|
||||
optimizer.RegisterLegalizationPasses();
|
||||
break;
|
||||
case PassId::kPerformancePasses:
|
||||
optimizer.RegisterPerformancePasses();
|
||||
break;
|
||||
case PassId::kSizePasses:
|
||||
optimizer.RegisterSizePasses();
|
||||
break;
|
||||
case PassId::kNullPass:
|
||||
// We actually don't need to do anything for null pass.
|
||||
break;
|
||||
case PassId::kStripDebugInfo:
|
||||
optimizer.RegisterPass(spvtools::CreateStripDebugInfoPass());
|
||||
break;
|
||||
case PassId::kCompactIds:
|
||||
optimizer.RegisterPass(spvtools::CreateCompactIdsPass());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!optimizer.Run(binary->data(), binary->size(), binary, opt_opts)) {
|
||||
*errors = oss.str();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace shaderc_util
|
||||
59
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/version_profile.cc
vendored
Normal file
59
Android/android-ndk-r27d/sources/third_party/shaderc/libshaderc_util/src/version_profile.cc
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
// 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/version_profile.h"
|
||||
|
||||
#include <cctype>
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
|
||||
const int kVersionNumberLength = 3;
|
||||
const int kMaxProfileLength = 13; // strlen(compatibility)
|
||||
const int kMaxVersionProfileLength = kVersionNumberLength + kMaxProfileLength;
|
||||
const int kMinVersionProfileLength = kVersionNumberLength;
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace shaderc_util {
|
||||
|
||||
bool ParseVersionProfile(const std::string& version_profile, int* version,
|
||||
EProfile* profile) {
|
||||
if (version_profile.size() < kMinVersionProfileLength ||
|
||||
version_profile.size() > kMaxVersionProfileLength ||
|
||||
!::isdigit(version_profile.front()))
|
||||
return false;
|
||||
|
||||
std::string profile_string;
|
||||
std::istringstream(version_profile) >> *version >> profile_string;
|
||||
|
||||
if (!IsKnownVersion(*version)) {
|
||||
return false;
|
||||
}
|
||||
if (profile_string.empty()) {
|
||||
*profile = ENoProfile;
|
||||
} else if (profile_string == "core") {
|
||||
*profile = ECoreProfile;
|
||||
} else if (profile_string == "es") {
|
||||
*profile = EEsProfile;
|
||||
} else if (profile_string == "compatibility") {
|
||||
*profile = ECompatibilityProfile;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace shaderc_util
|
||||
35
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/Android.mk
vendored
Normal file
35
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/Android.mk
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
THIRD_PARTY_PATH := $(call my-dir)
|
||||
|
||||
# Set the location of glslang
|
||||
ifeq ($(GLSLANG_LOCAL_PATH),)
|
||||
GLSLANG_LOCAL_PATH:=$(THIRD_PARTY_PATH)/glslang
|
||||
endif
|
||||
include $(GLSLANG_LOCAL_PATH)/Android.mk
|
||||
|
||||
# Set the location of SPIRV-Tools.
|
||||
# Allow the user to override it, but default it to under our third_party directory.
|
||||
ifeq ($(SPVTOOLS_LOCAL_PATH),)
|
||||
SPVTOOLS_LOCAL_PATH:=$(THIRD_PARTY_PATH)/spirv-tools
|
||||
endif
|
||||
ifeq ($(SPVHEADERS_LOCAL_PATH),)
|
||||
# Use the third party dir if it exists.
|
||||
ifneq ($(wildcard $(THIRD_PARTY_PATH)/spirv-headers/include/spirv/spir-v.xml),)
|
||||
SPVHEADERS_LOCAL_PATH:=$(THIRD_PARTY_PATH)/spirv-headers
|
||||
else
|
||||
# Let SPIRV-Tools find its own headers and hope for the best.
|
||||
endif
|
||||
endif
|
||||
|
||||
# Now include the SPIRV-Tools dependency
|
||||
include $(SPVTOOLS_LOCAL_PATH)/Android.mk
|
||||
|
||||
ifeq ($(SHADERC_ENABLE_SPVC),1)
|
||||
# Set the location of SPIRV-Cross.
|
||||
# Allow the user to override it, but default it to under our third_party directory.
|
||||
ifeq ($(SPVCROSS_LOCAL_PATH),)
|
||||
SPVCROSS_LOCAL_PATH:=$(THIRD_PARTY_PATH)/spirv-cross
|
||||
endif
|
||||
|
||||
# Now include the SPIRV-Cross dependency
|
||||
include $(SPVCROSS_LOCAL_PATH)/jni/Android.mk
|
||||
endif
|
||||
168
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/Android.mk
vendored
Normal file
168
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/Android.mk
vendored
Normal file
@ -0,0 +1,168 @@
|
||||
# Copyright (C) 2020 The Khronos Group Inc.
|
||||
#
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following
|
||||
# disclaimer in the documentation and/or other materials provided
|
||||
# with the distribution.
|
||||
#
|
||||
# Neither the name of The Khronos Group Inc. nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
# Generate glslang/build_info.h
|
||||
GLSLANG_GENERATED_INCLUDEDIR:=$(TARGET_OUT)/include
|
||||
GLSLANG_BUILD_INFO_H:=$(GLSLANG_GENERATED_INCLUDEDIR)/glslang/build_info.h
|
||||
|
||||
define gen_glslang_build_info_h
|
||||
$(call generate-file-dir,$(GLSLANG_GENERATED_INCLUDEDIR)/dummy_filename)
|
||||
$(GLSLANG_BUILD_INFO_H): \
|
||||
$(LOCAL_PATH)/build_info.py \
|
||||
$(LOCAL_PATH)/build_info.h.tmpl \
|
||||
$(LOCAL_PATH)/CHANGES.md
|
||||
@$(HOST_PYTHON) $(LOCAL_PATH)/build_info.py \
|
||||
$(LOCAL_PATH) \
|
||||
-i $(LOCAL_PATH)/build_info.h.tmpl \
|
||||
-o $(GLSLANG_BUILD_INFO_H)
|
||||
@echo "[$(TARGET_ARCH_ABI)] Generate : $(GLSLANG_BUILD_INFO_H) <= CHANGES.md"
|
||||
endef
|
||||
$(eval $(call gen_glslang_build_info_h))
|
||||
|
||||
GLSLANG_OS_FLAGS := -DGLSLANG_OSINCLUDE_UNIX
|
||||
# AMD and NV extensions are turned on by default in upstream Glslang.
|
||||
GLSLANG_DEFINES:= -DAMD_EXTENSIONS -DNV_EXTENSIONS -DENABLE_HLSL $(GLSLANG_OS_FLAGS)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE:=OSDependent
|
||||
LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti $(GLSLANG_DEFINES)
|
||||
LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)
|
||||
LOCAL_SRC_FILES:=glslang/OSDependent/Unix/ossource.cpp
|
||||
LOCAL_C_INCLUDES:=$(LOCAL_PATH) $(LOCAL_PATH)/glslang/OSDependent/Unix/
|
||||
LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)/glslang/OSDependent/Unix/
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE:=OGLCompiler
|
||||
LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti $(GLSLANG_DEFINES)
|
||||
LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)
|
||||
LOCAL_SRC_FILES:=OGLCompilersDLL/InitializeDll.cpp
|
||||
LOCAL_C_INCLUDES:=$(LOCAL_PATH)/OGLCompiler
|
||||
LOCAL_STATIC_LIBRARIES:=OSDependent
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
# Build the stubbed HLSL library.
|
||||
# The HLSL source is now directly referenced by the glslang static library
|
||||
# instead.
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE:=HLSL
|
||||
LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti $(GLSLANG_DEFINES)
|
||||
LOCAL_SRC_FILES:= \
|
||||
hlsl/stub.cpp
|
||||
LOCAL_C_INCLUDES:=$(LOCAL_PATH) \
|
||||
$(LOCAL_PATH)/glslang/HLSL
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
GLSLANG_OUT_PATH=$(if $(call host-path-is-absolute,$(TARGET_OUT)),$(TARGET_OUT),$(abspath $(TARGET_OUT)))
|
||||
|
||||
# ShaderLang.cpp depends on the generated build_info.h
|
||||
$(LOCAL_PATH)/glslang/MachineIndependent/ShaderLang.cpp: \
|
||||
$(GLSLANG_BUILD_INFO_H)
|
||||
|
||||
LOCAL_MODULE:=glslang
|
||||
LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti $(GLSLANG_DEFINES)
|
||||
LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)
|
||||
LOCAL_SRC_FILES:= \
|
||||
glslang/CInterface/glslang_c_interface.cpp \
|
||||
glslang/GenericCodeGen/CodeGen.cpp \
|
||||
glslang/GenericCodeGen/Link.cpp \
|
||||
glslang/HLSL/hlslAttributes.cpp \
|
||||
glslang/HLSL/hlslGrammar.cpp \
|
||||
glslang/HLSL/hlslOpMap.cpp \
|
||||
glslang/HLSL/hlslParseables.cpp \
|
||||
glslang/HLSL/hlslParseHelper.cpp \
|
||||
glslang/HLSL/hlslScanContext.cpp \
|
||||
glslang/HLSL/hlslTokenStream.cpp \
|
||||
glslang/MachineIndependent/attribute.cpp \
|
||||
glslang/MachineIndependent/Constant.cpp \
|
||||
glslang/MachineIndependent/glslang_tab.cpp \
|
||||
glslang/MachineIndependent/InfoSink.cpp \
|
||||
glslang/MachineIndependent/Initialize.cpp \
|
||||
glslang/MachineIndependent/Intermediate.cpp \
|
||||
glslang/MachineIndependent/intermOut.cpp \
|
||||
glslang/MachineIndependent/IntermTraverse.cpp \
|
||||
glslang/MachineIndependent/iomapper.cpp \
|
||||
glslang/MachineIndependent/limits.cpp \
|
||||
glslang/MachineIndependent/linkValidate.cpp \
|
||||
glslang/MachineIndependent/parseConst.cpp \
|
||||
glslang/MachineIndependent/ParseContextBase.cpp \
|
||||
glslang/MachineIndependent/ParseHelper.cpp \
|
||||
glslang/MachineIndependent/PoolAlloc.cpp \
|
||||
glslang/MachineIndependent/propagateNoContraction.cpp \
|
||||
glslang/MachineIndependent/reflection.cpp \
|
||||
glslang/MachineIndependent/RemoveTree.cpp \
|
||||
glslang/MachineIndependent/Scan.cpp \
|
||||
glslang/MachineIndependent/ShaderLang.cpp \
|
||||
glslang/MachineIndependent/SpirvIntrinsics.cpp \
|
||||
glslang/MachineIndependent/SymbolTable.cpp \
|
||||
glslang/MachineIndependent/Versions.cpp \
|
||||
glslang/MachineIndependent/preprocessor/PpAtom.cpp \
|
||||
glslang/MachineIndependent/preprocessor/PpContext.cpp \
|
||||
glslang/MachineIndependent/preprocessor/Pp.cpp \
|
||||
glslang/MachineIndependent/preprocessor/PpScanner.cpp \
|
||||
glslang/MachineIndependent/preprocessor/PpTokens.cpp
|
||||
LOCAL_C_INCLUDES:=$(LOCAL_PATH) \
|
||||
$(LOCAL_PATH)/glslang/MachineIndependent \
|
||||
$(GLSLANG_GENERATED_INCLUDEDIR) \
|
||||
$(GLSLANG_OUT_PATH)
|
||||
LOCAL_STATIC_LIBRARIES:=OSDependent OGLCompiler HLSL
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
# GlslangToSpv.cpp depends on the generated build_info.h
|
||||
$(LOCAL_PATH)/SPIRV/GlslangToSpv.cpp: \
|
||||
$(GLSLANG_BUILD_INFO_H)
|
||||
|
||||
LOCAL_MODULE:=SPIRV
|
||||
LOCAL_CXXFLAGS:=-std=c++11 -fno-exceptions -fno-rtti -Werror $(GLSLANG_DEFINES)
|
||||
LOCAL_SRC_FILES:= \
|
||||
SPIRV/CInterface/spirv_c_interface.cpp \
|
||||
SPIRV/GlslangToSpv.cpp \
|
||||
SPIRV/InReadableOrder.cpp \
|
||||
SPIRV/Logger.cpp \
|
||||
SPIRV/SPVRemapper.cpp \
|
||||
SPIRV/SpvBuilder.cpp \
|
||||
SPIRV/SpvPostProcess.cpp \
|
||||
SPIRV/SpvTools.cpp \
|
||||
SPIRV/disassemble.cpp \
|
||||
SPIRV/doc.cpp
|
||||
LOCAL_C_INCLUDES:=$(LOCAL_PATH) \
|
||||
$(LOCAL_PATH)/glslang/SPIRV \
|
||||
$(GLSLANG_GENERATED_INCLUDEDIR)
|
||||
LOCAL_EXPORT_C_INCLUDES:=$(LOCAL_PATH)/glslang/SPIRV
|
||||
LOCAL_STATIC_LIBRARIES:=glslang
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
119
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/CHANGES.md
vendored
Normal file
119
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/CHANGES.md
vendored
Normal file
@ -0,0 +1,119 @@
|
||||
# Revision history for `glslang`
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](https://semver.org/).
|
||||
|
||||
## 11.11.0 2022-08-11
|
||||
|
||||
### Other changes
|
||||
* Add OpSource support to C interface
|
||||
* Deprecate samplerBuffer for spirv1.6 and later
|
||||
* Add support for SPV_AMD_shader_early_and_late_fragment_tests
|
||||
|
||||
## 11.10.0 2022-06-02
|
||||
|
||||
### Other changes
|
||||
* Generate OpLine before OpFunction
|
||||
* Add support for VK_EXT_fragment_shader_barycentric
|
||||
* Add whitelist filtering for debug comments in SPIRV-Remap
|
||||
* Add support for GL_EXT_ray_cull_mask
|
||||
|
||||
## 11.9.0 2022-04-06
|
||||
|
||||
### Other changes
|
||||
* Add GLSL version override functionality
|
||||
* Add eliminate-dead-input-components to -Os
|
||||
* Add enhanced-msgs option
|
||||
* Explicitly use Python 3 for builds
|
||||
|
||||
## 11.8.0 2022-01-27
|
||||
|
||||
### Other changes
|
||||
* Add support for SPIR-V 1.6
|
||||
* Add support for Vulkan 1.3
|
||||
* Add --hlsl-dx-position-w option
|
||||
|
||||
## 11.7.0 2021-11-11
|
||||
|
||||
### Other changes
|
||||
* Add support for targeting Vulkan 1.2 in the C API
|
||||
|
||||
## 11.6.0 2021-08-25
|
||||
|
||||
### Other changes
|
||||
* Atomic memory function only for shader storage block member or shared variable
|
||||
* Add support for gl_MaxVaryingVectors for ogl
|
||||
* Fix loading bool arrays from interface blocks
|
||||
* Generate separate stores for partially swizzled memory stores
|
||||
* Allow layout(std430) uniform with GL_EXT_scalar_block_layout
|
||||
* Support for pragma STDGL invariant(all)
|
||||
* Support for GL_NV_ray_tracing_motion_blur
|
||||
|
||||
## 11.5.0 2021-06-23
|
||||
|
||||
### Other changes
|
||||
* Implement GLSL_EXT_shader_atomic_float2
|
||||
* Implement GL_EXT_spirv_intrinsics
|
||||
* Fixed SPIR-V remapper not remapping OpExtInst instruction set IDs
|
||||
* only declare compatibility gl_ variables in compatibility mode
|
||||
* Add support for float spec const vector initialization
|
||||
* Implement GL_EXT_subgroup_uniform_control_flow.
|
||||
* Fix arrays dimensioned with spec constant sized gl_WorkGroupSize
|
||||
* Add support for 64bit integer scalar and vector types to bitCount() builtin
|
||||
|
||||
## 11.4.0 2021-04-22
|
||||
|
||||
### Other changes
|
||||
* Fix to keep source compatible with CMake 3.10.2
|
||||
|
||||
## 11.3.0 2021-04-21
|
||||
|
||||
### Other changes
|
||||
* Added --depfile
|
||||
* Added --auto-sampled-textures
|
||||
* Now supports InterpolateAt-based functions
|
||||
* Supports cross-stage automatic IO mapping
|
||||
* Supports GL_EXT_vulkan_glsl_relaxed (-R option)
|
||||
|
||||
## 11.2.0 2021-02-18
|
||||
|
||||
### Other changes
|
||||
* Removed Python requirement when not building with spirv-tools
|
||||
* Add support for GL_EXT_shared_memory_block
|
||||
* Implement GL_EXT_null_initializer
|
||||
* Add CMake support for Fuschia
|
||||
|
||||
## 11.1.0 2020-12-07
|
||||
|
||||
### Other changes
|
||||
* Added ray-tracing extension support
|
||||
|
||||
## 11.0.0 2020-07-20
|
||||
|
||||
### Breaking changes
|
||||
|
||||
#### Visual Studio 2013 is no longer supported
|
||||
|
||||
[As scheduled](https://github.com/KhronosGroup/glslang/blob/9eef54b2513ca6b40b47b07d24f453848b65c0df/README.md#planned-deprecationsremovals),
|
||||
Microsoft Visual Studio 2013 is no longer officially supported. Please upgrade
|
||||
to at least Visual Studio 2015.
|
||||
|
||||
## 10.15.3847 2020-07-20
|
||||
|
||||
### Breaking changes
|
||||
|
||||
* The following files have been removed:
|
||||
* `glslang/include/revision.h`
|
||||
* `glslang/include/revision.template`
|
||||
|
||||
The `GLSLANG_MINOR_VERSION` and `GLSLANG_PATCH_LEVEL` defines have been removed
|
||||
from the public headers. \
|
||||
Instead each build script now uses the new `build_info.py`
|
||||
script along with the `build_info.h.tmpl` and this `CHANGES.md` file to generate
|
||||
the glslang build-time generated header `glslang/build_info.h`.
|
||||
|
||||
The new public API to obtain the `glslang` version is `glslang::GetVersion()`.
|
||||
|
||||
### Other changes
|
||||
* `glslang` shared objects produced by CMake are now `SONAME` versioned using
|
||||
[Semantic Versioning 2.0.0](https://semver.org/).
|
||||
@ -0,0 +1,165 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#define SH_EXPORTING
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "InitializeDll.h"
|
||||
#include "../glslang/Include/InitializeGlobals.h"
|
||||
#include "../glslang/Public/ShaderLang.h"
|
||||
#include "../glslang/Include/PoolAlloc.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
OS_TLSIndex ThreadInitializeIndex = OS_INVALID_TLS_INDEX;
|
||||
|
||||
// Per-process initialization.
|
||||
// Needs to be called at least once before parsing, etc. is done.
|
||||
// Will also do thread initialization for the calling thread; other
|
||||
// threads will need to do that explicitly.
|
||||
bool InitProcess()
|
||||
{
|
||||
glslang::GetGlobalLock();
|
||||
|
||||
if (ThreadInitializeIndex != OS_INVALID_TLS_INDEX) {
|
||||
//
|
||||
// Function is re-entrant.
|
||||
//
|
||||
|
||||
glslang::ReleaseGlobalLock();
|
||||
return true;
|
||||
}
|
||||
|
||||
ThreadInitializeIndex = OS_AllocTLSIndex();
|
||||
|
||||
if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX) {
|
||||
assert(0 && "InitProcess(): Failed to allocate TLS area for init flag");
|
||||
|
||||
glslang::ReleaseGlobalLock();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! InitializePoolIndex()) {
|
||||
assert(0 && "InitProcess(): Failed to initialize global pool");
|
||||
|
||||
glslang::ReleaseGlobalLock();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! InitThread()) {
|
||||
assert(0 && "InitProcess(): Failed to initialize thread");
|
||||
|
||||
glslang::ReleaseGlobalLock();
|
||||
return false;
|
||||
}
|
||||
|
||||
glslang::ReleaseGlobalLock();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Per-thread scoped initialization.
|
||||
// Must be called at least once by each new thread sharing the
|
||||
// symbol tables, etc., needed to parse.
|
||||
bool InitThread()
|
||||
{
|
||||
//
|
||||
// This function is re-entrant
|
||||
//
|
||||
if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX) {
|
||||
assert(0 && "InitThread(): Process hasn't been initalised.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (OS_GetTLSValue(ThreadInitializeIndex) != 0)
|
||||
return true;
|
||||
|
||||
if (! OS_SetTLSValue(ThreadInitializeIndex, (void *)1)) {
|
||||
assert(0 && "InitThread(): Unable to set init flag.");
|
||||
return false;
|
||||
}
|
||||
|
||||
glslang::SetThreadPoolAllocator(nullptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Not necessary to call this: InitThread() is reentrant, and the need
|
||||
// to do per thread tear down has been removed.
|
||||
//
|
||||
// This is kept, with memory management removed, to satisfy any exiting
|
||||
// calls to it that rely on it.
|
||||
bool DetachThread()
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX)
|
||||
return true;
|
||||
|
||||
//
|
||||
// Function is re-entrant and this thread may not have been initialized.
|
||||
//
|
||||
if (OS_GetTLSValue(ThreadInitializeIndex) != 0) {
|
||||
if (!OS_SetTLSValue(ThreadInitializeIndex, (void *)0)) {
|
||||
assert(0 && "DetachThread(): Unable to clear init flag.");
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Not necessary to call this: InitProcess() is reentrant.
|
||||
//
|
||||
// This is kept, with memory management removed, to satisfy any exiting
|
||||
// calls to it that rely on it.
|
||||
//
|
||||
// Users of glslang should call shFinalize() or glslang::FinalizeProcess() for
|
||||
// process-scoped memory tear down.
|
||||
bool DetachProcess()
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX)
|
||||
return true;
|
||||
|
||||
success = DetachThread();
|
||||
|
||||
OS_FreeTLSIndex(ThreadInitializeIndex);
|
||||
ThreadInitializeIndex = OS_INVALID_TLS_INDEX;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
} // end namespace glslang
|
||||
@ -0,0 +1,49 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
#ifndef __INITIALIZEDLL_H
|
||||
#define __INITIALIZEDLL_H
|
||||
|
||||
#include "../glslang/OSDependent/osinclude.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
bool InitProcess();
|
||||
bool InitThread();
|
||||
bool DetachThread(); // not called from standalone, perhaps other tools rely on parts of it
|
||||
bool DetachProcess(); // not called from standalone, perhaps other tools rely on parts of it
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // __INITIALIZEDLL_H
|
||||
|
||||
@ -0,0 +1,124 @@
|
||||
/**
|
||||
This code is based on the glslang_c_interface implementation by Viktor Latypov
|
||||
**/
|
||||
|
||||
/**
|
||||
BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2019, Viktor Latypov
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**/
|
||||
|
||||
#include "glslang/Include/glslang_c_interface.h"
|
||||
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "SPIRV/Logger.h"
|
||||
#include "SPIRV/SpvTools.h"
|
||||
|
||||
static_assert(sizeof(glslang_spv_options_t) == sizeof(glslang::SpvOptions), "");
|
||||
|
||||
typedef struct glslang_program_s {
|
||||
glslang::TProgram* program;
|
||||
std::vector<unsigned int> spirv;
|
||||
std::string loggerMessages;
|
||||
} glslang_program_t;
|
||||
|
||||
static EShLanguage c_shader_stage(glslang_stage_t stage)
|
||||
{
|
||||
switch (stage) {
|
||||
case GLSLANG_STAGE_VERTEX:
|
||||
return EShLangVertex;
|
||||
case GLSLANG_STAGE_TESSCONTROL:
|
||||
return EShLangTessControl;
|
||||
case GLSLANG_STAGE_TESSEVALUATION:
|
||||
return EShLangTessEvaluation;
|
||||
case GLSLANG_STAGE_GEOMETRY:
|
||||
return EShLangGeometry;
|
||||
case GLSLANG_STAGE_FRAGMENT:
|
||||
return EShLangFragment;
|
||||
case GLSLANG_STAGE_COMPUTE:
|
||||
return EShLangCompute;
|
||||
case GLSLANG_STAGE_RAYGEN:
|
||||
return EShLangRayGen;
|
||||
case GLSLANG_STAGE_INTERSECT:
|
||||
return EShLangIntersect;
|
||||
case GLSLANG_STAGE_ANYHIT:
|
||||
return EShLangAnyHit;
|
||||
case GLSLANG_STAGE_CLOSESTHIT:
|
||||
return EShLangClosestHit;
|
||||
case GLSLANG_STAGE_MISS:
|
||||
return EShLangMiss;
|
||||
case GLSLANG_STAGE_CALLABLE:
|
||||
return EShLangCallable;
|
||||
case GLSLANG_STAGE_TASK:
|
||||
return EShLangTask;
|
||||
case GLSLANG_STAGE_MESH:
|
||||
return EShLangMesh;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return EShLangCount;
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT void glslang_program_SPIRV_generate(glslang_program_t* program, glslang_stage_t stage)
|
||||
{
|
||||
glslang_spv_options_t spv_options;
|
||||
spv_options.generate_debug_info = false;
|
||||
spv_options.strip_debug_info = false;
|
||||
spv_options.emit_nonsemantic_shader_debug_info = false;
|
||||
spv_options.emit_nonsemantic_shader_debug_source = false;
|
||||
spv_options.disable_optimizer = true;
|
||||
spv_options.optimize_size = false;
|
||||
spv_options.disassemble = false;
|
||||
spv_options.validate = true;
|
||||
|
||||
glslang_program_SPIRV_generate_with_options(program, stage, &spv_options);
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT void glslang_program_SPIRV_generate_with_options(glslang_program_t* program, glslang_stage_t stage, glslang_spv_options_t* spv_options) {
|
||||
spv::SpvBuildLogger logger;
|
||||
|
||||
const glslang::TIntermediate* intermediate = program->program->getIntermediate(c_shader_stage(stage));
|
||||
|
||||
glslang::GlslangToSpv(*intermediate, program->spirv, &logger, reinterpret_cast<glslang::SpvOptions*>(spv_options));
|
||||
|
||||
program->loggerMessages = logger.getAllMessages();
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT size_t glslang_program_SPIRV_get_size(glslang_program_t* program) { return program->spirv.size(); }
|
||||
|
||||
GLSLANG_EXPORT void glslang_program_SPIRV_get(glslang_program_t* program, unsigned int* out)
|
||||
{
|
||||
memcpy(out, program->spirv.data(), program->spirv.size() * sizeof(unsigned int));
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT unsigned int* glslang_program_SPIRV_get_ptr(glslang_program_t* program)
|
||||
{
|
||||
return program->spirv.data();
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT const char* glslang_program_SPIRV_get_messages(glslang_program_t* program)
|
||||
{
|
||||
return program->loggerMessages.empty() ? nullptr : program->loggerMessages.c_str();
|
||||
}
|
||||
108
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/GLSL.ext.AMD.h
vendored
Normal file
108
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/GLSL.ext.AMD.h
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
** Copyright (c) 2014-2016 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
** of this software and/or associated documentation files (the "Materials"),
|
||||
** to deal in the Materials without restriction, including without limitation
|
||||
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
** and/or sell copies of the Materials, and to permit persons to whom the
|
||||
** Materials are furnished to do so, subject to the following conditions:
|
||||
**
|
||||
** The above copyright notice and this permission notice shall be included in
|
||||
** all copies or substantial portions of the Materials.
|
||||
**
|
||||
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
|
||||
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
|
||||
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
|
||||
**
|
||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
** FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
|
||||
** IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
#ifndef GLSLextAMD_H
|
||||
#define GLSLextAMD_H
|
||||
|
||||
static const int GLSLextAMDVersion = 100;
|
||||
static const int GLSLextAMDRevision = 7;
|
||||
|
||||
// SPV_AMD_shader_ballot
|
||||
static const char* const E_SPV_AMD_shader_ballot = "SPV_AMD_shader_ballot";
|
||||
|
||||
enum ShaderBallotAMD {
|
||||
ShaderBallotBadAMD = 0, // Don't use
|
||||
|
||||
SwizzleInvocationsAMD = 1,
|
||||
SwizzleInvocationsMaskedAMD = 2,
|
||||
WriteInvocationAMD = 3,
|
||||
MbcntAMD = 4,
|
||||
|
||||
ShaderBallotCountAMD
|
||||
};
|
||||
|
||||
// SPV_AMD_shader_trinary_minmax
|
||||
static const char* const E_SPV_AMD_shader_trinary_minmax = "SPV_AMD_shader_trinary_minmax";
|
||||
|
||||
enum ShaderTrinaryMinMaxAMD {
|
||||
ShaderTrinaryMinMaxBadAMD = 0, // Don't use
|
||||
|
||||
FMin3AMD = 1,
|
||||
UMin3AMD = 2,
|
||||
SMin3AMD = 3,
|
||||
FMax3AMD = 4,
|
||||
UMax3AMD = 5,
|
||||
SMax3AMD = 6,
|
||||
FMid3AMD = 7,
|
||||
UMid3AMD = 8,
|
||||
SMid3AMD = 9,
|
||||
|
||||
ShaderTrinaryMinMaxCountAMD
|
||||
};
|
||||
|
||||
// SPV_AMD_shader_explicit_vertex_parameter
|
||||
static const char* const E_SPV_AMD_shader_explicit_vertex_parameter = "SPV_AMD_shader_explicit_vertex_parameter";
|
||||
|
||||
enum ShaderExplicitVertexParameterAMD {
|
||||
ShaderExplicitVertexParameterBadAMD = 0, // Don't use
|
||||
|
||||
InterpolateAtVertexAMD = 1,
|
||||
|
||||
ShaderExplicitVertexParameterCountAMD
|
||||
};
|
||||
|
||||
// SPV_AMD_gcn_shader
|
||||
static const char* const E_SPV_AMD_gcn_shader = "SPV_AMD_gcn_shader";
|
||||
|
||||
enum GcnShaderAMD {
|
||||
GcnShaderBadAMD = 0, // Don't use
|
||||
|
||||
CubeFaceIndexAMD = 1,
|
||||
CubeFaceCoordAMD = 2,
|
||||
TimeAMD = 3,
|
||||
|
||||
GcnShaderCountAMD
|
||||
};
|
||||
|
||||
// SPV_AMD_gpu_shader_half_float
|
||||
static const char* const E_SPV_AMD_gpu_shader_half_float = "SPV_AMD_gpu_shader_half_float";
|
||||
|
||||
// SPV_AMD_texture_gather_bias_lod
|
||||
static const char* const E_SPV_AMD_texture_gather_bias_lod = "SPV_AMD_texture_gather_bias_lod";
|
||||
|
||||
// SPV_AMD_gpu_shader_int16
|
||||
static const char* const E_SPV_AMD_gpu_shader_int16 = "SPV_AMD_gpu_shader_int16";
|
||||
|
||||
// SPV_AMD_shader_image_load_store_lod
|
||||
static const char* const E_SPV_AMD_shader_image_load_store_lod = "SPV_AMD_shader_image_load_store_lod";
|
||||
|
||||
// SPV_AMD_shader_fragment_mask
|
||||
static const char* const E_SPV_AMD_shader_fragment_mask = "SPV_AMD_shader_fragment_mask";
|
||||
|
||||
// SPV_AMD_gpu_shader_half_float_fetch
|
||||
static const char* const E_SPV_AMD_gpu_shader_half_float_fetch = "SPV_AMD_gpu_shader_half_float_fetch";
|
||||
|
||||
#endif // #ifndef GLSLextAMD_H
|
||||
44
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/GLSL.ext.EXT.h
vendored
Normal file
44
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/GLSL.ext.EXT.h
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
** Copyright (c) 2014-2016 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
** of this software and/or associated documentation files (the "Materials"),
|
||||
** to deal in the Materials without restriction, including without limitation
|
||||
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
** and/or sell copies of the Materials, and to permit persons to whom the
|
||||
** Materials are furnished to do so, subject to the following conditions:
|
||||
**
|
||||
** The above copyright notice and this permission notice shall be included in
|
||||
** all copies or substantial portions of the Materials.
|
||||
**
|
||||
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
|
||||
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
|
||||
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
|
||||
**
|
||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
** FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
|
||||
** IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
#ifndef GLSLextEXT_H
|
||||
#define GLSLextEXT_H
|
||||
|
||||
static const int GLSLextEXTVersion = 100;
|
||||
static const int GLSLextEXTRevision = 2;
|
||||
|
||||
static const char* const E_SPV_EXT_shader_stencil_export = "SPV_EXT_shader_stencil_export";
|
||||
static const char* const E_SPV_EXT_shader_viewport_index_layer = "SPV_EXT_shader_viewport_index_layer";
|
||||
static const char* const E_SPV_EXT_fragment_fully_covered = "SPV_EXT_fragment_fully_covered";
|
||||
static const char* const E_SPV_EXT_fragment_invocation_density = "SPV_EXT_fragment_invocation_density";
|
||||
static const char* const E_SPV_EXT_demote_to_helper_invocation = "SPV_EXT_demote_to_helper_invocation";
|
||||
static const char* const E_SPV_EXT_shader_atomic_float_add = "SPV_EXT_shader_atomic_float_add";
|
||||
static const char* const E_SPV_EXT_shader_atomic_float16_add = "SPV_EXT_shader_atomic_float16_add";
|
||||
static const char* const E_SPV_EXT_shader_atomic_float_min_max = "SPV_EXT_shader_atomic_float_min_max";
|
||||
static const char* const E_SPV_EXT_shader_image_int64 = "SPV_EXT_shader_image_int64";
|
||||
static const char* const E_SPV_EXT_mesh_shader = "SPV_EXT_mesh_shader";
|
||||
|
||||
#endif // #ifndef GLSLextEXT_H
|
||||
58
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/GLSL.ext.KHR.h
vendored
Normal file
58
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/GLSL.ext.KHR.h
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
** Copyright (c) 2014-2020 The Khronos Group Inc.
|
||||
** Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
** of this software and/or associated documentation files (the "Materials"),
|
||||
** to deal in the Materials without restriction, including without limitation
|
||||
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
** and/or sell copies of the Materials, and to permit persons to whom the
|
||||
** Materials are furnished to do so, subject to the following conditions:
|
||||
**
|
||||
** The above copyright notice and this permission notice shall be included in
|
||||
** all copies or substantial portions of the Materials.
|
||||
**
|
||||
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
|
||||
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
|
||||
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
|
||||
**
|
||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
** FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
|
||||
** IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
#ifndef GLSLextKHR_H
|
||||
#define GLSLextKHR_H
|
||||
|
||||
static const int GLSLextKHRVersion = 100;
|
||||
static const int GLSLextKHRRevision = 3;
|
||||
|
||||
static const char* const E_SPV_KHR_shader_ballot = "SPV_KHR_shader_ballot";
|
||||
static const char* const E_SPV_KHR_subgroup_vote = "SPV_KHR_subgroup_vote";
|
||||
static const char* const E_SPV_KHR_device_group = "SPV_KHR_device_group";
|
||||
static const char* const E_SPV_KHR_multiview = "SPV_KHR_multiview";
|
||||
static const char* const E_SPV_KHR_shader_draw_parameters = "SPV_KHR_shader_draw_parameters";
|
||||
static const char* const E_SPV_KHR_16bit_storage = "SPV_KHR_16bit_storage";
|
||||
static const char* const E_SPV_KHR_8bit_storage = "SPV_KHR_8bit_storage";
|
||||
static const char* const E_SPV_KHR_storage_buffer_storage_class = "SPV_KHR_storage_buffer_storage_class";
|
||||
static const char* const E_SPV_KHR_post_depth_coverage = "SPV_KHR_post_depth_coverage";
|
||||
static const char* const E_SPV_KHR_vulkan_memory_model = "SPV_KHR_vulkan_memory_model";
|
||||
static const char* const E_SPV_EXT_physical_storage_buffer = "SPV_EXT_physical_storage_buffer";
|
||||
static const char* const E_SPV_KHR_physical_storage_buffer = "SPV_KHR_physical_storage_buffer";
|
||||
static const char* const E_SPV_EXT_fragment_shader_interlock = "SPV_EXT_fragment_shader_interlock";
|
||||
static const char* const E_SPV_KHR_shader_clock = "SPV_KHR_shader_clock";
|
||||
static const char* const E_SPV_KHR_non_semantic_info = "SPV_KHR_non_semantic_info";
|
||||
static const char* const E_SPV_KHR_ray_tracing = "SPV_KHR_ray_tracing";
|
||||
static const char* const E_SPV_KHR_ray_query = "SPV_KHR_ray_query";
|
||||
static const char* const E_SPV_KHR_fragment_shading_rate = "SPV_KHR_fragment_shading_rate";
|
||||
static const char* const E_SPV_KHR_terminate_invocation = "SPV_KHR_terminate_invocation";
|
||||
static const char* const E_SPV_KHR_workgroup_memory_explicit_layout = "SPV_KHR_workgroup_memory_explicit_layout";
|
||||
static const char* const E_SPV_KHR_subgroup_uniform_control_flow = "SPV_KHR_subgroup_uniform_control_flow";
|
||||
static const char* const E_SPV_KHR_fragment_shader_barycentric = "SPV_KHR_fragment_shader_barycentric";
|
||||
static const char* const E_SPV_AMD_shader_early_and_late_fragment_tests = "SPV_AMD_shader_early_and_late_fragment_tests";
|
||||
|
||||
#endif // #ifndef GLSLextKHR_H
|
||||
84
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/GLSL.ext.NV.h
vendored
Normal file
84
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/GLSL.ext.NV.h
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
** Copyright (c) 2014-2017 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
** of this software and/or associated documentation files (the "Materials"),
|
||||
** to deal in the Materials without restriction, including without limitation
|
||||
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
** and/or sell copies of the Materials, and to permit persons to whom the
|
||||
** Materials are furnished to do so, subject to the following conditions:
|
||||
**
|
||||
** The above copyright notice and this permission notice shall be included in
|
||||
** all copies or substantial portions of the Materials.
|
||||
**
|
||||
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
|
||||
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
|
||||
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
|
||||
**
|
||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
** FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
|
||||
** IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
#ifndef GLSLextNV_H
|
||||
#define GLSLextNV_H
|
||||
|
||||
enum BuiltIn;
|
||||
enum Decoration;
|
||||
enum Op;
|
||||
enum Capability;
|
||||
|
||||
static const int GLSLextNVVersion = 100;
|
||||
static const int GLSLextNVRevision = 11;
|
||||
|
||||
//SPV_NV_sample_mask_override_coverage
|
||||
const char* const E_SPV_NV_sample_mask_override_coverage = "SPV_NV_sample_mask_override_coverage";
|
||||
|
||||
//SPV_NV_geometry_shader_passthrough
|
||||
const char* const E_SPV_NV_geometry_shader_passthrough = "SPV_NV_geometry_shader_passthrough";
|
||||
|
||||
//SPV_NV_viewport_array2
|
||||
const char* const E_SPV_NV_viewport_array2 = "SPV_NV_viewport_array2";
|
||||
const char* const E_ARB_shader_viewport_layer_array = "SPV_ARB_shader_viewport_layer_array";
|
||||
|
||||
//SPV_NV_stereo_view_rendering
|
||||
const char* const E_SPV_NV_stereo_view_rendering = "SPV_NV_stereo_view_rendering";
|
||||
|
||||
//SPV_NVX_multiview_per_view_attributes
|
||||
const char* const E_SPV_NVX_multiview_per_view_attributes = "SPV_NVX_multiview_per_view_attributes";
|
||||
|
||||
//SPV_NV_shader_subgroup_partitioned
|
||||
const char* const E_SPV_NV_shader_subgroup_partitioned = "SPV_NV_shader_subgroup_partitioned";
|
||||
|
||||
//SPV_NV_fragment_shader_barycentric
|
||||
const char* const E_SPV_NV_fragment_shader_barycentric = "SPV_NV_fragment_shader_barycentric";
|
||||
|
||||
//SPV_NV_compute_shader_derivatives
|
||||
const char* const E_SPV_NV_compute_shader_derivatives = "SPV_NV_compute_shader_derivatives";
|
||||
|
||||
//SPV_NV_shader_image_footprint
|
||||
const char* const E_SPV_NV_shader_image_footprint = "SPV_NV_shader_image_footprint";
|
||||
|
||||
//SPV_NV_mesh_shader
|
||||
const char* const E_SPV_NV_mesh_shader = "SPV_NV_mesh_shader";
|
||||
|
||||
//SPV_NV_raytracing
|
||||
const char* const E_SPV_NV_ray_tracing = "SPV_NV_ray_tracing";
|
||||
|
||||
//SPV_NV_ray_tracing_motion_blur
|
||||
const char* const E_SPV_NV_ray_tracing_motion_blur = "SPV_NV_ray_tracing_motion_blur";
|
||||
|
||||
//SPV_NV_shading_rate
|
||||
const char* const E_SPV_NV_shading_rate = "SPV_NV_shading_rate";
|
||||
|
||||
//SPV_NV_cooperative_matrix
|
||||
const char* const E_SPV_NV_cooperative_matrix = "SPV_NV_cooperative_matrix";
|
||||
|
||||
//SPV_NV_shader_sm_builtins
|
||||
const char* const E_SPV_NV_shader_sm_builtins = "SPV_NV_shader_sm_builtins";
|
||||
|
||||
#endif // #ifndef GLSLextNV_H
|
||||
131
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/GLSL.std.450.h
vendored
Normal file
131
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/GLSL.std.450.h
vendored
Normal file
@ -0,0 +1,131 @@
|
||||
/*
|
||||
** Copyright (c) 2014-2016 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
** of this software and/or associated documentation files (the "Materials"),
|
||||
** to deal in the Materials without restriction, including without limitation
|
||||
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
** and/or sell copies of the Materials, and to permit persons to whom the
|
||||
** Materials are furnished to do so, subject to the following conditions:
|
||||
**
|
||||
** The above copyright notice and this permission notice shall be included in
|
||||
** all copies or substantial portions of the Materials.
|
||||
**
|
||||
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
|
||||
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
|
||||
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
|
||||
**
|
||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
** FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
|
||||
** IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
#ifndef GLSLstd450_H
|
||||
#define GLSLstd450_H
|
||||
|
||||
static const int GLSLstd450Version = 100;
|
||||
static const int GLSLstd450Revision = 1;
|
||||
|
||||
enum GLSLstd450 {
|
||||
GLSLstd450Bad = 0, // Don't use
|
||||
|
||||
GLSLstd450Round = 1,
|
||||
GLSLstd450RoundEven = 2,
|
||||
GLSLstd450Trunc = 3,
|
||||
GLSLstd450FAbs = 4,
|
||||
GLSLstd450SAbs = 5,
|
||||
GLSLstd450FSign = 6,
|
||||
GLSLstd450SSign = 7,
|
||||
GLSLstd450Floor = 8,
|
||||
GLSLstd450Ceil = 9,
|
||||
GLSLstd450Fract = 10,
|
||||
|
||||
GLSLstd450Radians = 11,
|
||||
GLSLstd450Degrees = 12,
|
||||
GLSLstd450Sin = 13,
|
||||
GLSLstd450Cos = 14,
|
||||
GLSLstd450Tan = 15,
|
||||
GLSLstd450Asin = 16,
|
||||
GLSLstd450Acos = 17,
|
||||
GLSLstd450Atan = 18,
|
||||
GLSLstd450Sinh = 19,
|
||||
GLSLstd450Cosh = 20,
|
||||
GLSLstd450Tanh = 21,
|
||||
GLSLstd450Asinh = 22,
|
||||
GLSLstd450Acosh = 23,
|
||||
GLSLstd450Atanh = 24,
|
||||
GLSLstd450Atan2 = 25,
|
||||
|
||||
GLSLstd450Pow = 26,
|
||||
GLSLstd450Exp = 27,
|
||||
GLSLstd450Log = 28,
|
||||
GLSLstd450Exp2 = 29,
|
||||
GLSLstd450Log2 = 30,
|
||||
GLSLstd450Sqrt = 31,
|
||||
GLSLstd450InverseSqrt = 32,
|
||||
|
||||
GLSLstd450Determinant = 33,
|
||||
GLSLstd450MatrixInverse = 34,
|
||||
|
||||
GLSLstd450Modf = 35, // second operand needs an OpVariable to write to
|
||||
GLSLstd450ModfStruct = 36, // no OpVariable operand
|
||||
GLSLstd450FMin = 37,
|
||||
GLSLstd450UMin = 38,
|
||||
GLSLstd450SMin = 39,
|
||||
GLSLstd450FMax = 40,
|
||||
GLSLstd450UMax = 41,
|
||||
GLSLstd450SMax = 42,
|
||||
GLSLstd450FClamp = 43,
|
||||
GLSLstd450UClamp = 44,
|
||||
GLSLstd450SClamp = 45,
|
||||
GLSLstd450FMix = 46,
|
||||
GLSLstd450IMix = 47, // Reserved
|
||||
GLSLstd450Step = 48,
|
||||
GLSLstd450SmoothStep = 49,
|
||||
|
||||
GLSLstd450Fma = 50,
|
||||
GLSLstd450Frexp = 51, // second operand needs an OpVariable to write to
|
||||
GLSLstd450FrexpStruct = 52, // no OpVariable operand
|
||||
GLSLstd450Ldexp = 53,
|
||||
|
||||
GLSLstd450PackSnorm4x8 = 54,
|
||||
GLSLstd450PackUnorm4x8 = 55,
|
||||
GLSLstd450PackSnorm2x16 = 56,
|
||||
GLSLstd450PackUnorm2x16 = 57,
|
||||
GLSLstd450PackHalf2x16 = 58,
|
||||
GLSLstd450PackDouble2x32 = 59,
|
||||
GLSLstd450UnpackSnorm2x16 = 60,
|
||||
GLSLstd450UnpackUnorm2x16 = 61,
|
||||
GLSLstd450UnpackHalf2x16 = 62,
|
||||
GLSLstd450UnpackSnorm4x8 = 63,
|
||||
GLSLstd450UnpackUnorm4x8 = 64,
|
||||
GLSLstd450UnpackDouble2x32 = 65,
|
||||
|
||||
GLSLstd450Length = 66,
|
||||
GLSLstd450Distance = 67,
|
||||
GLSLstd450Cross = 68,
|
||||
GLSLstd450Normalize = 69,
|
||||
GLSLstd450FaceForward = 70,
|
||||
GLSLstd450Reflect = 71,
|
||||
GLSLstd450Refract = 72,
|
||||
|
||||
GLSLstd450FindILsb = 73,
|
||||
GLSLstd450FindSMsb = 74,
|
||||
GLSLstd450FindUMsb = 75,
|
||||
|
||||
GLSLstd450InterpolateAtCentroid = 76,
|
||||
GLSLstd450InterpolateAtSample = 77,
|
||||
GLSLstd450InterpolateAtOffset = 78,
|
||||
|
||||
GLSLstd450NMin = 79,
|
||||
GLSLstd450NMax = 80,
|
||||
GLSLstd450NClamp = 81,
|
||||
|
||||
GLSLstd450Count
|
||||
};
|
||||
|
||||
#endif // #ifndef GLSLstd450_H
|
||||
9646
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/GlslangToSpv.cpp
vendored
Normal file
9646
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/GlslangToSpv.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
61
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/GlslangToSpv.h
vendored
Normal file
61
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/GlslangToSpv.h
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
//
|
||||
// Copyright (C) 2014 LunarG, Inc.
|
||||
// Copyright (C) 2015-2018 Google, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1900
|
||||
#pragma warning(disable : 4464) // relative include path contains '..'
|
||||
#endif
|
||||
|
||||
#include "SpvTools.h"
|
||||
#include "glslang/Include/intermediate.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Logger.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
void GetSpirvVersion(std::string&);
|
||||
int GetSpirvGeneratorVersion();
|
||||
void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
||||
SpvOptions* options = nullptr);
|
||||
void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
||||
spv::SpvBuildLogger* logger, SpvOptions* options = nullptr);
|
||||
void OutputSpvBin(const std::vector<unsigned int>& spirv, const char* baseName);
|
||||
void OutputSpvHex(const std::vector<unsigned int>& spirv, const char* baseName, const char* varName);
|
||||
|
||||
}
|
||||
131
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/InReadableOrder.cpp
vendored
Normal file
131
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/InReadableOrder.cpp
vendored
Normal file
@ -0,0 +1,131 @@
|
||||
//
|
||||
// Copyright (C) 2016 Google, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// The SPIR-V spec requires code blocks to appear in an order satisfying the
|
||||
// dominator-tree direction (ie, dominator before the dominated). This is,
|
||||
// actually, easy to achieve: any pre-order CFG traversal algorithm will do it.
|
||||
// Because such algorithms visit a block only after traversing some path to it
|
||||
// from the root, they necessarily visit the block's idom first.
|
||||
//
|
||||
// But not every graph-traversal algorithm outputs blocks in an order that
|
||||
// appears logical to human readers. The problem is that unrelated branches may
|
||||
// be interspersed with each other, and merge blocks may come before some of the
|
||||
// branches being merged.
|
||||
//
|
||||
// A good, human-readable order of blocks may be achieved by performing
|
||||
// depth-first search but delaying merge nodes until after all their branches
|
||||
// have been visited. This is implemented below by the inReadableOrder()
|
||||
// function.
|
||||
|
||||
#include "spvIR.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <unordered_set>
|
||||
|
||||
using spv::Block;
|
||||
using spv::Id;
|
||||
|
||||
namespace {
|
||||
// Traverses CFG in a readable order, invoking a pre-set callback on each block.
|
||||
// Use by calling visit() on the root block.
|
||||
class ReadableOrderTraverser {
|
||||
public:
|
||||
ReadableOrderTraverser(std::function<void(Block*, spv::ReachReason, Block*)> callback)
|
||||
: callback_(callback) {}
|
||||
// Visits the block if it hasn't been visited already and isn't currently
|
||||
// being delayed. Invokes callback(block, why, header), then descends into its
|
||||
// successors. Delays merge-block and continue-block processing until all
|
||||
// the branches have been completed. If |block| is an unreachable merge block or
|
||||
// an unreachable continue target, then |header| is the corresponding header block.
|
||||
void visit(Block* block, spv::ReachReason why, Block* header)
|
||||
{
|
||||
assert(block);
|
||||
if (why == spv::ReachViaControlFlow) {
|
||||
reachableViaControlFlow_.insert(block);
|
||||
}
|
||||
if (visited_.count(block) || delayed_.count(block))
|
||||
return;
|
||||
callback_(block, why, header);
|
||||
visited_.insert(block);
|
||||
Block* mergeBlock = nullptr;
|
||||
Block* continueBlock = nullptr;
|
||||
auto mergeInst = block->getMergeInstruction();
|
||||
if (mergeInst) {
|
||||
Id mergeId = mergeInst->getIdOperand(0);
|
||||
mergeBlock = block->getParent().getParent().getInstruction(mergeId)->getBlock();
|
||||
delayed_.insert(mergeBlock);
|
||||
if (mergeInst->getOpCode() == spv::OpLoopMerge) {
|
||||
Id continueId = mergeInst->getIdOperand(1);
|
||||
continueBlock =
|
||||
block->getParent().getParent().getInstruction(continueId)->getBlock();
|
||||
delayed_.insert(continueBlock);
|
||||
}
|
||||
}
|
||||
if (why == spv::ReachViaControlFlow) {
|
||||
const auto& successors = block->getSuccessors();
|
||||
for (auto it = successors.cbegin(); it != successors.cend(); ++it)
|
||||
visit(*it, why, nullptr);
|
||||
}
|
||||
if (continueBlock) {
|
||||
const spv::ReachReason continueWhy =
|
||||
(reachableViaControlFlow_.count(continueBlock) > 0)
|
||||
? spv::ReachViaControlFlow
|
||||
: spv::ReachDeadContinue;
|
||||
delayed_.erase(continueBlock);
|
||||
visit(continueBlock, continueWhy, block);
|
||||
}
|
||||
if (mergeBlock) {
|
||||
const spv::ReachReason mergeWhy =
|
||||
(reachableViaControlFlow_.count(mergeBlock) > 0)
|
||||
? spv::ReachViaControlFlow
|
||||
: spv::ReachDeadMerge;
|
||||
delayed_.erase(mergeBlock);
|
||||
visit(mergeBlock, mergeWhy, block);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<void(Block*, spv::ReachReason, Block*)> callback_;
|
||||
// Whether a block has already been visited or is being delayed.
|
||||
std::unordered_set<Block *> visited_, delayed_;
|
||||
|
||||
// The set of blocks that actually are reached via control flow.
|
||||
std::unordered_set<Block *> reachableViaControlFlow_;
|
||||
};
|
||||
}
|
||||
|
||||
void spv::inReadableOrder(Block* root, std::function<void(Block*, spv::ReachReason, Block*)> callback)
|
||||
{
|
||||
ReadableOrderTraverser(callback).visit(root, spv::ReachViaControlFlow, nullptr);
|
||||
}
|
||||
72
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/Logger.cpp
vendored
Normal file
72
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/Logger.cpp
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
//
|
||||
// Copyright (C) 2016 Google, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GLSLANG_WEB
|
||||
|
||||
#include "Logger.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
|
||||
namespace spv {
|
||||
|
||||
void SpvBuildLogger::tbdFunctionality(const std::string& f)
|
||||
{
|
||||
if (std::find(std::begin(tbdFeatures), std::end(tbdFeatures), f) == std::end(tbdFeatures))
|
||||
tbdFeatures.push_back(f);
|
||||
}
|
||||
|
||||
void SpvBuildLogger::missingFunctionality(const std::string& f)
|
||||
{
|
||||
if (std::find(std::begin(missingFeatures), std::end(missingFeatures), f) == std::end(missingFeatures))
|
||||
missingFeatures.push_back(f);
|
||||
}
|
||||
|
||||
std::string SpvBuildLogger::getAllMessages() const {
|
||||
std::ostringstream messages;
|
||||
for (auto it = tbdFeatures.cbegin(); it != tbdFeatures.cend(); ++it)
|
||||
messages << "TBD functionality: " << *it << "\n";
|
||||
for (auto it = missingFeatures.cbegin(); it != missingFeatures.cend(); ++it)
|
||||
messages << "Missing functionality: " << *it << "\n";
|
||||
for (auto it = warnings.cbegin(); it != warnings.cend(); ++it)
|
||||
messages << "warning: " << *it << "\n";
|
||||
for (auto it = errors.cbegin(); it != errors.cend(); ++it)
|
||||
messages << "error: " << *it << "\n";
|
||||
return messages.str();
|
||||
}
|
||||
|
||||
} // end spv namespace
|
||||
|
||||
#endif
|
||||
83
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/Logger.h
vendored
Normal file
83
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/Logger.h
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
//
|
||||
// Copyright (C) 2016 Google, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GLSLANG_SPIRV_LOGGER_H
|
||||
#define GLSLANG_SPIRV_LOGGER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace spv {
|
||||
|
||||
// A class for holding all SPIR-V build status messages, including
|
||||
// missing/TBD functionalities, warnings, and errors.
|
||||
class SpvBuildLogger {
|
||||
public:
|
||||
SpvBuildLogger() {}
|
||||
|
||||
#ifdef GLSLANG_WEB
|
||||
void tbdFunctionality(const std::string& f) { }
|
||||
void missingFunctionality(const std::string& f) { }
|
||||
void warning(const std::string& w) { }
|
||||
void error(const std::string& e) { errors.push_back(e); }
|
||||
std::string getAllMessages() { return ""; }
|
||||
#else
|
||||
|
||||
// Registers a TBD functionality.
|
||||
void tbdFunctionality(const std::string& f);
|
||||
// Registers a missing functionality.
|
||||
void missingFunctionality(const std::string& f);
|
||||
|
||||
// Logs a warning.
|
||||
void warning(const std::string& w) { warnings.push_back(w); }
|
||||
// Logs an error.
|
||||
void error(const std::string& e) { errors.push_back(e); }
|
||||
|
||||
// Returns all messages accumulated in the order of:
|
||||
// TBD functionalities, missing functionalities, warnings, errors.
|
||||
std::string getAllMessages() const;
|
||||
#endif
|
||||
|
||||
private:
|
||||
SpvBuildLogger(const SpvBuildLogger&);
|
||||
|
||||
std::vector<std::string> tbdFeatures;
|
||||
std::vector<std::string> missingFeatures;
|
||||
std::vector<std::string> warnings;
|
||||
std::vector<std::string> errors;
|
||||
};
|
||||
|
||||
} // end spv namespace
|
||||
|
||||
#endif // GLSLANG_SPIRV_LOGGER_H
|
||||
@ -0,0 +1,50 @@
|
||||
// Copyright (c) 2020 The Khronos Group Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and/or associated documentation files (the
|
||||
// "Materials"), to deal in the Materials without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
// permit persons to whom the Materials are furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Materials.
|
||||
//
|
||||
// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
|
||||
// KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
|
||||
// SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
|
||||
// https://www.khronos.org/registry/
|
||||
//
|
||||
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
//
|
||||
|
||||
#ifndef SPIRV_UNIFIED1_NonSemanticDebugPrintf_H_
|
||||
#define SPIRV_UNIFIED1_NonSemanticDebugPrintf_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum {
|
||||
NonSemanticDebugPrintfRevision = 1,
|
||||
NonSemanticDebugPrintfRevision_BitWidthPadding = 0x7fffffff
|
||||
};
|
||||
|
||||
enum NonSemanticDebugPrintfInstructions {
|
||||
NonSemanticDebugPrintfDebugPrintf = 1,
|
||||
NonSemanticDebugPrintfInstructionsMax = 0x7fffffff
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SPIRV_UNIFIED1_NonSemanticDebugPrintf_H_
|
||||
@ -0,0 +1,171 @@
|
||||
// Copyright (c) 2018 The Khronos Group Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and/or associated documentation files (the "Materials"),
|
||||
// to deal in the Materials without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Materials, and to permit persons to whom the
|
||||
// Materials are furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Materials.
|
||||
//
|
||||
// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
|
||||
// STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
|
||||
// HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
|
||||
//
|
||||
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
|
||||
// IN THE MATERIALS.
|
||||
|
||||
#ifndef SPIRV_UNIFIED1_NonSemanticShaderDebugInfo100_H_
|
||||
#define SPIRV_UNIFIED1_NonSemanticShaderDebugInfo100_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum {
|
||||
NonSemanticShaderDebugInfo100Version = 100,
|
||||
NonSemanticShaderDebugInfo100Version_BitWidthPadding = 0x7fffffff
|
||||
};
|
||||
enum {
|
||||
NonSemanticShaderDebugInfo100Revision = 6,
|
||||
NonSemanticShaderDebugInfo100Revision_BitWidthPadding = 0x7fffffff
|
||||
};
|
||||
|
||||
enum NonSemanticShaderDebugInfo100Instructions {
|
||||
NonSemanticShaderDebugInfo100DebugInfoNone = 0,
|
||||
NonSemanticShaderDebugInfo100DebugCompilationUnit = 1,
|
||||
NonSemanticShaderDebugInfo100DebugTypeBasic = 2,
|
||||
NonSemanticShaderDebugInfo100DebugTypePointer = 3,
|
||||
NonSemanticShaderDebugInfo100DebugTypeQualifier = 4,
|
||||
NonSemanticShaderDebugInfo100DebugTypeArray = 5,
|
||||
NonSemanticShaderDebugInfo100DebugTypeVector = 6,
|
||||
NonSemanticShaderDebugInfo100DebugTypedef = 7,
|
||||
NonSemanticShaderDebugInfo100DebugTypeFunction = 8,
|
||||
NonSemanticShaderDebugInfo100DebugTypeEnum = 9,
|
||||
NonSemanticShaderDebugInfo100DebugTypeComposite = 10,
|
||||
NonSemanticShaderDebugInfo100DebugTypeMember = 11,
|
||||
NonSemanticShaderDebugInfo100DebugTypeInheritance = 12,
|
||||
NonSemanticShaderDebugInfo100DebugTypePtrToMember = 13,
|
||||
NonSemanticShaderDebugInfo100DebugTypeTemplate = 14,
|
||||
NonSemanticShaderDebugInfo100DebugTypeTemplateParameter = 15,
|
||||
NonSemanticShaderDebugInfo100DebugTypeTemplateTemplateParameter = 16,
|
||||
NonSemanticShaderDebugInfo100DebugTypeTemplateParameterPack = 17,
|
||||
NonSemanticShaderDebugInfo100DebugGlobalVariable = 18,
|
||||
NonSemanticShaderDebugInfo100DebugFunctionDeclaration = 19,
|
||||
NonSemanticShaderDebugInfo100DebugFunction = 20,
|
||||
NonSemanticShaderDebugInfo100DebugLexicalBlock = 21,
|
||||
NonSemanticShaderDebugInfo100DebugLexicalBlockDiscriminator = 22,
|
||||
NonSemanticShaderDebugInfo100DebugScope = 23,
|
||||
NonSemanticShaderDebugInfo100DebugNoScope = 24,
|
||||
NonSemanticShaderDebugInfo100DebugInlinedAt = 25,
|
||||
NonSemanticShaderDebugInfo100DebugLocalVariable = 26,
|
||||
NonSemanticShaderDebugInfo100DebugInlinedVariable = 27,
|
||||
NonSemanticShaderDebugInfo100DebugDeclare = 28,
|
||||
NonSemanticShaderDebugInfo100DebugValue = 29,
|
||||
NonSemanticShaderDebugInfo100DebugOperation = 30,
|
||||
NonSemanticShaderDebugInfo100DebugExpression = 31,
|
||||
NonSemanticShaderDebugInfo100DebugMacroDef = 32,
|
||||
NonSemanticShaderDebugInfo100DebugMacroUndef = 33,
|
||||
NonSemanticShaderDebugInfo100DebugImportedEntity = 34,
|
||||
NonSemanticShaderDebugInfo100DebugSource = 35,
|
||||
NonSemanticShaderDebugInfo100DebugFunctionDefinition = 101,
|
||||
NonSemanticShaderDebugInfo100DebugSourceContinued = 102,
|
||||
NonSemanticShaderDebugInfo100DebugLine = 103,
|
||||
NonSemanticShaderDebugInfo100DebugNoLine = 104,
|
||||
NonSemanticShaderDebugInfo100DebugBuildIdentifier = 105,
|
||||
NonSemanticShaderDebugInfo100DebugStoragePath = 106,
|
||||
NonSemanticShaderDebugInfo100DebugEntryPoint = 107,
|
||||
NonSemanticShaderDebugInfo100DebugTypeMatrix = 108,
|
||||
NonSemanticShaderDebugInfo100InstructionsMax = 0x7fffffff
|
||||
};
|
||||
|
||||
|
||||
enum NonSemanticShaderDebugInfo100DebugInfoFlags {
|
||||
NonSemanticShaderDebugInfo100None = 0x0000,
|
||||
NonSemanticShaderDebugInfo100FlagIsProtected = 0x01,
|
||||
NonSemanticShaderDebugInfo100FlagIsPrivate = 0x02,
|
||||
NonSemanticShaderDebugInfo100FlagIsPublic = 0x03,
|
||||
NonSemanticShaderDebugInfo100FlagIsLocal = 0x04,
|
||||
NonSemanticShaderDebugInfo100FlagIsDefinition = 0x08,
|
||||
NonSemanticShaderDebugInfo100FlagFwdDecl = 0x10,
|
||||
NonSemanticShaderDebugInfo100FlagArtificial = 0x20,
|
||||
NonSemanticShaderDebugInfo100FlagExplicit = 0x40,
|
||||
NonSemanticShaderDebugInfo100FlagPrototyped = 0x80,
|
||||
NonSemanticShaderDebugInfo100FlagObjectPointer = 0x100,
|
||||
NonSemanticShaderDebugInfo100FlagStaticMember = 0x200,
|
||||
NonSemanticShaderDebugInfo100FlagIndirectVariable = 0x400,
|
||||
NonSemanticShaderDebugInfo100FlagLValueReference = 0x800,
|
||||
NonSemanticShaderDebugInfo100FlagRValueReference = 0x1000,
|
||||
NonSemanticShaderDebugInfo100FlagIsOptimized = 0x2000,
|
||||
NonSemanticShaderDebugInfo100FlagIsEnumClass = 0x4000,
|
||||
NonSemanticShaderDebugInfo100FlagTypePassByValue = 0x8000,
|
||||
NonSemanticShaderDebugInfo100FlagTypePassByReference = 0x10000,
|
||||
NonSemanticShaderDebugInfo100FlagUnknownPhysicalLayout = 0x20000,
|
||||
NonSemanticShaderDebugInfo100DebugInfoFlagsMax = 0x7fffffff
|
||||
};
|
||||
|
||||
enum NonSemanticShaderDebugInfo100BuildIdentifierFlags {
|
||||
NonSemanticShaderDebugInfo100IdentifierPossibleDuplicates = 0x01,
|
||||
NonSemanticShaderDebugInfo100BuildIdentifierFlagsMax = 0x7fffffff
|
||||
};
|
||||
|
||||
enum NonSemanticShaderDebugInfo100DebugBaseTypeAttributeEncoding {
|
||||
NonSemanticShaderDebugInfo100Unspecified = 0,
|
||||
NonSemanticShaderDebugInfo100Address = 1,
|
||||
NonSemanticShaderDebugInfo100Boolean = 2,
|
||||
NonSemanticShaderDebugInfo100Float = 3,
|
||||
NonSemanticShaderDebugInfo100Signed = 4,
|
||||
NonSemanticShaderDebugInfo100SignedChar = 5,
|
||||
NonSemanticShaderDebugInfo100Unsigned = 6,
|
||||
NonSemanticShaderDebugInfo100UnsignedChar = 7,
|
||||
NonSemanticShaderDebugInfo100DebugBaseTypeAttributeEncodingMax = 0x7fffffff
|
||||
};
|
||||
|
||||
enum NonSemanticShaderDebugInfo100DebugCompositeType {
|
||||
NonSemanticShaderDebugInfo100Class = 0,
|
||||
NonSemanticShaderDebugInfo100Structure = 1,
|
||||
NonSemanticShaderDebugInfo100Union = 2,
|
||||
NonSemanticShaderDebugInfo100DebugCompositeTypeMax = 0x7fffffff
|
||||
};
|
||||
|
||||
enum NonSemanticShaderDebugInfo100DebugTypeQualifier {
|
||||
NonSemanticShaderDebugInfo100ConstType = 0,
|
||||
NonSemanticShaderDebugInfo100VolatileType = 1,
|
||||
NonSemanticShaderDebugInfo100RestrictType = 2,
|
||||
NonSemanticShaderDebugInfo100AtomicType = 3,
|
||||
NonSemanticShaderDebugInfo100DebugTypeQualifierMax = 0x7fffffff
|
||||
};
|
||||
|
||||
enum NonSemanticShaderDebugInfo100DebugOperation {
|
||||
NonSemanticShaderDebugInfo100Deref = 0,
|
||||
NonSemanticShaderDebugInfo100Plus = 1,
|
||||
NonSemanticShaderDebugInfo100Minus = 2,
|
||||
NonSemanticShaderDebugInfo100PlusUconst = 3,
|
||||
NonSemanticShaderDebugInfo100BitPiece = 4,
|
||||
NonSemanticShaderDebugInfo100Swap = 5,
|
||||
NonSemanticShaderDebugInfo100Xderef = 6,
|
||||
NonSemanticShaderDebugInfo100StackValue = 7,
|
||||
NonSemanticShaderDebugInfo100Constu = 8,
|
||||
NonSemanticShaderDebugInfo100Fragment = 9,
|
||||
NonSemanticShaderDebugInfo100DebugOperationMax = 0x7fffffff
|
||||
};
|
||||
|
||||
enum NonSemanticShaderDebugInfo100DebugImportedEntity {
|
||||
NonSemanticShaderDebugInfo100ImportedModule = 0,
|
||||
NonSemanticShaderDebugInfo100ImportedDeclaration = 1,
|
||||
NonSemanticShaderDebugInfo100DebugImportedEntityMax = 0x7fffffff
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SPIRV_UNIFIED1_NonSemanticShaderDebugInfo100_H_
|
||||
1532
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/SPVRemapper.cpp
vendored
Normal file
1532
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/SPVRemapper.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
312
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/SPVRemapper.h
vendored
Normal file
312
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/SPVRemapper.h
vendored
Normal file
@ -0,0 +1,312 @@
|
||||
//
|
||||
// Copyright (C) 2015 LunarG, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef SPIRVREMAPPER_H
|
||||
#define SPIRVREMAPPER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
|
||||
namespace spv {
|
||||
|
||||
// MSVC defines __cplusplus as an older value, even when it supports almost all of 11.
|
||||
// We handle that here by making our own symbol.
|
||||
#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1700)
|
||||
# define use_cpp11 1
|
||||
#endif
|
||||
|
||||
class spirvbin_base_t
|
||||
{
|
||||
public:
|
||||
enum Options {
|
||||
NONE = 0,
|
||||
STRIP = (1<<0),
|
||||
MAP_TYPES = (1<<1),
|
||||
MAP_NAMES = (1<<2),
|
||||
MAP_FUNCS = (1<<3),
|
||||
DCE_FUNCS = (1<<4),
|
||||
DCE_VARS = (1<<5),
|
||||
DCE_TYPES = (1<<6),
|
||||
OPT_LOADSTORE = (1<<7),
|
||||
OPT_FWD_LS = (1<<8), // EXPERIMENTAL: PRODUCES INVALID SCHEMA-0 SPIRV
|
||||
MAP_ALL = (MAP_TYPES | MAP_NAMES | MAP_FUNCS),
|
||||
DCE_ALL = (DCE_FUNCS | DCE_VARS | DCE_TYPES),
|
||||
OPT_ALL = (OPT_LOADSTORE),
|
||||
|
||||
ALL_BUT_STRIP = (MAP_ALL | DCE_ALL | OPT_ALL),
|
||||
DO_EVERYTHING = (STRIP | ALL_BUT_STRIP)
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace SPV
|
||||
|
||||
#if !defined (use_cpp11)
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
|
||||
namespace spv {
|
||||
class spirvbin_t : public spirvbin_base_t
|
||||
{
|
||||
public:
|
||||
spirvbin_t(int /*verbose = 0*/) { }
|
||||
|
||||
void remap(std::vector<std::uint32_t>& /*spv*/, unsigned int /*opts = 0*/)
|
||||
{
|
||||
printf("Tool not compiled for C++11, which is required for SPIR-V remapping.\n");
|
||||
exit(5);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace SPV
|
||||
|
||||
#else // defined (use_cpp11)
|
||||
|
||||
#include <functional>
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <cassert>
|
||||
|
||||
#include "spirv.hpp"
|
||||
#include "spvIR.h"
|
||||
|
||||
namespace spv {
|
||||
|
||||
// class to hold SPIR-V binary data for remapping, DCE, and debug stripping
|
||||
class spirvbin_t : public spirvbin_base_t
|
||||
{
|
||||
public:
|
||||
spirvbin_t(int verbose = 0) : entryPoint(spv::NoResult), largestNewId(0), verbose(verbose), errorLatch(false)
|
||||
{ }
|
||||
|
||||
virtual ~spirvbin_t() { }
|
||||
|
||||
// remap on an existing binary in memory
|
||||
void remap(std::vector<std::uint32_t>& spv, const std::vector<std::string>& whiteListStrings,
|
||||
std::uint32_t opts = DO_EVERYTHING);
|
||||
|
||||
// remap on an existing binary in memory - legacy interface without white list
|
||||
void remap(std::vector<std::uint32_t>& spv, std::uint32_t opts = DO_EVERYTHING);
|
||||
|
||||
// Type for error/log handler functions
|
||||
typedef std::function<void(const std::string&)> errorfn_t;
|
||||
typedef std::function<void(const std::string&)> logfn_t;
|
||||
|
||||
// Register error/log handling functions (can be lambda fn / functor / etc)
|
||||
static void registerErrorHandler(errorfn_t handler) { errorHandler = handler; }
|
||||
static void registerLogHandler(logfn_t handler) { logHandler = handler; }
|
||||
|
||||
protected:
|
||||
// This can be overridden to provide other message behavior if needed
|
||||
virtual void msg(int minVerbosity, int indent, const std::string& txt) const;
|
||||
|
||||
private:
|
||||
// Local to global, or global to local ID map
|
||||
typedef std::unordered_map<spv::Id, spv::Id> idmap_t;
|
||||
typedef std::unordered_set<spv::Id> idset_t;
|
||||
typedef std::unordered_map<spv::Id, int> blockmap_t;
|
||||
|
||||
void remap(std::uint32_t opts = DO_EVERYTHING);
|
||||
|
||||
// Map of names to IDs
|
||||
typedef std::unordered_map<std::string, spv::Id> namemap_t;
|
||||
|
||||
typedef std::uint32_t spirword_t;
|
||||
|
||||
typedef std::pair<unsigned, unsigned> range_t;
|
||||
typedef std::function<void(spv::Id&)> idfn_t;
|
||||
typedef std::function<bool(spv::Op, unsigned start)> instfn_t;
|
||||
|
||||
// Special Values for ID map:
|
||||
static const spv::Id unmapped; // unchanged from default value
|
||||
static const spv::Id unused; // unused ID
|
||||
static const int header_size; // SPIR header = 5 words
|
||||
|
||||
class id_iterator_t;
|
||||
|
||||
// For mapping type entries between different shaders
|
||||
typedef std::vector<spirword_t> typeentry_t;
|
||||
typedef std::map<spv::Id, typeentry_t> globaltypes_t;
|
||||
|
||||
// A set that preserves position order, and a reverse map
|
||||
typedef std::set<int> posmap_t;
|
||||
typedef std::unordered_map<spv::Id, int> posmap_rev_t;
|
||||
|
||||
// Maps and ID to the size of its base type, if known.
|
||||
typedef std::unordered_map<spv::Id, unsigned> typesize_map_t;
|
||||
|
||||
// handle error
|
||||
void error(const std::string& txt) const { errorLatch = true; errorHandler(txt); }
|
||||
|
||||
bool isConstOp(spv::Op opCode) const;
|
||||
bool isTypeOp(spv::Op opCode) const;
|
||||
bool isStripOp(spv::Op opCode) const;
|
||||
bool isFlowCtrl(spv::Op opCode) const;
|
||||
range_t literalRange(spv::Op opCode) const;
|
||||
range_t typeRange(spv::Op opCode) const;
|
||||
range_t constRange(spv::Op opCode) const;
|
||||
unsigned typeSizeInWords(spv::Id id) const;
|
||||
unsigned idTypeSizeInWords(spv::Id id) const;
|
||||
|
||||
bool isStripOp(spv::Op opCode, unsigned start) const;
|
||||
|
||||
spv::Id& asId(unsigned word) { return spv[word]; }
|
||||
const spv::Id& asId(unsigned word) const { return spv[word]; }
|
||||
spv::Op asOpCode(unsigned word) const { return opOpCode(spv[word]); }
|
||||
std::uint32_t asOpCodeHash(unsigned word);
|
||||
spv::Decoration asDecoration(unsigned word) const { return spv::Decoration(spv[word]); }
|
||||
unsigned asWordCount(unsigned word) const { return opWordCount(spv[word]); }
|
||||
spv::Id asTypeConstId(unsigned word) const { return asId(word + (isTypeOp(asOpCode(word)) ? 1 : 2)); }
|
||||
unsigned idPos(spv::Id id) const;
|
||||
|
||||
static unsigned opWordCount(spirword_t data) { return data >> spv::WordCountShift; }
|
||||
static spv::Op opOpCode(spirword_t data) { return spv::Op(data & spv::OpCodeMask); }
|
||||
|
||||
// Header access & set methods
|
||||
spirword_t magic() const { return spv[0]; } // return magic number
|
||||
spirword_t bound() const { return spv[3]; } // return Id bound from header
|
||||
spirword_t bound(spirword_t b) { return spv[3] = b; }
|
||||
spirword_t genmagic() const { return spv[2]; } // generator magic
|
||||
spirword_t genmagic(spirword_t m) { return spv[2] = m; }
|
||||
spirword_t schemaNum() const { return spv[4]; } // schema number from header
|
||||
|
||||
// Mapping fns: get
|
||||
spv::Id localId(spv::Id id) const { return idMapL[id]; }
|
||||
|
||||
// Mapping fns: set
|
||||
inline spv::Id localId(spv::Id id, spv::Id newId);
|
||||
void countIds(spv::Id id);
|
||||
|
||||
// Return next unused new local ID.
|
||||
// NOTE: boost::dynamic_bitset would be more efficient due to find_next(),
|
||||
// which std::vector<bool> doens't have.
|
||||
inline spv::Id nextUnusedId(spv::Id id);
|
||||
|
||||
void buildLocalMaps();
|
||||
std::string literalString(unsigned word) const; // Return literal as a std::string
|
||||
int literalStringWords(const std::string& str) const { return (int(str.size())+4)/4; }
|
||||
|
||||
bool isNewIdMapped(spv::Id newId) const { return isMapped(newId); }
|
||||
bool isOldIdUnmapped(spv::Id oldId) const { return localId(oldId) == unmapped; }
|
||||
bool isOldIdUnused(spv::Id oldId) const { return localId(oldId) == unused; }
|
||||
bool isOldIdMapped(spv::Id oldId) const { return !isOldIdUnused(oldId) && !isOldIdUnmapped(oldId); }
|
||||
bool isFunction(spv::Id oldId) const { return fnPos.find(oldId) != fnPos.end(); }
|
||||
|
||||
// bool matchType(const globaltypes_t& globalTypes, spv::Id lt, spv::Id gt) const;
|
||||
// spv::Id findType(const globaltypes_t& globalTypes, spv::Id lt) const;
|
||||
std::uint32_t hashType(unsigned typeStart) const;
|
||||
|
||||
spirvbin_t& process(instfn_t, idfn_t, unsigned begin = 0, unsigned end = 0);
|
||||
int processInstruction(unsigned word, instfn_t, idfn_t);
|
||||
|
||||
void validate() const;
|
||||
void mapTypeConst();
|
||||
void mapFnBodies();
|
||||
void optLoadStore();
|
||||
void dceFuncs();
|
||||
void dceVars();
|
||||
void dceTypes();
|
||||
void mapNames();
|
||||
void foldIds(); // fold IDs to smallest space
|
||||
void forwardLoadStores(); // load store forwarding (EXPERIMENTAL)
|
||||
void offsetIds(); // create relative offset IDs
|
||||
|
||||
void applyMap(); // remap per local name map
|
||||
void mapRemainder(); // map any IDs we haven't touched yet
|
||||
void stripDebug(); // strip all debug info
|
||||
void stripDeadRefs(); // strips debug info for now-dead references after DCE
|
||||
void strip(); // remove debug symbols
|
||||
|
||||
std::vector<spirword_t> spv; // SPIR words
|
||||
|
||||
std::vector<std::string> stripWhiteList;
|
||||
|
||||
namemap_t nameMap; // ID names from OpName
|
||||
|
||||
// Since we want to also do binary ops, we can't use std::vector<bool>. we could use
|
||||
// boost::dynamic_bitset, but we're trying to avoid a boost dependency.
|
||||
typedef std::uint64_t bits_t;
|
||||
std::vector<bits_t> mapped; // which new IDs have been mapped
|
||||
static const int mBits = sizeof(bits_t) * 4;
|
||||
|
||||
bool isMapped(spv::Id id) const { return id < maxMappedId() && ((mapped[id/mBits] & (1LL<<(id%mBits))) != 0); }
|
||||
void setMapped(spv::Id id) { resizeMapped(id); mapped[id/mBits] |= (1LL<<(id%mBits)); }
|
||||
void resizeMapped(spv::Id id) { if (id >= maxMappedId()) mapped.resize(id/mBits+1, 0); }
|
||||
size_t maxMappedId() const { return mapped.size() * mBits; }
|
||||
|
||||
// Add a strip range for a given instruction starting at 'start'
|
||||
// Note: avoiding brace initializers to please older versions os MSVC.
|
||||
void stripInst(unsigned start) { stripRange.push_back(range_t(start, start + asWordCount(start))); }
|
||||
|
||||
// Function start and end. use unordered_map because we'll have
|
||||
// many fewer functions than IDs.
|
||||
std::unordered_map<spv::Id, range_t> fnPos;
|
||||
|
||||
// Which functions are called, anywhere in the module, with a call count
|
||||
std::unordered_map<spv::Id, int> fnCalls;
|
||||
|
||||
posmap_t typeConstPos; // word positions that define types & consts (ordered)
|
||||
posmap_rev_t idPosR; // reverse map from IDs to positions
|
||||
typesize_map_t idTypeSizeMap; // maps each ID to its type size, if known.
|
||||
|
||||
std::vector<spv::Id> idMapL; // ID {M}ap from {L}ocal to {G}lobal IDs
|
||||
|
||||
spv::Id entryPoint; // module entry point
|
||||
spv::Id largestNewId; // biggest new ID we have mapped anything to
|
||||
|
||||
// Sections of the binary to strip, given as [begin,end)
|
||||
std::vector<range_t> stripRange;
|
||||
|
||||
// processing options:
|
||||
std::uint32_t options;
|
||||
int verbose; // verbosity level
|
||||
|
||||
// Error latch: this is set if the error handler is ever executed. It would be better to
|
||||
// use a try/catch block and throw, but that's not desired for certain environments, so
|
||||
// this is the alternative.
|
||||
mutable bool errorLatch;
|
||||
|
||||
static errorfn_t errorHandler;
|
||||
static logfn_t logHandler;
|
||||
};
|
||||
|
||||
} // namespace SPV
|
||||
|
||||
#endif // defined (use_cpp11)
|
||||
#endif // SPIRVREMAPPER_H
|
||||
4036
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/SpvBuilder.cpp
vendored
Normal file
4036
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/SpvBuilder.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
959
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/SpvBuilder.h
vendored
Normal file
959
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/SpvBuilder.h
vendored
Normal file
@ -0,0 +1,959 @@
|
||||
//
|
||||
// Copyright (C) 2014-2015 LunarG, Inc.
|
||||
// Copyright (C) 2015-2020 Google, Inc.
|
||||
// Copyright (C) 2017 ARM Limited.
|
||||
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// "Builder" is an interface to fully build SPIR-V IR. Allocate one of
|
||||
// these to build (a thread safe) internal SPIR-V representation (IR),
|
||||
// and then dump it as a binary stream according to the SPIR-V specification.
|
||||
//
|
||||
// A Builder has a 1:1 relationship with a SPIR-V module.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#ifndef SpvBuilder_H
|
||||
#define SpvBuilder_H
|
||||
|
||||
#include "Logger.h"
|
||||
#include "spirv.hpp"
|
||||
#include "spvIR.h"
|
||||
namespace spv {
|
||||
#include "GLSL.ext.KHR.h"
|
||||
#include "NonSemanticShaderDebugInfo100.h"
|
||||
}
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <stack>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
|
||||
namespace spv {
|
||||
|
||||
typedef enum {
|
||||
Spv_1_0 = (1 << 16),
|
||||
Spv_1_1 = (1 << 16) | (1 << 8),
|
||||
Spv_1_2 = (1 << 16) | (2 << 8),
|
||||
Spv_1_3 = (1 << 16) | (3 << 8),
|
||||
Spv_1_4 = (1 << 16) | (4 << 8),
|
||||
Spv_1_5 = (1 << 16) | (5 << 8),
|
||||
} SpvVersion;
|
||||
|
||||
class Builder {
|
||||
public:
|
||||
Builder(unsigned int spvVersion, unsigned int userNumber, SpvBuildLogger* logger);
|
||||
virtual ~Builder();
|
||||
|
||||
static const int maxMatrixSize = 4;
|
||||
|
||||
unsigned int getSpvVersion() const { return spvVersion; }
|
||||
|
||||
void setSource(spv::SourceLanguage lang, int version)
|
||||
{
|
||||
sourceLang = lang;
|
||||
sourceVersion = version;
|
||||
}
|
||||
spv::Id getStringId(const std::string& str)
|
||||
{
|
||||
auto sItr = stringIds.find(str);
|
||||
if (sItr != stringIds.end())
|
||||
return sItr->second;
|
||||
spv::Id strId = getUniqueId();
|
||||
Instruction* fileString = new Instruction(strId, NoType, OpString);
|
||||
const char* file_c_str = str.c_str();
|
||||
fileString->addStringOperand(file_c_str);
|
||||
strings.push_back(std::unique_ptr<Instruction>(fileString));
|
||||
module.mapInstruction(fileString);
|
||||
stringIds[file_c_str] = strId;
|
||||
return strId;
|
||||
}
|
||||
spv::Id getSourceFile() const
|
||||
{
|
||||
return sourceFileStringId;
|
||||
}
|
||||
void setSourceFile(const std::string& file)
|
||||
{
|
||||
sourceFileStringId = getStringId(file);
|
||||
currentFileId = sourceFileStringId;
|
||||
}
|
||||
void setSourceText(const std::string& text) { sourceText = text; }
|
||||
void addSourceExtension(const char* ext) { sourceExtensions.push_back(ext); }
|
||||
void addModuleProcessed(const std::string& p) { moduleProcesses.push_back(p.c_str()); }
|
||||
void setEmitOpLines() { emitOpLines = true; }
|
||||
void setEmitNonSemanticShaderDebugInfo(bool const emit)
|
||||
{
|
||||
emitNonSemanticShaderDebugInfo = emit;
|
||||
|
||||
if(emit)
|
||||
{
|
||||
importNonSemanticShaderDebugInfoInstructions();
|
||||
}
|
||||
}
|
||||
void setEmitNonSemanticShaderDebugSource(bool const src)
|
||||
{
|
||||
emitNonSemanticShaderDebugSource = src;
|
||||
}
|
||||
void addExtension(const char* ext) { extensions.insert(ext); }
|
||||
void removeExtension(const char* ext)
|
||||
{
|
||||
extensions.erase(ext);
|
||||
}
|
||||
void addIncorporatedExtension(const char* ext, SpvVersion incorporatedVersion)
|
||||
{
|
||||
if (getSpvVersion() < static_cast<unsigned>(incorporatedVersion))
|
||||
addExtension(ext);
|
||||
}
|
||||
void promoteIncorporatedExtension(const char* baseExt, const char* promoExt, SpvVersion incorporatedVersion)
|
||||
{
|
||||
removeExtension(baseExt);
|
||||
addIncorporatedExtension(promoExt, incorporatedVersion);
|
||||
}
|
||||
void addInclude(const std::string& name, const std::string& text)
|
||||
{
|
||||
spv::Id incId = getStringId(name);
|
||||
includeFiles[incId] = &text;
|
||||
}
|
||||
Id import(const char*);
|
||||
void setMemoryModel(spv::AddressingModel addr, spv::MemoryModel mem)
|
||||
{
|
||||
addressModel = addr;
|
||||
memoryModel = mem;
|
||||
}
|
||||
|
||||
void addCapability(spv::Capability cap) { capabilities.insert(cap); }
|
||||
|
||||
// To get a new <id> for anything needing a new one.
|
||||
Id getUniqueId() { return ++uniqueId; }
|
||||
|
||||
// To get a set of new <id>s, e.g., for a set of function parameters
|
||||
Id getUniqueIds(int numIds)
|
||||
{
|
||||
Id id = uniqueId + 1;
|
||||
uniqueId += numIds;
|
||||
return id;
|
||||
}
|
||||
|
||||
// Generate OpLine for non-filename-based #line directives (ie no filename
|
||||
// seen yet): Log the current line, and if different than the last one,
|
||||
// issue a new OpLine using the new line and current source file name.
|
||||
void setLine(int line);
|
||||
|
||||
// If filename null, generate OpLine for non-filename-based line directives,
|
||||
// else do filename-based: Log the current line and file, and if different
|
||||
// than the last one, issue a new OpLine using the new line and file
|
||||
// name.
|
||||
void setLine(int line, const char* filename);
|
||||
// Low-level OpLine. See setLine() for a layered helper.
|
||||
void addLine(Id fileName, int line, int column);
|
||||
void addDebugScopeAndLine(Id fileName, int line, int column);
|
||||
|
||||
// For creating new types (will return old type if the requested one was already made).
|
||||
Id makeVoidType();
|
||||
Id makeBoolType(bool const compilerGenerated = true);
|
||||
Id makePointer(StorageClass, Id pointee);
|
||||
Id makeForwardPointer(StorageClass);
|
||||
Id makePointerFromForwardPointer(StorageClass, Id forwardPointerType, Id pointee);
|
||||
Id makeIntegerType(int width, bool hasSign); // generic
|
||||
Id makeIntType(int width) { return makeIntegerType(width, true); }
|
||||
Id makeUintType(int width) { return makeIntegerType(width, false); }
|
||||
Id makeFloatType(int width);
|
||||
Id makeStructType(const std::vector<Id>& members, const char* name, bool const compilerGenerated = true);
|
||||
Id makeStructResultType(Id type0, Id type1);
|
||||
Id makeVectorType(Id component, int size);
|
||||
Id makeMatrixType(Id component, int cols, int rows);
|
||||
Id makeArrayType(Id element, Id sizeId, int stride); // 0 stride means no stride decoration
|
||||
Id makeRuntimeArray(Id element);
|
||||
Id makeFunctionType(Id returnType, const std::vector<Id>& paramTypes);
|
||||
Id makeImageType(Id sampledType, Dim, bool depth, bool arrayed, bool ms, unsigned sampled, ImageFormat format);
|
||||
Id makeSamplerType();
|
||||
Id makeSampledImageType(Id imageType);
|
||||
Id makeCooperativeMatrixType(Id component, Id scope, Id rows, Id cols);
|
||||
Id makeGenericType(spv::Op opcode, std::vector<spv::IdImmediate>& operands);
|
||||
|
||||
// SPIR-V NonSemantic Shader DebugInfo Instructions
|
||||
struct DebugTypeLoc {
|
||||
std::string name {};
|
||||
int line {0};
|
||||
int column {0};
|
||||
};
|
||||
std::unordered_map<Id, DebugTypeLoc> debugTypeLocs;
|
||||
Id makeDebugInfoNone();
|
||||
Id makeBoolDebugType(int const size);
|
||||
Id makeIntegerDebugType(int const width, bool const hasSign);
|
||||
Id makeFloatDebugType(int const width);
|
||||
Id makeSequentialDebugType(Id const baseType, Id const componentCount, NonSemanticShaderDebugInfo100Instructions const sequenceType);
|
||||
Id makeArrayDebugType(Id const baseType, Id const componentCount);
|
||||
Id makeVectorDebugType(Id const baseType, int const componentCount);
|
||||
Id makeMatrixDebugType(Id const vectorType, int const vectorCount, bool columnMajor = true);
|
||||
Id makeMemberDebugType(Id const memberType, DebugTypeLoc const& debugTypeLoc);
|
||||
Id makeCompositeDebugType(std::vector<Id> const& memberTypes, char const*const name,
|
||||
NonSemanticShaderDebugInfo100DebugCompositeType const tag, bool const isOpaqueType = false);
|
||||
Id makeDebugSource(const Id fileName);
|
||||
Id makeDebugCompilationUnit();
|
||||
Id createDebugGlobalVariable(Id const type, char const*const name, Id const variable);
|
||||
Id createDebugLocalVariable(Id type, char const*const name, size_t const argNumber = 0);
|
||||
Id makeDebugExpression();
|
||||
Id makeDebugDeclare(Id const debugLocalVariable, Id const localVariable);
|
||||
Id makeDebugValue(Id const debugLocalVariable, Id const value);
|
||||
Id makeDebugFunctionType(Id returnType, const std::vector<Id>& paramTypes);
|
||||
Id makeDebugFunction(Function* function, Id nameId, Id funcTypeId);
|
||||
Id makeDebugLexicalBlock(uint32_t line);
|
||||
std::string unmangleFunctionName(std::string const& name) const;
|
||||
|
||||
// accelerationStructureNV type
|
||||
Id makeAccelerationStructureType();
|
||||
// rayQueryEXT type
|
||||
Id makeRayQueryType();
|
||||
|
||||
// For querying about types.
|
||||
Id getTypeId(Id resultId) const { return module.getTypeId(resultId); }
|
||||
Id getDerefTypeId(Id resultId) const;
|
||||
Op getOpCode(Id id) const { return module.getInstruction(id)->getOpCode(); }
|
||||
Op getTypeClass(Id typeId) const { return getOpCode(typeId); }
|
||||
Op getMostBasicTypeClass(Id typeId) const;
|
||||
int getNumComponents(Id resultId) const { return getNumTypeComponents(getTypeId(resultId)); }
|
||||
int getNumTypeConstituents(Id typeId) const;
|
||||
int getNumTypeComponents(Id typeId) const { return getNumTypeConstituents(typeId); }
|
||||
Id getScalarTypeId(Id typeId) const;
|
||||
Id getContainedTypeId(Id typeId) const;
|
||||
Id getContainedTypeId(Id typeId, int) const;
|
||||
StorageClass getTypeStorageClass(Id typeId) const { return module.getStorageClass(typeId); }
|
||||
ImageFormat getImageTypeFormat(Id typeId) const
|
||||
{ return (ImageFormat)module.getInstruction(typeId)->getImmediateOperand(6); }
|
||||
Id getResultingAccessChainType() const;
|
||||
|
||||
bool isPointer(Id resultId) const { return isPointerType(getTypeId(resultId)); }
|
||||
bool isScalar(Id resultId) const { return isScalarType(getTypeId(resultId)); }
|
||||
bool isVector(Id resultId) const { return isVectorType(getTypeId(resultId)); }
|
||||
bool isMatrix(Id resultId) const { return isMatrixType(getTypeId(resultId)); }
|
||||
bool isCooperativeMatrix(Id resultId)const { return isCooperativeMatrixType(getTypeId(resultId)); }
|
||||
bool isAggregate(Id resultId) const { return isAggregateType(getTypeId(resultId)); }
|
||||
bool isSampledImage(Id resultId) const { return isSampledImageType(getTypeId(resultId)); }
|
||||
|
||||
bool isBoolType(Id typeId)
|
||||
{ return groupedTypes[OpTypeBool].size() > 0 && typeId == groupedTypes[OpTypeBool].back()->getResultId(); }
|
||||
bool isIntType(Id typeId) const
|
||||
{ return getTypeClass(typeId) == OpTypeInt && module.getInstruction(typeId)->getImmediateOperand(1) != 0; }
|
||||
bool isUintType(Id typeId) const
|
||||
{ return getTypeClass(typeId) == OpTypeInt && module.getInstruction(typeId)->getImmediateOperand(1) == 0; }
|
||||
bool isFloatType(Id typeId) const { return getTypeClass(typeId) == OpTypeFloat; }
|
||||
bool isPointerType(Id typeId) const { return getTypeClass(typeId) == OpTypePointer; }
|
||||
bool isScalarType(Id typeId) const
|
||||
{ return getTypeClass(typeId) == OpTypeFloat || getTypeClass(typeId) == OpTypeInt ||
|
||||
getTypeClass(typeId) == OpTypeBool; }
|
||||
bool isVectorType(Id typeId) const { return getTypeClass(typeId) == OpTypeVector; }
|
||||
bool isMatrixType(Id typeId) const { return getTypeClass(typeId) == OpTypeMatrix; }
|
||||
bool isStructType(Id typeId) const { return getTypeClass(typeId) == OpTypeStruct; }
|
||||
bool isArrayType(Id typeId) const { return getTypeClass(typeId) == OpTypeArray; }
|
||||
#ifdef GLSLANG_WEB
|
||||
bool isCooperativeMatrixType(Id typeId)const { return false; }
|
||||
#else
|
||||
bool isCooperativeMatrixType(Id typeId)const { return getTypeClass(typeId) == OpTypeCooperativeMatrixNV; }
|
||||
#endif
|
||||
bool isAggregateType(Id typeId) const
|
||||
{ return isArrayType(typeId) || isStructType(typeId) || isCooperativeMatrixType(typeId); }
|
||||
bool isImageType(Id typeId) const { return getTypeClass(typeId) == OpTypeImage; }
|
||||
bool isSamplerType(Id typeId) const { return getTypeClass(typeId) == OpTypeSampler; }
|
||||
bool isSampledImageType(Id typeId) const { return getTypeClass(typeId) == OpTypeSampledImage; }
|
||||
bool containsType(Id typeId, Op typeOp, unsigned int width) const;
|
||||
bool containsPhysicalStorageBufferOrArray(Id typeId) const;
|
||||
|
||||
bool isConstantOpCode(Op opcode) const;
|
||||
bool isSpecConstantOpCode(Op opcode) const;
|
||||
bool isConstant(Id resultId) const { return isConstantOpCode(getOpCode(resultId)); }
|
||||
bool isConstantScalar(Id resultId) const { return getOpCode(resultId) == OpConstant; }
|
||||
bool isSpecConstant(Id resultId) const { return isSpecConstantOpCode(getOpCode(resultId)); }
|
||||
unsigned int getConstantScalar(Id resultId) const
|
||||
{ return module.getInstruction(resultId)->getImmediateOperand(0); }
|
||||
StorageClass getStorageClass(Id resultId) const { return getTypeStorageClass(getTypeId(resultId)); }
|
||||
|
||||
bool isVariableOpCode(Op opcode) const { return opcode == OpVariable; }
|
||||
bool isVariable(Id resultId) const { return isVariableOpCode(getOpCode(resultId)); }
|
||||
bool isGlobalStorage(Id resultId) const { return getStorageClass(resultId) != StorageClassFunction; }
|
||||
bool isGlobalVariable(Id resultId) const { return isVariable(resultId) && isGlobalStorage(resultId); }
|
||||
// See if a resultId is valid for use as an initializer.
|
||||
bool isValidInitializer(Id resultId) const { return isConstant(resultId) || isGlobalVariable(resultId); }
|
||||
|
||||
bool isRayTracingOpCode(Op opcode) const;
|
||||
|
||||
int getScalarTypeWidth(Id typeId) const
|
||||
{
|
||||
Id scalarTypeId = getScalarTypeId(typeId);
|
||||
assert(getTypeClass(scalarTypeId) == OpTypeInt || getTypeClass(scalarTypeId) == OpTypeFloat);
|
||||
return module.getInstruction(scalarTypeId)->getImmediateOperand(0);
|
||||
}
|
||||
|
||||
int getTypeNumColumns(Id typeId) const
|
||||
{
|
||||
assert(isMatrixType(typeId));
|
||||
return getNumTypeConstituents(typeId);
|
||||
}
|
||||
int getNumColumns(Id resultId) const { return getTypeNumColumns(getTypeId(resultId)); }
|
||||
int getTypeNumRows(Id typeId) const
|
||||
{
|
||||
assert(isMatrixType(typeId));
|
||||
return getNumTypeComponents(getContainedTypeId(typeId));
|
||||
}
|
||||
int getNumRows(Id resultId) const { return getTypeNumRows(getTypeId(resultId)); }
|
||||
|
||||
Dim getTypeDimensionality(Id typeId) const
|
||||
{
|
||||
assert(isImageType(typeId));
|
||||
return (Dim)module.getInstruction(typeId)->getImmediateOperand(1);
|
||||
}
|
||||
Id getImageType(Id resultId) const
|
||||
{
|
||||
Id typeId = getTypeId(resultId);
|
||||
assert(isImageType(typeId) || isSampledImageType(typeId));
|
||||
return isSampledImageType(typeId) ? module.getInstruction(typeId)->getIdOperand(0) : typeId;
|
||||
}
|
||||
bool isArrayedImageType(Id typeId) const
|
||||
{
|
||||
assert(isImageType(typeId));
|
||||
return module.getInstruction(typeId)->getImmediateOperand(3) != 0;
|
||||
}
|
||||
|
||||
// For making new constants (will return old constant if the requested one was already made).
|
||||
Id makeNullConstant(Id typeId);
|
||||
Id makeBoolConstant(bool b, bool specConstant = false);
|
||||
Id makeInt8Constant(int i, bool specConstant = false)
|
||||
{ return makeIntConstant(makeIntType(8), (unsigned)i, specConstant); }
|
||||
Id makeUint8Constant(unsigned u, bool specConstant = false)
|
||||
{ return makeIntConstant(makeUintType(8), u, specConstant); }
|
||||
Id makeInt16Constant(int i, bool specConstant = false)
|
||||
{ return makeIntConstant(makeIntType(16), (unsigned)i, specConstant); }
|
||||
Id makeUint16Constant(unsigned u, bool specConstant = false)
|
||||
{ return makeIntConstant(makeUintType(16), u, specConstant); }
|
||||
Id makeIntConstant(int i, bool specConstant = false)
|
||||
{ return makeIntConstant(makeIntType(32), (unsigned)i, specConstant); }
|
||||
Id makeUintConstant(unsigned u, bool specConstant = false)
|
||||
{ return makeIntConstant(makeUintType(32), u, specConstant); }
|
||||
Id makeInt64Constant(long long i, bool specConstant = false)
|
||||
{ return makeInt64Constant(makeIntType(64), (unsigned long long)i, specConstant); }
|
||||
Id makeUint64Constant(unsigned long long u, bool specConstant = false)
|
||||
{ return makeInt64Constant(makeUintType(64), u, specConstant); }
|
||||
Id makeFloatConstant(float f, bool specConstant = false);
|
||||
Id makeDoubleConstant(double d, bool specConstant = false);
|
||||
Id makeFloat16Constant(float f16, bool specConstant = false);
|
||||
Id makeFpConstant(Id type, double d, bool specConstant = false);
|
||||
|
||||
Id importNonSemanticShaderDebugInfoInstructions();
|
||||
|
||||
// Turn the array of constants into a proper spv constant of the requested type.
|
||||
Id makeCompositeConstant(Id type, const std::vector<Id>& comps, bool specConst = false);
|
||||
|
||||
// Methods for adding information outside the CFG.
|
||||
Instruction* addEntryPoint(ExecutionModel, Function*, const char* name);
|
||||
void addExecutionMode(Function*, ExecutionMode mode, int value1 = -1, int value2 = -1, int value3 = -1);
|
||||
void addExecutionMode(Function*, ExecutionMode mode, const std::vector<unsigned>& literals);
|
||||
void addExecutionModeId(Function*, ExecutionMode mode, const std::vector<Id>& operandIds);
|
||||
void addName(Id, const char* name);
|
||||
void addMemberName(Id, int member, const char* name);
|
||||
void addDecoration(Id, Decoration, int num = -1);
|
||||
void addDecoration(Id, Decoration, const char*);
|
||||
void addDecoration(Id, Decoration, const std::vector<unsigned>& literals);
|
||||
void addDecoration(Id, Decoration, const std::vector<const char*>& strings);
|
||||
void addDecorationId(Id id, Decoration, Id idDecoration);
|
||||
void addDecorationId(Id id, Decoration, const std::vector<Id>& operandIds);
|
||||
void addMemberDecoration(Id, unsigned int member, Decoration, int num = -1);
|
||||
void addMemberDecoration(Id, unsigned int member, Decoration, const char*);
|
||||
void addMemberDecoration(Id, unsigned int member, Decoration, const std::vector<unsigned>& literals);
|
||||
void addMemberDecoration(Id, unsigned int member, Decoration, const std::vector<const char*>& strings);
|
||||
|
||||
// At the end of what block do the next create*() instructions go?
|
||||
// Also reset current last DebugScope and current source line to unknown
|
||||
void setBuildPoint(Block* bp) {
|
||||
buildPoint = bp;
|
||||
lastDebugScopeId = NoResult;
|
||||
currentLine = 0;
|
||||
}
|
||||
Block* getBuildPoint() const { return buildPoint; }
|
||||
|
||||
// Make the entry-point function. The returned pointer is only valid
|
||||
// for the lifetime of this builder.
|
||||
Function* makeEntryPoint(const char*);
|
||||
|
||||
// Make a shader-style function, and create its entry block if entry is non-zero.
|
||||
// Return the function, pass back the entry.
|
||||
// The returned pointer is only valid for the lifetime of this builder.
|
||||
Function* makeFunctionEntry(Decoration precision, Id returnType, const char* name,
|
||||
const std::vector<Id>& paramTypes, const std::vector<char const*>& paramNames,
|
||||
const std::vector<std::vector<Decoration>>& precisions, Block **entry = 0);
|
||||
|
||||
// Create a return. An 'implicit' return is one not appearing in the source
|
||||
// code. In the case of an implicit return, no post-return block is inserted.
|
||||
void makeReturn(bool implicit, Id retVal = 0);
|
||||
|
||||
// Initialize state and generate instructions for new lexical scope
|
||||
void enterScope(uint32_t line);
|
||||
|
||||
// Set state and generate instructions to exit current lexical scope
|
||||
void leaveScope();
|
||||
|
||||
// Prepare builder for generation of instructions for a function.
|
||||
void enterFunction(Function const* function);
|
||||
|
||||
// Generate all the code needed to finish up a function.
|
||||
void leaveFunction();
|
||||
|
||||
// Create block terminator instruction for certain statements like
|
||||
// discard, terminate-invocation, terminateRayEXT, or ignoreIntersectionEXT
|
||||
void makeStatementTerminator(spv::Op opcode, const char *name);
|
||||
|
||||
// Create block terminator instruction for statements that have input operands
|
||||
// such as OpEmitMeshTasksEXT
|
||||
void makeStatementTerminator(spv::Op opcode, const std::vector<Id>& operands, const char* name);
|
||||
|
||||
// Create a global or function local or IO variable.
|
||||
Id createVariable(Decoration precision, StorageClass storageClass, Id type, const char* name = nullptr,
|
||||
Id initializer = NoResult, bool const compilerGenerated = true);
|
||||
|
||||
// Create an intermediate with an undefined value.
|
||||
Id createUndefined(Id type);
|
||||
|
||||
// Store into an Id and return the l-value
|
||||
void createStore(Id rValue, Id lValue, spv::MemoryAccessMask memoryAccess = spv::MemoryAccessMaskNone,
|
||||
spv::Scope scope = spv::ScopeMax, unsigned int alignment = 0);
|
||||
|
||||
// Load from an Id and return it
|
||||
Id createLoad(Id lValue, spv::Decoration precision,
|
||||
spv::MemoryAccessMask memoryAccess = spv::MemoryAccessMaskNone,
|
||||
spv::Scope scope = spv::ScopeMax, unsigned int alignment = 0);
|
||||
|
||||
// Create an OpAccessChain instruction
|
||||
Id createAccessChain(StorageClass, Id base, const std::vector<Id>& offsets);
|
||||
|
||||
// Create an OpArrayLength instruction
|
||||
Id createArrayLength(Id base, unsigned int member);
|
||||
|
||||
// Create an OpCooperativeMatrixLengthNV instruction
|
||||
Id createCooperativeMatrixLength(Id type);
|
||||
|
||||
// Create an OpCompositeExtract instruction
|
||||
Id createCompositeExtract(Id composite, Id typeId, unsigned index);
|
||||
Id createCompositeExtract(Id composite, Id typeId, const std::vector<unsigned>& indexes);
|
||||
Id createCompositeInsert(Id object, Id composite, Id typeId, unsigned index);
|
||||
Id createCompositeInsert(Id object, Id composite, Id typeId, const std::vector<unsigned>& indexes);
|
||||
|
||||
Id createVectorExtractDynamic(Id vector, Id typeId, Id componentIndex);
|
||||
Id createVectorInsertDynamic(Id vector, Id typeId, Id component, Id componentIndex);
|
||||
|
||||
void createNoResultOp(Op);
|
||||
void createNoResultOp(Op, Id operand);
|
||||
void createNoResultOp(Op, const std::vector<Id>& operands);
|
||||
void createNoResultOp(Op, const std::vector<IdImmediate>& operands);
|
||||
void createControlBarrier(Scope execution, Scope memory, MemorySemanticsMask);
|
||||
void createMemoryBarrier(unsigned executionScope, unsigned memorySemantics);
|
||||
Id createUnaryOp(Op, Id typeId, Id operand);
|
||||
Id createBinOp(Op, Id typeId, Id operand1, Id operand2);
|
||||
Id createTriOp(Op, Id typeId, Id operand1, Id operand2, Id operand3);
|
||||
Id createOp(Op, Id typeId, const std::vector<Id>& operands);
|
||||
Id createOp(Op, Id typeId, const std::vector<IdImmediate>& operands);
|
||||
Id createFunctionCall(spv::Function*, const std::vector<spv::Id>&);
|
||||
Id createSpecConstantOp(Op, Id typeId, const std::vector<spv::Id>& operands, const std::vector<unsigned>& literals);
|
||||
|
||||
// Take an rvalue (source) and a set of channels to extract from it to
|
||||
// make a new rvalue, which is returned.
|
||||
Id createRvalueSwizzle(Decoration precision, Id typeId, Id source, const std::vector<unsigned>& channels);
|
||||
|
||||
// Take a copy of an lvalue (target) and a source of components, and set the
|
||||
// source components into the lvalue where the 'channels' say to put them.
|
||||
// An updated version of the target is returned.
|
||||
// (No true lvalue or stores are used.)
|
||||
Id createLvalueSwizzle(Id typeId, Id target, Id source, const std::vector<unsigned>& channels);
|
||||
|
||||
// If both the id and precision are valid, the id
|
||||
// gets tagged with the requested precision.
|
||||
// The passed in id is always the returned id, to simplify use patterns.
|
||||
Id setPrecision(Id id, Decoration precision)
|
||||
{
|
||||
if (precision != NoPrecision && id != NoResult)
|
||||
addDecoration(id, precision);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
// Can smear a scalar to a vector for the following forms:
|
||||
// - promoteScalar(scalar, vector) // smear scalar to width of vector
|
||||
// - promoteScalar(vector, scalar) // smear scalar to width of vector
|
||||
// - promoteScalar(pointer, scalar) // smear scalar to width of what pointer points to
|
||||
// - promoteScalar(scalar, scalar) // do nothing
|
||||
// Other forms are not allowed.
|
||||
//
|
||||
// Generally, the type of 'scalar' does not need to be the same type as the components in 'vector'.
|
||||
// The type of the created vector is a vector of components of the same type as the scalar.
|
||||
//
|
||||
// Note: One of the arguments will change, with the result coming back that way rather than
|
||||
// through the return value.
|
||||
void promoteScalar(Decoration precision, Id& left, Id& right);
|
||||
|
||||
// Make a value by smearing the scalar to fill the type.
|
||||
// vectorType should be the correct type for making a vector of scalarVal.
|
||||
// (No conversions are done.)
|
||||
Id smearScalar(Decoration precision, Id scalarVal, Id vectorType);
|
||||
|
||||
// Create a call to a built-in function.
|
||||
Id createBuiltinCall(Id resultType, Id builtins, int entryPoint, const std::vector<Id>& args);
|
||||
|
||||
// List of parameters used to create a texture operation
|
||||
struct TextureParameters {
|
||||
Id sampler;
|
||||
Id coords;
|
||||
Id bias;
|
||||
Id lod;
|
||||
Id Dref;
|
||||
Id offset;
|
||||
Id offsets;
|
||||
Id gradX;
|
||||
Id gradY;
|
||||
Id sample;
|
||||
Id component;
|
||||
Id texelOut;
|
||||
Id lodClamp;
|
||||
Id granularity;
|
||||
Id coarse;
|
||||
bool nonprivate;
|
||||
bool volatil;
|
||||
};
|
||||
|
||||
// Select the correct texture operation based on all inputs, and emit the correct instruction
|
||||
Id createTextureCall(Decoration precision, Id resultType, bool sparse, bool fetch, bool proj, bool gather,
|
||||
bool noImplicit, const TextureParameters&, ImageOperandsMask);
|
||||
|
||||
// Emit the OpTextureQuery* instruction that was passed in.
|
||||
// Figure out the right return value and type, and return it.
|
||||
Id createTextureQueryCall(Op, const TextureParameters&, bool isUnsignedResult);
|
||||
|
||||
Id createSamplePositionCall(Decoration precision, Id, Id);
|
||||
|
||||
Id createBitFieldExtractCall(Decoration precision, Id, Id, Id, bool isSigned);
|
||||
Id createBitFieldInsertCall(Decoration precision, Id, Id, Id, Id);
|
||||
|
||||
// Reduction comparison for composites: For equal and not-equal resulting in a scalar.
|
||||
Id createCompositeCompare(Decoration precision, Id, Id, bool /* true if for equal, false if for not-equal */);
|
||||
|
||||
// OpCompositeConstruct
|
||||
Id createCompositeConstruct(Id typeId, const std::vector<Id>& constituents);
|
||||
|
||||
// vector or scalar constructor
|
||||
Id createConstructor(Decoration precision, const std::vector<Id>& sources, Id resultTypeId);
|
||||
|
||||
// matrix constructor
|
||||
Id createMatrixConstructor(Decoration precision, const std::vector<Id>& sources, Id constructee);
|
||||
|
||||
// Helper to use for building nested control flow with if-then-else.
|
||||
class If {
|
||||
public:
|
||||
If(Id condition, unsigned int ctrl, Builder& builder);
|
||||
~If() {}
|
||||
|
||||
void makeBeginElse();
|
||||
void makeEndIf();
|
||||
|
||||
private:
|
||||
If(const If&);
|
||||
If& operator=(If&);
|
||||
|
||||
Builder& builder;
|
||||
Id condition;
|
||||
unsigned int control;
|
||||
Function* function;
|
||||
Block* headerBlock;
|
||||
Block* thenBlock;
|
||||
Block* elseBlock;
|
||||
Block* mergeBlock;
|
||||
};
|
||||
|
||||
// Make a switch statement. A switch has 'numSegments' of pieces of code, not containing
|
||||
// any case/default labels, all separated by one or more case/default labels. Each possible
|
||||
// case value v is a jump to the caseValues[v] segment. The defaultSegment is also in this
|
||||
// number space. How to compute the value is given by 'condition', as in switch(condition).
|
||||
//
|
||||
// The SPIR-V Builder will maintain the stack of post-switch merge blocks for nested switches.
|
||||
//
|
||||
// Use a defaultSegment < 0 if there is no default segment (to branch to post switch).
|
||||
//
|
||||
// Returns the right set of basic blocks to start each code segment with, so that the caller's
|
||||
// recursion stack can hold the memory for it.
|
||||
//
|
||||
void makeSwitch(Id condition, unsigned int control, int numSegments, const std::vector<int>& caseValues,
|
||||
const std::vector<int>& valueToSegment, int defaultSegment, std::vector<Block*>& segmentBB);
|
||||
|
||||
// Add a branch to the innermost switch's merge block.
|
||||
void addSwitchBreak();
|
||||
|
||||
// Move to the next code segment, passing in the return argument in makeSwitch()
|
||||
void nextSwitchSegment(std::vector<Block*>& segmentBB, int segment);
|
||||
|
||||
// Finish off the innermost switch.
|
||||
void endSwitch(std::vector<Block*>& segmentBB);
|
||||
|
||||
struct LoopBlocks {
|
||||
LoopBlocks(Block& head, Block& body, Block& merge, Block& continue_target) :
|
||||
head(head), body(body), merge(merge), continue_target(continue_target) { }
|
||||
Block &head, &body, &merge, &continue_target;
|
||||
private:
|
||||
LoopBlocks();
|
||||
LoopBlocks& operator=(const LoopBlocks&) = delete;
|
||||
};
|
||||
|
||||
// Start a new loop and prepare the builder to generate code for it. Until
|
||||
// closeLoop() is called for this loop, createLoopContinue() and
|
||||
// createLoopExit() will target its corresponding blocks.
|
||||
LoopBlocks& makeNewLoop();
|
||||
|
||||
// Create a new block in the function containing the build point. Memory is
|
||||
// owned by the function object.
|
||||
Block& makeNewBlock();
|
||||
|
||||
// Add a branch to the continue_target of the current (innermost) loop.
|
||||
void createLoopContinue();
|
||||
|
||||
// Add an exit (e.g. "break") from the innermost loop that we're currently
|
||||
// in.
|
||||
void createLoopExit();
|
||||
|
||||
// Close the innermost loop that you're in
|
||||
void closeLoop();
|
||||
|
||||
//
|
||||
// Access chain design for an R-Value vs. L-Value:
|
||||
//
|
||||
// There is a single access chain the builder is building at
|
||||
// any particular time. Such a chain can be used to either to a load or
|
||||
// a store, when desired.
|
||||
//
|
||||
// Expressions can be r-values, l-values, or both, or only r-values:
|
||||
// a[b.c].d = .... // l-value
|
||||
// ... = a[b.c].d; // r-value, that also looks like an l-value
|
||||
// ++a[b.c].d; // r-value and l-value
|
||||
// (x + y)[2]; // r-value only, can't possibly be l-value
|
||||
//
|
||||
// Computing an r-value means generating code. Hence,
|
||||
// r-values should only be computed when they are needed, not speculatively.
|
||||
//
|
||||
// Computing an l-value means saving away information for later use in the compiler,
|
||||
// no code is generated until the l-value is later dereferenced. It is okay
|
||||
// to speculatively generate an l-value, just not okay to speculatively dereference it.
|
||||
//
|
||||
// The base of the access chain (the left-most variable or expression
|
||||
// from which everything is based) can be set either as an l-value
|
||||
// or as an r-value. Most efficient would be to set an l-value if one
|
||||
// is available. If an expression was evaluated, the resulting r-value
|
||||
// can be set as the chain base.
|
||||
//
|
||||
// The users of this single access chain can save and restore if they
|
||||
// want to nest or manage multiple chains.
|
||||
//
|
||||
|
||||
struct AccessChain {
|
||||
Id base; // for l-values, pointer to the base object, for r-values, the base object
|
||||
std::vector<Id> indexChain;
|
||||
Id instr; // cache the instruction that generates this access chain
|
||||
std::vector<unsigned> swizzle; // each std::vector element selects the next GLSL component number
|
||||
Id component; // a dynamic component index, can coexist with a swizzle,
|
||||
// done after the swizzle, NoResult if not present
|
||||
Id preSwizzleBaseType; // dereferenced type, before swizzle or component is applied;
|
||||
// NoType unless a swizzle or component is present
|
||||
bool isRValue; // true if 'base' is an r-value, otherwise, base is an l-value
|
||||
unsigned int alignment; // bitwise OR of alignment values passed in. Accumulates worst alignment.
|
||||
// Only tracks base and (optional) component selection alignment.
|
||||
|
||||
// Accumulate whether anything in the chain of structures has coherent decorations.
|
||||
struct CoherentFlags {
|
||||
CoherentFlags() { clear(); }
|
||||
#ifdef GLSLANG_WEB
|
||||
void clear() { }
|
||||
bool isVolatile() const { return false; }
|
||||
CoherentFlags operator |=(const CoherentFlags &other) { return *this; }
|
||||
#else
|
||||
bool isVolatile() const { return volatil; }
|
||||
bool isNonUniform() const { return nonUniform; }
|
||||
bool anyCoherent() const {
|
||||
return coherent || devicecoherent || queuefamilycoherent || workgroupcoherent ||
|
||||
subgroupcoherent || shadercallcoherent;
|
||||
}
|
||||
|
||||
unsigned coherent : 1;
|
||||
unsigned devicecoherent : 1;
|
||||
unsigned queuefamilycoherent : 1;
|
||||
unsigned workgroupcoherent : 1;
|
||||
unsigned subgroupcoherent : 1;
|
||||
unsigned shadercallcoherent : 1;
|
||||
unsigned nonprivate : 1;
|
||||
unsigned volatil : 1;
|
||||
unsigned isImage : 1;
|
||||
unsigned nonUniform : 1;
|
||||
|
||||
void clear() {
|
||||
coherent = 0;
|
||||
devicecoherent = 0;
|
||||
queuefamilycoherent = 0;
|
||||
workgroupcoherent = 0;
|
||||
subgroupcoherent = 0;
|
||||
shadercallcoherent = 0;
|
||||
nonprivate = 0;
|
||||
volatil = 0;
|
||||
isImage = 0;
|
||||
nonUniform = 0;
|
||||
}
|
||||
|
||||
CoherentFlags operator |=(const CoherentFlags &other) {
|
||||
coherent |= other.coherent;
|
||||
devicecoherent |= other.devicecoherent;
|
||||
queuefamilycoherent |= other.queuefamilycoherent;
|
||||
workgroupcoherent |= other.workgroupcoherent;
|
||||
subgroupcoherent |= other.subgroupcoherent;
|
||||
shadercallcoherent |= other.shadercallcoherent;
|
||||
nonprivate |= other.nonprivate;
|
||||
volatil |= other.volatil;
|
||||
isImage |= other.isImage;
|
||||
nonUniform |= other.nonUniform;
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
CoherentFlags coherentFlags;
|
||||
};
|
||||
|
||||
//
|
||||
// the SPIR-V builder maintains a single active chain that
|
||||
// the following methods operate on
|
||||
//
|
||||
|
||||
// for external save and restore
|
||||
AccessChain getAccessChain() { return accessChain; }
|
||||
void setAccessChain(AccessChain newChain) { accessChain = newChain; }
|
||||
|
||||
// clear accessChain
|
||||
void clearAccessChain();
|
||||
|
||||
// set new base as an l-value base
|
||||
void setAccessChainLValue(Id lValue)
|
||||
{
|
||||
assert(isPointer(lValue));
|
||||
accessChain.base = lValue;
|
||||
}
|
||||
|
||||
// set new base value as an r-value
|
||||
void setAccessChainRValue(Id rValue)
|
||||
{
|
||||
accessChain.isRValue = true;
|
||||
accessChain.base = rValue;
|
||||
}
|
||||
|
||||
// push offset onto the end of the chain
|
||||
void accessChainPush(Id offset, AccessChain::CoherentFlags coherentFlags, unsigned int alignment)
|
||||
{
|
||||
accessChain.indexChain.push_back(offset);
|
||||
accessChain.coherentFlags |= coherentFlags;
|
||||
accessChain.alignment |= alignment;
|
||||
}
|
||||
|
||||
// push new swizzle onto the end of any existing swizzle, merging into a single swizzle
|
||||
void accessChainPushSwizzle(std::vector<unsigned>& swizzle, Id preSwizzleBaseType,
|
||||
AccessChain::CoherentFlags coherentFlags, unsigned int alignment);
|
||||
|
||||
// push a dynamic component selection onto the access chain, only applicable with a
|
||||
// non-trivial swizzle or no swizzle
|
||||
void accessChainPushComponent(Id component, Id preSwizzleBaseType, AccessChain::CoherentFlags coherentFlags,
|
||||
unsigned int alignment)
|
||||
{
|
||||
if (accessChain.swizzle.size() != 1) {
|
||||
accessChain.component = component;
|
||||
if (accessChain.preSwizzleBaseType == NoType)
|
||||
accessChain.preSwizzleBaseType = preSwizzleBaseType;
|
||||
}
|
||||
accessChain.coherentFlags |= coherentFlags;
|
||||
accessChain.alignment |= alignment;
|
||||
}
|
||||
|
||||
// use accessChain and swizzle to store value
|
||||
void accessChainStore(Id rvalue, Decoration nonUniform,
|
||||
spv::MemoryAccessMask memoryAccess = spv::MemoryAccessMaskNone,
|
||||
spv::Scope scope = spv::ScopeMax, unsigned int alignment = 0);
|
||||
|
||||
// use accessChain and swizzle to load an r-value
|
||||
Id accessChainLoad(Decoration precision, Decoration l_nonUniform, Decoration r_nonUniform, Id ResultType,
|
||||
spv::MemoryAccessMask memoryAccess = spv::MemoryAccessMaskNone, spv::Scope scope = spv::ScopeMax,
|
||||
unsigned int alignment = 0);
|
||||
|
||||
// Return whether or not the access chain can be represented in SPIR-V
|
||||
// as an l-value.
|
||||
// E.g., a[3].yx cannot be, while a[3].y and a[3].y[x] can be.
|
||||
bool isSpvLvalue() const { return accessChain.swizzle.size() <= 1; }
|
||||
|
||||
// get the direct pointer for an l-value
|
||||
Id accessChainGetLValue();
|
||||
|
||||
// Get the inferred SPIR-V type of the result of the current access chain,
|
||||
// based on the type of the base and the chain of dereferences.
|
||||
Id accessChainGetInferredType();
|
||||
|
||||
// Add capabilities, extensions, remove unneeded decorations, etc.,
|
||||
// based on the resulting SPIR-V.
|
||||
void postProcess();
|
||||
|
||||
// Prune unreachable blocks in the CFG and remove unneeded decorations.
|
||||
void postProcessCFG();
|
||||
|
||||
#ifndef GLSLANG_WEB
|
||||
// Add capabilities, extensions based on instructions in the module.
|
||||
void postProcessFeatures();
|
||||
// Hook to visit each instruction in a block in a function
|
||||
void postProcess(Instruction&);
|
||||
// Hook to visit each non-32-bit sized float/int operation in a block.
|
||||
void postProcessType(const Instruction&, spv::Id typeId);
|
||||
#endif
|
||||
|
||||
void dump(std::vector<unsigned int>&) const;
|
||||
|
||||
void createBranch(Block* block);
|
||||
void createConditionalBranch(Id condition, Block* thenBlock, Block* elseBlock);
|
||||
void createLoopMerge(Block* mergeBlock, Block* continueBlock, unsigned int control,
|
||||
const std::vector<unsigned int>& operands);
|
||||
|
||||
// Sets to generate opcode for specialization constants.
|
||||
void setToSpecConstCodeGenMode() { generatingOpCodeForSpecConst = true; }
|
||||
// Sets to generate opcode for non-specialization constants (normal mode).
|
||||
void setToNormalCodeGenMode() { generatingOpCodeForSpecConst = false; }
|
||||
// Check if the builder is generating code for spec constants.
|
||||
bool isInSpecConstCodeGenMode() { return generatingOpCodeForSpecConst; }
|
||||
|
||||
protected:
|
||||
Id makeIntConstant(Id typeId, unsigned value, bool specConstant);
|
||||
Id makeInt64Constant(Id typeId, unsigned long long value, bool specConstant);
|
||||
Id findScalarConstant(Op typeClass, Op opcode, Id typeId, unsigned value);
|
||||
Id findScalarConstant(Op typeClass, Op opcode, Id typeId, unsigned v1, unsigned v2);
|
||||
Id findCompositeConstant(Op typeClass, Id typeId, const std::vector<Id>& comps);
|
||||
Id findStructConstant(Id typeId, const std::vector<Id>& comps);
|
||||
Id collapseAccessChain();
|
||||
void remapDynamicSwizzle();
|
||||
void transferAccessChainSwizzle(bool dynamic);
|
||||
void simplifyAccessChainSwizzle();
|
||||
void createAndSetNoPredecessorBlock(const char*);
|
||||
void createSelectionMerge(Block* mergeBlock, unsigned int control);
|
||||
void dumpSourceInstructions(std::vector<unsigned int>&) const;
|
||||
void dumpSourceInstructions(const spv::Id fileId, const std::string& text, std::vector<unsigned int>&) const;
|
||||
void dumpInstructions(std::vector<unsigned int>&, const std::vector<std::unique_ptr<Instruction> >&) const;
|
||||
void dumpModuleProcesses(std::vector<unsigned int>&) const;
|
||||
spv::MemoryAccessMask sanitizeMemoryAccessForStorageClass(spv::MemoryAccessMask memoryAccess, StorageClass sc)
|
||||
const;
|
||||
|
||||
unsigned int spvVersion; // the version of SPIR-V to emit in the header
|
||||
SourceLanguage sourceLang;
|
||||
int sourceVersion;
|
||||
spv::Id sourceFileStringId;
|
||||
spv::Id nonSemanticShaderCompilationUnitId {0};
|
||||
spv::Id nonSemanticShaderDebugInfo {0};
|
||||
spv::Id debugInfoNone {0};
|
||||
spv::Id debugExpression {0}; // Debug expression with zero operations.
|
||||
std::string sourceText;
|
||||
int currentLine;
|
||||
const char* currentFile;
|
||||
spv::Id currentFileId;
|
||||
std::stack<spv::Id> currentDebugScopeId;
|
||||
spv::Id lastDebugScopeId;
|
||||
bool emitOpLines;
|
||||
bool emitNonSemanticShaderDebugInfo;
|
||||
bool restoreNonSemanticShaderDebugInfo;
|
||||
bool emitNonSemanticShaderDebugSource;
|
||||
std::set<std::string> extensions;
|
||||
std::vector<const char*> sourceExtensions;
|
||||
std::vector<const char*> moduleProcesses;
|
||||
AddressingModel addressModel;
|
||||
MemoryModel memoryModel;
|
||||
std::set<spv::Capability> capabilities;
|
||||
int builderNumber;
|
||||
Module module;
|
||||
Block* buildPoint;
|
||||
Id uniqueId;
|
||||
Function* entryPointFunction;
|
||||
bool generatingOpCodeForSpecConst;
|
||||
AccessChain accessChain;
|
||||
|
||||
// special blocks of instructions for output
|
||||
std::vector<std::unique_ptr<Instruction> > strings;
|
||||
std::vector<std::unique_ptr<Instruction> > imports;
|
||||
std::vector<std::unique_ptr<Instruction> > entryPoints;
|
||||
std::vector<std::unique_ptr<Instruction> > executionModes;
|
||||
std::vector<std::unique_ptr<Instruction> > names;
|
||||
std::vector<std::unique_ptr<Instruction> > decorations;
|
||||
std::vector<std::unique_ptr<Instruction> > constantsTypesGlobals;
|
||||
std::vector<std::unique_ptr<Instruction> > externals;
|
||||
std::vector<std::unique_ptr<Function> > functions;
|
||||
|
||||
// not output, internally used for quick & dirty canonical (unique) creation
|
||||
|
||||
// map type opcodes to constant inst.
|
||||
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedConstants;
|
||||
// map struct-id to constant instructions
|
||||
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedStructConstants;
|
||||
// map type opcodes to type instructions
|
||||
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedTypes;
|
||||
// map type opcodes to debug type instructions
|
||||
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedDebugTypes;
|
||||
// list of OpConstantNull instructions
|
||||
std::vector<Instruction*> nullConstants;
|
||||
|
||||
// stack of switches
|
||||
std::stack<Block*> switchMerges;
|
||||
|
||||
// Our loop stack.
|
||||
std::stack<LoopBlocks> loops;
|
||||
|
||||
// map from strings to their string ids
|
||||
std::unordered_map<std::string, spv::Id> stringIds;
|
||||
|
||||
// map from include file name ids to their contents
|
||||
std::map<spv::Id, const std::string*> includeFiles;
|
||||
|
||||
// map from core id to debug id
|
||||
std::map <spv::Id, spv::Id> debugId;
|
||||
|
||||
// map from file name string id to DebugSource id
|
||||
std::unordered_map<spv::Id, spv::Id> debugSourceId;
|
||||
|
||||
// The stream for outputting warnings and errors.
|
||||
SpvBuildLogger* logger;
|
||||
}; // end Builder class
|
||||
|
||||
}; // end spv namespace
|
||||
|
||||
#endif // SpvBuilder_H
|
||||
495
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/SpvPostProcess.cpp
vendored
Normal file
495
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/SpvPostProcess.cpp
vendored
Normal file
@ -0,0 +1,495 @@
|
||||
//
|
||||
// Copyright (C) 2018 Google, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// Post-processing for SPIR-V IR, in internal form, not standard binary form.
|
||||
//
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <algorithm>
|
||||
|
||||
#include "SpvBuilder.h"
|
||||
#include "spirv.hpp"
|
||||
|
||||
namespace spv {
|
||||
#include "GLSL.std.450.h"
|
||||
#include "GLSL.ext.KHR.h"
|
||||
#include "GLSL.ext.EXT.h"
|
||||
#include "GLSL.ext.AMD.h"
|
||||
#include "GLSL.ext.NV.h"
|
||||
}
|
||||
|
||||
namespace spv {
|
||||
|
||||
#ifndef GLSLANG_WEB
|
||||
// Hook to visit each operand type and result type of an instruction.
|
||||
// Will be called multiple times for one instruction, once for each typed
|
||||
// operand and the result.
|
||||
void Builder::postProcessType(const Instruction& inst, Id typeId)
|
||||
{
|
||||
// Characterize the type being questioned
|
||||
Id basicTypeOp = getMostBasicTypeClass(typeId);
|
||||
int width = 0;
|
||||
if (basicTypeOp == OpTypeFloat || basicTypeOp == OpTypeInt)
|
||||
width = getScalarTypeWidth(typeId);
|
||||
|
||||
// Do opcode-specific checks
|
||||
switch (inst.getOpCode()) {
|
||||
case OpLoad:
|
||||
case OpStore:
|
||||
if (basicTypeOp == OpTypeStruct) {
|
||||
if (containsType(typeId, OpTypeInt, 8))
|
||||
addCapability(CapabilityInt8);
|
||||
if (containsType(typeId, OpTypeInt, 16))
|
||||
addCapability(CapabilityInt16);
|
||||
if (containsType(typeId, OpTypeFloat, 16))
|
||||
addCapability(CapabilityFloat16);
|
||||
} else {
|
||||
StorageClass storageClass = getStorageClass(inst.getIdOperand(0));
|
||||
if (width == 8) {
|
||||
switch (storageClass) {
|
||||
case StorageClassPhysicalStorageBufferEXT:
|
||||
case StorageClassUniform:
|
||||
case StorageClassStorageBuffer:
|
||||
case StorageClassPushConstant:
|
||||
break;
|
||||
default:
|
||||
addCapability(CapabilityInt8);
|
||||
break;
|
||||
}
|
||||
} else if (width == 16) {
|
||||
switch (storageClass) {
|
||||
case StorageClassPhysicalStorageBufferEXT:
|
||||
case StorageClassUniform:
|
||||
case StorageClassStorageBuffer:
|
||||
case StorageClassPushConstant:
|
||||
case StorageClassInput:
|
||||
case StorageClassOutput:
|
||||
break;
|
||||
default:
|
||||
if (basicTypeOp == OpTypeInt)
|
||||
addCapability(CapabilityInt16);
|
||||
if (basicTypeOp == OpTypeFloat)
|
||||
addCapability(CapabilityFloat16);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OpCopyObject:
|
||||
break;
|
||||
case OpFConvert:
|
||||
case OpSConvert:
|
||||
case OpUConvert:
|
||||
// Look for any 8/16-bit storage capabilities. If there are none, assume that
|
||||
// the convert instruction requires the Float16/Int8/16 capability.
|
||||
if (containsType(typeId, OpTypeFloat, 16) || containsType(typeId, OpTypeInt, 16)) {
|
||||
bool foundStorage = false;
|
||||
for (auto it = capabilities.begin(); it != capabilities.end(); ++it) {
|
||||
spv::Capability cap = *it;
|
||||
if (cap == spv::CapabilityStorageInputOutput16 ||
|
||||
cap == spv::CapabilityStoragePushConstant16 ||
|
||||
cap == spv::CapabilityStorageUniformBufferBlock16 ||
|
||||
cap == spv::CapabilityStorageUniform16) {
|
||||
foundStorage = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundStorage) {
|
||||
if (containsType(typeId, OpTypeFloat, 16))
|
||||
addCapability(CapabilityFloat16);
|
||||
if (containsType(typeId, OpTypeInt, 16))
|
||||
addCapability(CapabilityInt16);
|
||||
}
|
||||
}
|
||||
if (containsType(typeId, OpTypeInt, 8)) {
|
||||
bool foundStorage = false;
|
||||
for (auto it = capabilities.begin(); it != capabilities.end(); ++it) {
|
||||
spv::Capability cap = *it;
|
||||
if (cap == spv::CapabilityStoragePushConstant8 ||
|
||||
cap == spv::CapabilityUniformAndStorageBuffer8BitAccess ||
|
||||
cap == spv::CapabilityStorageBuffer8BitAccess) {
|
||||
foundStorage = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundStorage) {
|
||||
addCapability(CapabilityInt8);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OpExtInst:
|
||||
switch (inst.getImmediateOperand(1)) {
|
||||
case GLSLstd450Frexp:
|
||||
case GLSLstd450FrexpStruct:
|
||||
if (getSpvVersion() < spv::Spv_1_3 && containsType(typeId, OpTypeInt, 16))
|
||||
addExtension(spv::E_SPV_AMD_gpu_shader_int16);
|
||||
break;
|
||||
case GLSLstd450InterpolateAtCentroid:
|
||||
case GLSLstd450InterpolateAtSample:
|
||||
case GLSLstd450InterpolateAtOffset:
|
||||
if (getSpvVersion() < spv::Spv_1_3 && containsType(typeId, OpTypeFloat, 16))
|
||||
addExtension(spv::E_SPV_AMD_gpu_shader_half_float);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case OpAccessChain:
|
||||
case OpPtrAccessChain:
|
||||
if (isPointerType(typeId))
|
||||
break;
|
||||
if (basicTypeOp == OpTypeInt) {
|
||||
if (width == 16)
|
||||
addCapability(CapabilityInt16);
|
||||
else if (width == 8)
|
||||
addCapability(CapabilityInt8);
|
||||
}
|
||||
default:
|
||||
if (basicTypeOp == OpTypeInt) {
|
||||
if (width == 16)
|
||||
addCapability(CapabilityInt16);
|
||||
else if (width == 8)
|
||||
addCapability(CapabilityInt8);
|
||||
else if (width == 64)
|
||||
addCapability(CapabilityInt64);
|
||||
} else if (basicTypeOp == OpTypeFloat) {
|
||||
if (width == 16)
|
||||
addCapability(CapabilityFloat16);
|
||||
else if (width == 64)
|
||||
addCapability(CapabilityFloat64);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Called for each instruction that resides in a block.
|
||||
void Builder::postProcess(Instruction& inst)
|
||||
{
|
||||
// Add capabilities based simply on the opcode.
|
||||
switch (inst.getOpCode()) {
|
||||
case OpExtInst:
|
||||
switch (inst.getImmediateOperand(1)) {
|
||||
case GLSLstd450InterpolateAtCentroid:
|
||||
case GLSLstd450InterpolateAtSample:
|
||||
case GLSLstd450InterpolateAtOffset:
|
||||
addCapability(CapabilityInterpolationFunction);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case OpDPdxFine:
|
||||
case OpDPdyFine:
|
||||
case OpFwidthFine:
|
||||
case OpDPdxCoarse:
|
||||
case OpDPdyCoarse:
|
||||
case OpFwidthCoarse:
|
||||
addCapability(CapabilityDerivativeControl);
|
||||
break;
|
||||
|
||||
case OpImageQueryLod:
|
||||
case OpImageQuerySize:
|
||||
case OpImageQuerySizeLod:
|
||||
case OpImageQuerySamples:
|
||||
case OpImageQueryLevels:
|
||||
addCapability(CapabilityImageQuery);
|
||||
break;
|
||||
|
||||
case OpGroupNonUniformPartitionNV:
|
||||
addExtension(E_SPV_NV_shader_subgroup_partitioned);
|
||||
addCapability(CapabilityGroupNonUniformPartitionedNV);
|
||||
break;
|
||||
|
||||
case OpLoad:
|
||||
case OpStore:
|
||||
{
|
||||
// For any load/store to a PhysicalStorageBufferEXT, walk the accesschain
|
||||
// index list to compute the misalignment. The pre-existing alignment value
|
||||
// (set via Builder::AccessChain::alignment) only accounts for the base of
|
||||
// the reference type and any scalar component selection in the accesschain,
|
||||
// and this function computes the rest from the SPIR-V Offset decorations.
|
||||
Instruction *accessChain = module.getInstruction(inst.getIdOperand(0));
|
||||
if (accessChain->getOpCode() == OpAccessChain) {
|
||||
Instruction *base = module.getInstruction(accessChain->getIdOperand(0));
|
||||
// Get the type of the base of the access chain. It must be a pointer type.
|
||||
Id typeId = base->getTypeId();
|
||||
Instruction *type = module.getInstruction(typeId);
|
||||
assert(type->getOpCode() == OpTypePointer);
|
||||
if (type->getImmediateOperand(0) != StorageClassPhysicalStorageBufferEXT) {
|
||||
break;
|
||||
}
|
||||
// Get the pointee type.
|
||||
typeId = type->getIdOperand(1);
|
||||
type = module.getInstruction(typeId);
|
||||
// Walk the index list for the access chain. For each index, find any
|
||||
// misalignment that can apply when accessing the member/element via
|
||||
// Offset/ArrayStride/MatrixStride decorations, and bitwise OR them all
|
||||
// together.
|
||||
int alignment = 0;
|
||||
for (int i = 1; i < accessChain->getNumOperands(); ++i) {
|
||||
Instruction *idx = module.getInstruction(accessChain->getIdOperand(i));
|
||||
if (type->getOpCode() == OpTypeStruct) {
|
||||
assert(idx->getOpCode() == OpConstant);
|
||||
unsigned int c = idx->getImmediateOperand(0);
|
||||
|
||||
const auto function = [&](const std::unique_ptr<Instruction>& decoration) {
|
||||
if (decoration.get()->getOpCode() == OpMemberDecorate &&
|
||||
decoration.get()->getIdOperand(0) == typeId &&
|
||||
decoration.get()->getImmediateOperand(1) == c &&
|
||||
(decoration.get()->getImmediateOperand(2) == DecorationOffset ||
|
||||
decoration.get()->getImmediateOperand(2) == DecorationMatrixStride)) {
|
||||
alignment |= decoration.get()->getImmediateOperand(3);
|
||||
}
|
||||
};
|
||||
std::for_each(decorations.begin(), decorations.end(), function);
|
||||
// get the next member type
|
||||
typeId = type->getIdOperand(c);
|
||||
type = module.getInstruction(typeId);
|
||||
} else if (type->getOpCode() == OpTypeArray ||
|
||||
type->getOpCode() == OpTypeRuntimeArray) {
|
||||
const auto function = [&](const std::unique_ptr<Instruction>& decoration) {
|
||||
if (decoration.get()->getOpCode() == OpDecorate &&
|
||||
decoration.get()->getIdOperand(0) == typeId &&
|
||||
decoration.get()->getImmediateOperand(1) == DecorationArrayStride) {
|
||||
alignment |= decoration.get()->getImmediateOperand(2);
|
||||
}
|
||||
};
|
||||
std::for_each(decorations.begin(), decorations.end(), function);
|
||||
// Get the element type
|
||||
typeId = type->getIdOperand(0);
|
||||
type = module.getInstruction(typeId);
|
||||
} else {
|
||||
// Once we get to any non-aggregate type, we're done.
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(inst.getNumOperands() >= 3);
|
||||
unsigned int memoryAccess = inst.getImmediateOperand((inst.getOpCode() == OpStore) ? 2 : 1);
|
||||
assert(memoryAccess & MemoryAccessAlignedMask);
|
||||
static_cast<void>(memoryAccess);
|
||||
// Compute the index of the alignment operand.
|
||||
int alignmentIdx = 2;
|
||||
if (inst.getOpCode() == OpStore)
|
||||
alignmentIdx++;
|
||||
// Merge new and old (mis)alignment
|
||||
alignment |= inst.getImmediateOperand(alignmentIdx);
|
||||
// Pick the LSB
|
||||
alignment = alignment & ~(alignment & (alignment-1));
|
||||
// update the Aligned operand
|
||||
inst.setImmediateOperand(alignmentIdx, alignment);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Checks based on type
|
||||
if (inst.getTypeId() != NoType)
|
||||
postProcessType(inst, inst.getTypeId());
|
||||
for (int op = 0; op < inst.getNumOperands(); ++op) {
|
||||
if (inst.isIdOperand(op)) {
|
||||
// In blocks, these are always result ids, but we are relying on
|
||||
// getTypeId() to return NoType for things like OpLabel.
|
||||
if (getTypeId(inst.getIdOperand(op)) != NoType)
|
||||
postProcessType(inst, getTypeId(inst.getIdOperand(op)));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// comment in header
|
||||
void Builder::postProcessCFG()
|
||||
{
|
||||
// reachableBlocks is the set of blockss reached via control flow, or which are
|
||||
// unreachable continue targert or unreachable merge.
|
||||
std::unordered_set<const Block*> reachableBlocks;
|
||||
std::unordered_map<Block*, Block*> headerForUnreachableContinue;
|
||||
std::unordered_set<Block*> unreachableMerges;
|
||||
std::unordered_set<Id> unreachableDefinitions;
|
||||
// Collect IDs defined in unreachable blocks. For each function, label the
|
||||
// reachable blocks first. Then for each unreachable block, collect the
|
||||
// result IDs of the instructions in it.
|
||||
for (auto fi = module.getFunctions().cbegin(); fi != module.getFunctions().cend(); fi++) {
|
||||
Function* f = *fi;
|
||||
Block* entry = f->getEntryBlock();
|
||||
inReadableOrder(entry,
|
||||
[&reachableBlocks, &unreachableMerges, &headerForUnreachableContinue]
|
||||
(Block* b, ReachReason why, Block* header) {
|
||||
reachableBlocks.insert(b);
|
||||
if (why == ReachDeadContinue) headerForUnreachableContinue[b] = header;
|
||||
if (why == ReachDeadMerge) unreachableMerges.insert(b);
|
||||
});
|
||||
for (auto bi = f->getBlocks().cbegin(); bi != f->getBlocks().cend(); bi++) {
|
||||
Block* b = *bi;
|
||||
if (unreachableMerges.count(b) != 0 || headerForUnreachableContinue.count(b) != 0) {
|
||||
auto ii = b->getInstructions().cbegin();
|
||||
++ii; // Keep potential decorations on the label.
|
||||
for (; ii != b->getInstructions().cend(); ++ii)
|
||||
unreachableDefinitions.insert(ii->get()->getResultId());
|
||||
} else if (reachableBlocks.count(b) == 0) {
|
||||
// The normal case for unreachable code. All definitions are considered dead.
|
||||
for (auto ii = b->getInstructions().cbegin(); ii != b->getInstructions().cend(); ++ii)
|
||||
unreachableDefinitions.insert(ii->get()->getResultId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Modify unreachable merge blocks and unreachable continue targets.
|
||||
// Delete their contents.
|
||||
for (auto mergeIter = unreachableMerges.begin(); mergeIter != unreachableMerges.end(); ++mergeIter) {
|
||||
(*mergeIter)->rewriteAsCanonicalUnreachableMerge();
|
||||
}
|
||||
for (auto continueIter = headerForUnreachableContinue.begin();
|
||||
continueIter != headerForUnreachableContinue.end();
|
||||
++continueIter) {
|
||||
Block* continue_target = continueIter->first;
|
||||
Block* header = continueIter->second;
|
||||
continue_target->rewriteAsCanonicalUnreachableContinue(header);
|
||||
}
|
||||
|
||||
// Remove unneeded decorations, for unreachable instructions
|
||||
decorations.erase(std::remove_if(decorations.begin(), decorations.end(),
|
||||
[&unreachableDefinitions](std::unique_ptr<Instruction>& I) -> bool {
|
||||
Id decoration_id = I.get()->getIdOperand(0);
|
||||
return unreachableDefinitions.count(decoration_id) != 0;
|
||||
}),
|
||||
decorations.end());
|
||||
}
|
||||
|
||||
#ifndef GLSLANG_WEB
|
||||
// comment in header
|
||||
void Builder::postProcessFeatures() {
|
||||
// Add per-instruction capabilities, extensions, etc.,
|
||||
|
||||
// Look for any 8/16 bit type in physical storage buffer class, and set the
|
||||
// appropriate capability. This happens in createSpvVariable for other storage
|
||||
// classes, but there isn't always a variable for physical storage buffer.
|
||||
for (int t = 0; t < (int)groupedTypes[OpTypePointer].size(); ++t) {
|
||||
Instruction* type = groupedTypes[OpTypePointer][t];
|
||||
if (type->getImmediateOperand(0) == (unsigned)StorageClassPhysicalStorageBufferEXT) {
|
||||
if (containsType(type->getIdOperand(1), OpTypeInt, 8)) {
|
||||
addIncorporatedExtension(spv::E_SPV_KHR_8bit_storage, spv::Spv_1_5);
|
||||
addCapability(spv::CapabilityStorageBuffer8BitAccess);
|
||||
}
|
||||
if (containsType(type->getIdOperand(1), OpTypeInt, 16) ||
|
||||
containsType(type->getIdOperand(1), OpTypeFloat, 16)) {
|
||||
addIncorporatedExtension(spv::E_SPV_KHR_16bit_storage, spv::Spv_1_3);
|
||||
addCapability(spv::CapabilityStorageBuffer16BitAccess);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// process all block-contained instructions
|
||||
for (auto fi = module.getFunctions().cbegin(); fi != module.getFunctions().cend(); fi++) {
|
||||
Function* f = *fi;
|
||||
for (auto bi = f->getBlocks().cbegin(); bi != f->getBlocks().cend(); bi++) {
|
||||
Block* b = *bi;
|
||||
for (auto ii = b->getInstructions().cbegin(); ii != b->getInstructions().cend(); ii++)
|
||||
postProcess(*ii->get());
|
||||
|
||||
// For all local variables that contain pointers to PhysicalStorageBufferEXT, check whether
|
||||
// there is an existing restrict/aliased decoration. If we don't find one, add Aliased as the
|
||||
// default.
|
||||
for (auto vi = b->getLocalVariables().cbegin(); vi != b->getLocalVariables().cend(); vi++) {
|
||||
const Instruction& inst = *vi->get();
|
||||
Id resultId = inst.getResultId();
|
||||
if (containsPhysicalStorageBufferOrArray(getDerefTypeId(resultId))) {
|
||||
bool foundDecoration = false;
|
||||
const auto function = [&](const std::unique_ptr<Instruction>& decoration) {
|
||||
if (decoration.get()->getIdOperand(0) == resultId &&
|
||||
decoration.get()->getOpCode() == OpDecorate &&
|
||||
(decoration.get()->getImmediateOperand(1) == spv::DecorationAliasedPointerEXT ||
|
||||
decoration.get()->getImmediateOperand(1) == spv::DecorationRestrictPointerEXT)) {
|
||||
foundDecoration = true;
|
||||
}
|
||||
};
|
||||
std::for_each(decorations.begin(), decorations.end(), function);
|
||||
if (!foundDecoration) {
|
||||
addDecoration(resultId, spv::DecorationAliasedPointerEXT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If any Vulkan memory model-specific functionality is used, update the
|
||||
// OpMemoryModel to match.
|
||||
if (capabilities.find(spv::CapabilityVulkanMemoryModelKHR) != capabilities.end()) {
|
||||
memoryModel = spv::MemoryModelVulkanKHR;
|
||||
addIncorporatedExtension(spv::E_SPV_KHR_vulkan_memory_model, spv::Spv_1_5);
|
||||
}
|
||||
|
||||
// Add Aliased decoration if there's more than one Workgroup Block variable.
|
||||
if (capabilities.find(spv::CapabilityWorkgroupMemoryExplicitLayoutKHR) != capabilities.end()) {
|
||||
assert(entryPoints.size() == 1);
|
||||
auto &ep = entryPoints[0];
|
||||
|
||||
std::vector<Id> workgroup_variables;
|
||||
for (int i = 0; i < (int)ep->getNumOperands(); i++) {
|
||||
if (!ep->isIdOperand(i))
|
||||
continue;
|
||||
|
||||
const Id id = ep->getIdOperand(i);
|
||||
const Instruction *instr = module.getInstruction(id);
|
||||
if (instr->getOpCode() != spv::OpVariable)
|
||||
continue;
|
||||
|
||||
if (instr->getImmediateOperand(0) == spv::StorageClassWorkgroup)
|
||||
workgroup_variables.push_back(id);
|
||||
}
|
||||
|
||||
if (workgroup_variables.size() > 1) {
|
||||
for (size_t i = 0; i < workgroup_variables.size(); i++)
|
||||
addDecoration(workgroup_variables[i], spv::DecorationAliased);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// comment in header
|
||||
void Builder::postProcess() {
|
||||
postProcessCFG();
|
||||
#ifndef GLSLANG_WEB
|
||||
postProcessFeatures();
|
||||
#endif
|
||||
}
|
||||
|
||||
}; // end spv namespace
|
||||
247
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/SpvTools.cpp
vendored
Normal file
247
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/SpvTools.cpp
vendored
Normal file
@ -0,0 +1,247 @@
|
||||
//
|
||||
// Copyright (C) 2014-2016 LunarG, Inc.
|
||||
// Copyright (C) 2018-2020 Google, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// Call into SPIRV-Tools to disassemble, validate, and optimize.
|
||||
//
|
||||
|
||||
#if ENABLE_OPT
|
||||
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
|
||||
#include "SpvTools.h"
|
||||
#include "spirv-tools/optimizer.hpp"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
// Translate glslang's view of target versioning to what SPIRV-Tools uses.
|
||||
spv_target_env MapToSpirvToolsEnv(const SpvVersion& spvVersion, spv::SpvBuildLogger* logger)
|
||||
{
|
||||
switch (spvVersion.vulkan) {
|
||||
case glslang::EShTargetVulkan_1_0:
|
||||
return spv_target_env::SPV_ENV_VULKAN_1_0;
|
||||
case glslang::EShTargetVulkan_1_1:
|
||||
switch (spvVersion.spv) {
|
||||
case EShTargetSpv_1_0:
|
||||
case EShTargetSpv_1_1:
|
||||
case EShTargetSpv_1_2:
|
||||
case EShTargetSpv_1_3:
|
||||
return spv_target_env::SPV_ENV_VULKAN_1_1;
|
||||
case EShTargetSpv_1_4:
|
||||
return spv_target_env::SPV_ENV_VULKAN_1_1_SPIRV_1_4;
|
||||
default:
|
||||
logger->missingFunctionality("Target version for SPIRV-Tools validator");
|
||||
return spv_target_env::SPV_ENV_VULKAN_1_1;
|
||||
}
|
||||
case glslang::EShTargetVulkan_1_2:
|
||||
return spv_target_env::SPV_ENV_VULKAN_1_2;
|
||||
case glslang::EShTargetVulkan_1_3:
|
||||
return spv_target_env::SPV_ENV_VULKAN_1_3;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (spvVersion.openGl > 0)
|
||||
return spv_target_env::SPV_ENV_OPENGL_4_5;
|
||||
|
||||
logger->missingFunctionality("Target version for SPIRV-Tools validator");
|
||||
return spv_target_env::SPV_ENV_UNIVERSAL_1_0;
|
||||
}
|
||||
|
||||
// Callback passed to spvtools::Optimizer::SetMessageConsumer
|
||||
void OptimizerMesssageConsumer(spv_message_level_t level, const char *source,
|
||||
const spv_position_t &position, const char *message)
|
||||
{
|
||||
auto &out = std::cerr;
|
||||
switch (level)
|
||||
{
|
||||
case SPV_MSG_FATAL:
|
||||
case SPV_MSG_INTERNAL_ERROR:
|
||||
case SPV_MSG_ERROR:
|
||||
out << "error: ";
|
||||
break;
|
||||
case SPV_MSG_WARNING:
|
||||
out << "warning: ";
|
||||
break;
|
||||
case SPV_MSG_INFO:
|
||||
case SPV_MSG_DEBUG:
|
||||
out << "info: ";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (source)
|
||||
{
|
||||
out << source << ":";
|
||||
}
|
||||
out << position.line << ":" << position.column << ":" << position.index << ":";
|
||||
if (message)
|
||||
{
|
||||
out << " " << message;
|
||||
}
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
// Use the SPIRV-Tools disassembler to print SPIR-V using a SPV_ENV_UNIVERSAL_1_3 environment.
|
||||
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv)
|
||||
{
|
||||
SpirvToolsDisassemble(out, spirv, spv_target_env::SPV_ENV_UNIVERSAL_1_3);
|
||||
}
|
||||
|
||||
// Use the SPIRV-Tools disassembler to print SPIR-V with a provided SPIR-V environment.
|
||||
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv,
|
||||
spv_target_env requested_context)
|
||||
{
|
||||
// disassemble
|
||||
spv_context context = spvContextCreate(requested_context);
|
||||
spv_text text;
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
spvBinaryToText(context, spirv.data(), spirv.size(),
|
||||
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES | SPV_BINARY_TO_TEXT_OPTION_INDENT,
|
||||
&text, &diagnostic);
|
||||
|
||||
// dump
|
||||
if (diagnostic == nullptr)
|
||||
out << text->str;
|
||||
else
|
||||
spvDiagnosticPrint(diagnostic);
|
||||
|
||||
// teardown
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
spvContextDestroy(context);
|
||||
}
|
||||
|
||||
// Apply the SPIRV-Tools validator to generated SPIR-V.
|
||||
void SpirvToolsValidate(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
||||
spv::SpvBuildLogger* logger, bool prelegalization)
|
||||
{
|
||||
// validate
|
||||
spv_context context = spvContextCreate(MapToSpirvToolsEnv(intermediate.getSpv(), logger));
|
||||
spv_const_binary_t binary = { spirv.data(), spirv.size() };
|
||||
spv_diagnostic diagnostic = nullptr;
|
||||
spv_validator_options options = spvValidatorOptionsCreate();
|
||||
spvValidatorOptionsSetRelaxBlockLayout(options, intermediate.usingHlslOffsets());
|
||||
spvValidatorOptionsSetBeforeHlslLegalization(options, prelegalization);
|
||||
spvValidatorOptionsSetScalarBlockLayout(options, intermediate.usingScalarBlockLayout());
|
||||
spvValidatorOptionsSetWorkgroupScalarBlockLayout(options, intermediate.usingScalarBlockLayout());
|
||||
spvValidateWithOptions(context, options, &binary, &diagnostic);
|
||||
|
||||
// report
|
||||
if (diagnostic != nullptr) {
|
||||
logger->error("SPIRV-Tools Validation Errors");
|
||||
logger->error(diagnostic->error);
|
||||
}
|
||||
|
||||
// tear down
|
||||
spvValidatorOptionsDestroy(options);
|
||||
spvDiagnosticDestroy(diagnostic);
|
||||
spvContextDestroy(context);
|
||||
}
|
||||
|
||||
// Apply the SPIRV-Tools optimizer to generated SPIR-V. HLSL SPIR-V is legalized in the process.
|
||||
void SpirvToolsTransform(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
||||
spv::SpvBuildLogger* logger, const SpvOptions* options)
|
||||
{
|
||||
spv_target_env target_env = MapToSpirvToolsEnv(intermediate.getSpv(), logger);
|
||||
|
||||
spvtools::Optimizer optimizer(target_env);
|
||||
optimizer.SetMessageConsumer(OptimizerMesssageConsumer);
|
||||
|
||||
// If debug (specifically source line info) is being generated, propagate
|
||||
// line information into all SPIR-V instructions. This avoids loss of
|
||||
// information when instructions are deleted or moved. Later, remove
|
||||
// redundant information to minimize final SPRIR-V size.
|
||||
if (options->stripDebugInfo) {
|
||||
optimizer.RegisterPass(spvtools::CreateStripDebugInfoPass());
|
||||
}
|
||||
optimizer.RegisterPass(spvtools::CreateWrapOpKillPass());
|
||||
optimizer.RegisterPass(spvtools::CreateDeadBranchElimPass());
|
||||
optimizer.RegisterPass(spvtools::CreateMergeReturnPass());
|
||||
optimizer.RegisterPass(spvtools::CreateInlineExhaustivePass());
|
||||
optimizer.RegisterPass(spvtools::CreateEliminateDeadFunctionsPass());
|
||||
optimizer.RegisterPass(spvtools::CreateScalarReplacementPass());
|
||||
optimizer.RegisterPass(spvtools::CreateLocalAccessChainConvertPass());
|
||||
optimizer.RegisterPass(spvtools::CreateLocalSingleBlockLoadStoreElimPass());
|
||||
optimizer.RegisterPass(spvtools::CreateLocalSingleStoreElimPass());
|
||||
optimizer.RegisterPass(spvtools::CreateSimplificationPass());
|
||||
optimizer.RegisterPass(spvtools::CreateAggressiveDCEPass());
|
||||
optimizer.RegisterPass(spvtools::CreateVectorDCEPass());
|
||||
optimizer.RegisterPass(spvtools::CreateDeadInsertElimPass());
|
||||
optimizer.RegisterPass(spvtools::CreateAggressiveDCEPass());
|
||||
optimizer.RegisterPass(spvtools::CreateDeadBranchElimPass());
|
||||
optimizer.RegisterPass(spvtools::CreateBlockMergePass());
|
||||
optimizer.RegisterPass(spvtools::CreateLocalMultiStoreElimPass());
|
||||
optimizer.RegisterPass(spvtools::CreateIfConversionPass());
|
||||
optimizer.RegisterPass(spvtools::CreateSimplificationPass());
|
||||
optimizer.RegisterPass(spvtools::CreateAggressiveDCEPass());
|
||||
optimizer.RegisterPass(spvtools::CreateVectorDCEPass());
|
||||
optimizer.RegisterPass(spvtools::CreateDeadInsertElimPass());
|
||||
optimizer.RegisterPass(spvtools::CreateInterpolateFixupPass());
|
||||
if (options->optimizeSize) {
|
||||
optimizer.RegisterPass(spvtools::CreateRedundancyEliminationPass());
|
||||
optimizer.RegisterPass(spvtools::CreateEliminateDeadInputComponentsPass());
|
||||
}
|
||||
optimizer.RegisterPass(spvtools::CreateAggressiveDCEPass());
|
||||
optimizer.RegisterPass(spvtools::CreateCFGCleanupPass());
|
||||
|
||||
spvtools::OptimizerOptions spvOptOptions;
|
||||
optimizer.SetTargetEnv(MapToSpirvToolsEnv(intermediate.getSpv(), logger));
|
||||
spvOptOptions.set_run_validator(false); // The validator may run as a separate step later on
|
||||
optimizer.Run(spirv.data(), spirv.size(), &spirv, spvOptOptions);
|
||||
}
|
||||
|
||||
// Apply the SPIRV-Tools optimizer to strip debug info from SPIR-V. This is implicitly done by
|
||||
// SpirvToolsTransform if spvOptions->stripDebugInfo is set, but can be called separately if
|
||||
// optimization is disabled.
|
||||
void SpirvToolsStripDebugInfo(const glslang::TIntermediate& intermediate,
|
||||
std::vector<unsigned int>& spirv, spv::SpvBuildLogger* logger)
|
||||
{
|
||||
spv_target_env target_env = MapToSpirvToolsEnv(intermediate.getSpv(), logger);
|
||||
|
||||
spvtools::Optimizer optimizer(target_env);
|
||||
optimizer.SetMessageConsumer(OptimizerMesssageConsumer);
|
||||
|
||||
optimizer.RegisterPass(spvtools::CreateStripDebugInfoPass());
|
||||
|
||||
spvtools::OptimizerOptions spvOptOptions;
|
||||
optimizer.SetTargetEnv(MapToSpirvToolsEnv(intermediate.getSpv(), logger));
|
||||
spvOptOptions.set_run_validator(false); // The validator may run as a separate step later on
|
||||
optimizer.Run(spirv.data(), spirv.size(), &spirv, spvOptOptions);
|
||||
}
|
||||
|
||||
}; // end namespace glslang
|
||||
|
||||
#endif
|
||||
93
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/SpvTools.h
vendored
Normal file
93
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/SpvTools.h
vendored
Normal file
@ -0,0 +1,93 @@
|
||||
//
|
||||
// Copyright (C) 2014-2016 LunarG, Inc.
|
||||
// Copyright (C) 2018 Google, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// Call into SPIRV-Tools to disassemble, validate, and optimize.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#ifndef GLSLANG_SPV_TOOLS_H
|
||||
#define GLSLANG_SPV_TOOLS_H
|
||||
|
||||
#if ENABLE_OPT
|
||||
#include <vector>
|
||||
#include <ostream>
|
||||
#include "spirv-tools/libspirv.h"
|
||||
#endif
|
||||
|
||||
#include "glslang/MachineIndependent/localintermediate.h"
|
||||
#include "Logger.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
struct SpvOptions {
|
||||
bool generateDebugInfo {false};
|
||||
bool stripDebugInfo {false};
|
||||
bool disableOptimizer {true};
|
||||
bool optimizeSize {false};
|
||||
bool disassemble {false};
|
||||
bool validate {false};
|
||||
bool emitNonSemanticShaderDebugInfo {false};
|
||||
bool emitNonSemanticShaderDebugSource{ false };
|
||||
};
|
||||
|
||||
#if ENABLE_OPT
|
||||
|
||||
// Use the SPIRV-Tools disassembler to print SPIR-V using a SPV_ENV_UNIVERSAL_1_3 environment.
|
||||
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv);
|
||||
|
||||
// Use the SPIRV-Tools disassembler to print SPIR-V with a provided SPIR-V environment.
|
||||
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv,
|
||||
spv_target_env requested_context);
|
||||
|
||||
// Apply the SPIRV-Tools validator to generated SPIR-V.
|
||||
void SpirvToolsValidate(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
||||
spv::SpvBuildLogger*, bool prelegalization);
|
||||
|
||||
// Apply the SPIRV-Tools optimizer to generated SPIR-V. HLSL SPIR-V is legalized in the process.
|
||||
void SpirvToolsTransform(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
||||
spv::SpvBuildLogger*, const SpvOptions*);
|
||||
|
||||
// Apply the SPIRV-Tools optimizer to strip debug info from SPIR-V. This is implicitly done by
|
||||
// SpirvToolsTransform if spvOptions->stripDebugInfo is set, but can be called separately if
|
||||
// optimization is disabled.
|
||||
void SpirvToolsStripDebugInfo(const glslang::TIntermediate& intermediate,
|
||||
std::vector<unsigned int>& spirv, spv::SpvBuildLogger*);
|
||||
|
||||
#endif
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // GLSLANG_SPV_TOOLS_H
|
||||
81
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/bitutils.h
vendored
Normal file
81
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/bitutils.h
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef LIBSPIRV_UTIL_BITUTILS_H_
|
||||
#define LIBSPIRV_UTIL_BITUTILS_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
namespace spvutils {
|
||||
|
||||
// Performs a bitwise copy of source to the destination type Dest.
|
||||
template <typename Dest, typename Src>
|
||||
Dest BitwiseCast(Src source) {
|
||||
Dest dest;
|
||||
static_assert(sizeof(source) == sizeof(dest),
|
||||
"BitwiseCast: Source and destination must have the same size");
|
||||
std::memcpy(static_cast<void*>(&dest), &source, sizeof(dest));
|
||||
return dest;
|
||||
}
|
||||
|
||||
// SetBits<T, First, Num> returns an integer of type <T> with bits set
|
||||
// for position <First> through <First + Num - 1>, counting from the least
|
||||
// significant bit. In particular when Num == 0, no positions are set to 1.
|
||||
// A static assert will be triggered if First + Num > sizeof(T) * 8, that is,
|
||||
// a bit that will not fit in the underlying type is set.
|
||||
template <typename T, size_t First = 0, size_t Num = 0>
|
||||
struct SetBits {
|
||||
static_assert(First < sizeof(T) * 8,
|
||||
"Tried to set a bit that is shifted too far.");
|
||||
const static T get = (T(1) << First) | SetBits<T, First + 1, Num - 1>::get;
|
||||
};
|
||||
|
||||
template <typename T, size_t Last>
|
||||
struct SetBits<T, Last, 0> {
|
||||
const static T get = T(0);
|
||||
};
|
||||
|
||||
// This is all compile-time so we can put our tests right here.
|
||||
static_assert(SetBits<uint32_t, 0, 0>::get == uint32_t(0x00000000),
|
||||
"SetBits failed");
|
||||
static_assert(SetBits<uint32_t, 0, 1>::get == uint32_t(0x00000001),
|
||||
"SetBits failed");
|
||||
static_assert(SetBits<uint32_t, 31, 1>::get == uint32_t(0x80000000),
|
||||
"SetBits failed");
|
||||
static_assert(SetBits<uint32_t, 1, 2>::get == uint32_t(0x00000006),
|
||||
"SetBits failed");
|
||||
static_assert(SetBits<uint32_t, 30, 2>::get == uint32_t(0xc0000000),
|
||||
"SetBits failed");
|
||||
static_assert(SetBits<uint32_t, 0, 31>::get == uint32_t(0x7FFFFFFF),
|
||||
"SetBits failed");
|
||||
static_assert(SetBits<uint32_t, 0, 32>::get == uint32_t(0xFFFFFFFF),
|
||||
"SetBits failed");
|
||||
static_assert(SetBits<uint32_t, 16, 16>::get == uint32_t(0xFFFF0000),
|
||||
"SetBits failed");
|
||||
|
||||
static_assert(SetBits<uint64_t, 0, 1>::get == uint64_t(0x0000000000000001LL),
|
||||
"SetBits failed");
|
||||
static_assert(SetBits<uint64_t, 63, 1>::get == uint64_t(0x8000000000000000LL),
|
||||
"SetBits failed");
|
||||
static_assert(SetBits<uint64_t, 62, 2>::get == uint64_t(0xc000000000000000LL),
|
||||
"SetBits failed");
|
||||
static_assert(SetBits<uint64_t, 31, 1>::get == uint64_t(0x0000000080000000LL),
|
||||
"SetBits failed");
|
||||
static_assert(SetBits<uint64_t, 16, 16>::get == uint64_t(0x00000000FFFF0000LL),
|
||||
"SetBits failed");
|
||||
|
||||
} // namespace spvutils
|
||||
|
||||
#endif // LIBSPIRV_UTIL_BITUTILS_H_
|
||||
761
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/disassemble.cpp
vendored
Normal file
761
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/disassemble.cpp
vendored
Normal file
@ -0,0 +1,761 @@
|
||||
//
|
||||
// Copyright (C) 2014-2015 LunarG, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// Disassembler for SPIR-V.
|
||||
//
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
#include <iomanip>
|
||||
#include <stack>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <utility>
|
||||
|
||||
#include "disassemble.h"
|
||||
#include "doc.h"
|
||||
|
||||
namespace spv {
|
||||
extern "C" {
|
||||
// Include C-based headers that don't have a namespace
|
||||
#include "GLSL.std.450.h"
|
||||
#include "GLSL.ext.AMD.h"
|
||||
#include "GLSL.ext.NV.h"
|
||||
}
|
||||
}
|
||||
const char* GlslStd450DebugNames[spv::GLSLstd450Count];
|
||||
|
||||
namespace spv {
|
||||
|
||||
static const char* GLSLextAMDGetDebugNames(const char*, unsigned);
|
||||
static const char* GLSLextNVGetDebugNames(const char*, unsigned);
|
||||
|
||||
static void Kill(std::ostream& out, const char* message)
|
||||
{
|
||||
out << std::endl << "Disassembly failed: " << message << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// used to identify the extended instruction library imported when printing
|
||||
enum ExtInstSet {
|
||||
GLSL450Inst,
|
||||
GLSLextAMDInst,
|
||||
GLSLextNVInst,
|
||||
OpenCLExtInst,
|
||||
NonSemanticDebugPrintfExtInst,
|
||||
};
|
||||
|
||||
// Container class for a single instance of a SPIR-V stream, with methods for disassembly.
|
||||
class SpirvStream {
|
||||
public:
|
||||
SpirvStream(std::ostream& out, const std::vector<unsigned int>& stream) : out(out), stream(stream), word(0), nextNestedControl(0) { }
|
||||
virtual ~SpirvStream() { }
|
||||
|
||||
void validate();
|
||||
void processInstructions();
|
||||
|
||||
protected:
|
||||
SpirvStream(const SpirvStream&);
|
||||
SpirvStream& operator=(const SpirvStream&);
|
||||
Op getOpCode(int id) const { return idInstruction[id] ? (Op)(stream[idInstruction[id]] & OpCodeMask) : OpNop; }
|
||||
|
||||
// Output methods
|
||||
void outputIndent();
|
||||
void formatId(Id id, std::stringstream&);
|
||||
void outputResultId(Id id);
|
||||
void outputTypeId(Id id);
|
||||
void outputId(Id id);
|
||||
void outputMask(OperandClass operandClass, unsigned mask);
|
||||
void disassembleImmediates(int numOperands);
|
||||
void disassembleIds(int numOperands);
|
||||
std::pair<int, std::string> decodeString();
|
||||
int disassembleString();
|
||||
void disassembleInstruction(Id resultId, Id typeId, Op opCode, int numOperands);
|
||||
|
||||
// Data
|
||||
std::ostream& out; // where to write the disassembly
|
||||
const std::vector<unsigned int>& stream; // the actual word stream
|
||||
int size; // the size of the word stream
|
||||
int word; // the next word of the stream to read
|
||||
|
||||
// map each <id> to the instruction that created it
|
||||
Id bound;
|
||||
std::vector<unsigned int> idInstruction; // the word offset into the stream where the instruction for result [id] starts; 0 if not yet seen (forward reference or function parameter)
|
||||
|
||||
std::vector<std::string> idDescriptor; // the best text string known for explaining the <id>
|
||||
|
||||
// schema
|
||||
unsigned int schema;
|
||||
|
||||
// stack of structured-merge points
|
||||
std::stack<Id> nestedControl;
|
||||
Id nextNestedControl; // need a slight delay for when we are nested
|
||||
};
|
||||
|
||||
void SpirvStream::validate()
|
||||
{
|
||||
size = (int)stream.size();
|
||||
if (size < 4)
|
||||
Kill(out, "stream is too short");
|
||||
|
||||
// Magic number
|
||||
if (stream[word++] != MagicNumber) {
|
||||
out << "Bad magic number";
|
||||
return;
|
||||
}
|
||||
|
||||
// Version
|
||||
out << "// Module Version " << std::hex << stream[word++] << std::endl;
|
||||
|
||||
// Generator's magic number
|
||||
out << "// Generated by (magic number): " << std::hex << stream[word++] << std::dec << std::endl;
|
||||
|
||||
// Result <id> bound
|
||||
bound = stream[word++];
|
||||
idInstruction.resize(bound);
|
||||
idDescriptor.resize(bound);
|
||||
out << "// Id's are bound by " << bound << std::endl;
|
||||
out << std::endl;
|
||||
|
||||
// Reserved schema, must be 0 for now
|
||||
schema = stream[word++];
|
||||
if (schema != 0)
|
||||
Kill(out, "bad schema, must be 0");
|
||||
}
|
||||
|
||||
// Loop over all the instructions, in order, processing each.
|
||||
// Boiler plate for each is handled here directly, the rest is dispatched.
|
||||
void SpirvStream::processInstructions()
|
||||
{
|
||||
// Instructions
|
||||
while (word < size) {
|
||||
int instructionStart = word;
|
||||
|
||||
// Instruction wordCount and opcode
|
||||
unsigned int firstWord = stream[word];
|
||||
unsigned wordCount = firstWord >> WordCountShift;
|
||||
Op opCode = (Op)(firstWord & OpCodeMask);
|
||||
int nextInst = word + wordCount;
|
||||
++word;
|
||||
|
||||
// Presence of full instruction
|
||||
if (nextInst > size)
|
||||
Kill(out, "stream instruction terminated too early");
|
||||
|
||||
// Base for computing number of operands; will be updated as more is learned
|
||||
unsigned numOperands = wordCount - 1;
|
||||
|
||||
// Type <id>
|
||||
Id typeId = 0;
|
||||
if (InstructionDesc[opCode].hasType()) {
|
||||
typeId = stream[word++];
|
||||
--numOperands;
|
||||
}
|
||||
|
||||
// Result <id>
|
||||
Id resultId = 0;
|
||||
if (InstructionDesc[opCode].hasResult()) {
|
||||
resultId = stream[word++];
|
||||
--numOperands;
|
||||
|
||||
// save instruction for future reference
|
||||
idInstruction[resultId] = instructionStart;
|
||||
}
|
||||
|
||||
outputResultId(resultId);
|
||||
outputTypeId(typeId);
|
||||
outputIndent();
|
||||
|
||||
// Hand off the Op and all its operands
|
||||
disassembleInstruction(resultId, typeId, opCode, numOperands);
|
||||
if (word != nextInst) {
|
||||
out << " ERROR, incorrect number of operands consumed. At " << word << " instead of " << nextInst << " instruction start was " << instructionStart;
|
||||
word = nextInst;
|
||||
}
|
||||
out << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void SpirvStream::outputIndent()
|
||||
{
|
||||
for (int i = 0; i < (int)nestedControl.size(); ++i)
|
||||
out << " ";
|
||||
}
|
||||
|
||||
void SpirvStream::formatId(Id id, std::stringstream& idStream)
|
||||
{
|
||||
if (id != 0) {
|
||||
// On instructions with no IDs, this is called with "0", which does not
|
||||
// have to be within ID bounds on null shaders.
|
||||
if (id >= bound)
|
||||
Kill(out, "Bad <id>");
|
||||
|
||||
idStream << id;
|
||||
if (idDescriptor[id].size() > 0)
|
||||
idStream << "(" << idDescriptor[id] << ")";
|
||||
}
|
||||
}
|
||||
|
||||
void SpirvStream::outputResultId(Id id)
|
||||
{
|
||||
const int width = 16;
|
||||
std::stringstream idStream;
|
||||
formatId(id, idStream);
|
||||
out << std::setw(width) << std::right << idStream.str();
|
||||
if (id != 0)
|
||||
out << ":";
|
||||
else
|
||||
out << " ";
|
||||
|
||||
if (nestedControl.size() && id == nestedControl.top())
|
||||
nestedControl.pop();
|
||||
}
|
||||
|
||||
void SpirvStream::outputTypeId(Id id)
|
||||
{
|
||||
const int width = 12;
|
||||
std::stringstream idStream;
|
||||
formatId(id, idStream);
|
||||
out << std::setw(width) << std::right << idStream.str() << " ";
|
||||
}
|
||||
|
||||
void SpirvStream::outputId(Id id)
|
||||
{
|
||||
if (id >= bound)
|
||||
Kill(out, "Bad <id>");
|
||||
|
||||
out << id;
|
||||
if (idDescriptor[id].size() > 0)
|
||||
out << "(" << idDescriptor[id] << ")";
|
||||
}
|
||||
|
||||
void SpirvStream::outputMask(OperandClass operandClass, unsigned mask)
|
||||
{
|
||||
if (mask == 0)
|
||||
out << "None";
|
||||
else {
|
||||
for (int m = 0; m < OperandClassParams[operandClass].ceiling; ++m) {
|
||||
if (mask & (1 << m))
|
||||
out << OperandClassParams[operandClass].getName(m) << " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpirvStream::disassembleImmediates(int numOperands)
|
||||
{
|
||||
for (int i = 0; i < numOperands; ++i) {
|
||||
out << stream[word++];
|
||||
if (i < numOperands - 1)
|
||||
out << " ";
|
||||
}
|
||||
}
|
||||
|
||||
void SpirvStream::disassembleIds(int numOperands)
|
||||
{
|
||||
for (int i = 0; i < numOperands; ++i) {
|
||||
outputId(stream[word++]);
|
||||
if (i < numOperands - 1)
|
||||
out << " ";
|
||||
}
|
||||
}
|
||||
|
||||
// decode string from words at current position (non-consuming)
|
||||
std::pair<int, std::string> SpirvStream::decodeString()
|
||||
{
|
||||
std::string res;
|
||||
int wordPos = word;
|
||||
char c;
|
||||
bool done = false;
|
||||
|
||||
do {
|
||||
unsigned int content = stream[wordPos];
|
||||
for (int charCount = 0; charCount < 4; ++charCount) {
|
||||
c = content & 0xff;
|
||||
content >>= 8;
|
||||
if (c == '\0') {
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
res += c;
|
||||
}
|
||||
++wordPos;
|
||||
} while(! done);
|
||||
|
||||
return std::make_pair(wordPos - word, res);
|
||||
}
|
||||
|
||||
// return the number of operands consumed by the string
|
||||
int SpirvStream::disassembleString()
|
||||
{
|
||||
out << " \"";
|
||||
|
||||
std::pair<int, std::string> decoderes = decodeString();
|
||||
|
||||
out << decoderes.second;
|
||||
out << "\"";
|
||||
|
||||
word += decoderes.first;
|
||||
|
||||
return decoderes.first;
|
||||
}
|
||||
|
||||
void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode, int numOperands)
|
||||
{
|
||||
// Process the opcode
|
||||
|
||||
out << (OpcodeString(opCode) + 2); // leave out the "Op"
|
||||
|
||||
if (opCode == OpLoopMerge || opCode == OpSelectionMerge)
|
||||
nextNestedControl = stream[word];
|
||||
else if (opCode == OpBranchConditional || opCode == OpSwitch) {
|
||||
if (nextNestedControl) {
|
||||
nestedControl.push(nextNestedControl);
|
||||
nextNestedControl = 0;
|
||||
}
|
||||
} else if (opCode == OpExtInstImport) {
|
||||
idDescriptor[resultId] = decodeString().second;
|
||||
}
|
||||
else {
|
||||
if (resultId != 0 && idDescriptor[resultId].size() == 0) {
|
||||
switch (opCode) {
|
||||
case OpTypeInt:
|
||||
switch (stream[word]) {
|
||||
case 8: idDescriptor[resultId] = "int8_t"; break;
|
||||
case 16: idDescriptor[resultId] = "int16_t"; break;
|
||||
default: assert(0); // fallthrough
|
||||
case 32: idDescriptor[resultId] = "int"; break;
|
||||
case 64: idDescriptor[resultId] = "int64_t"; break;
|
||||
}
|
||||
break;
|
||||
case OpTypeFloat:
|
||||
switch (stream[word]) {
|
||||
case 16: idDescriptor[resultId] = "float16_t"; break;
|
||||
default: assert(0); // fallthrough
|
||||
case 32: idDescriptor[resultId] = "float"; break;
|
||||
case 64: idDescriptor[resultId] = "float64_t"; break;
|
||||
}
|
||||
break;
|
||||
case OpTypeBool:
|
||||
idDescriptor[resultId] = "bool";
|
||||
break;
|
||||
case OpTypeStruct:
|
||||
idDescriptor[resultId] = "struct";
|
||||
break;
|
||||
case OpTypePointer:
|
||||
idDescriptor[resultId] = "ptr";
|
||||
break;
|
||||
case OpTypeVector:
|
||||
if (idDescriptor[stream[word]].size() > 0) {
|
||||
idDescriptor[resultId].append(idDescriptor[stream[word]].begin(), idDescriptor[stream[word]].begin() + 1);
|
||||
if (strstr(idDescriptor[stream[word]].c_str(), "8")) {
|
||||
idDescriptor[resultId].append("8");
|
||||
}
|
||||
if (strstr(idDescriptor[stream[word]].c_str(), "16")) {
|
||||
idDescriptor[resultId].append("16");
|
||||
}
|
||||
if (strstr(idDescriptor[stream[word]].c_str(), "64")) {
|
||||
idDescriptor[resultId].append("64");
|
||||
}
|
||||
}
|
||||
idDescriptor[resultId].append("vec");
|
||||
switch (stream[word + 1]) {
|
||||
case 2: idDescriptor[resultId].append("2"); break;
|
||||
case 3: idDescriptor[resultId].append("3"); break;
|
||||
case 4: idDescriptor[resultId].append("4"); break;
|
||||
case 8: idDescriptor[resultId].append("8"); break;
|
||||
case 16: idDescriptor[resultId].append("16"); break;
|
||||
case 32: idDescriptor[resultId].append("32"); break;
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process the operands. Note, a new context-dependent set could be
|
||||
// swapped in mid-traversal.
|
||||
|
||||
// Handle images specially, so can put out helpful strings.
|
||||
if (opCode == OpTypeImage) {
|
||||
out << " ";
|
||||
disassembleIds(1);
|
||||
out << " " << DimensionString((Dim)stream[word++]);
|
||||
out << (stream[word++] != 0 ? " depth" : "");
|
||||
out << (stream[word++] != 0 ? " array" : "");
|
||||
out << (stream[word++] != 0 ? " multi-sampled" : "");
|
||||
switch (stream[word++]) {
|
||||
case 0: out << " runtime"; break;
|
||||
case 1: out << " sampled"; break;
|
||||
case 2: out << " nonsampled"; break;
|
||||
}
|
||||
out << " format:" << ImageFormatString((ImageFormat)stream[word++]);
|
||||
|
||||
if (numOperands == 8) {
|
||||
out << " " << AccessQualifierString(stream[word++]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle all the parameterized operands
|
||||
for (int op = 0; op < InstructionDesc[opCode].operands.getNum() && numOperands > 0; ++op) {
|
||||
out << " ";
|
||||
OperandClass operandClass = InstructionDesc[opCode].operands.getClass(op);
|
||||
switch (operandClass) {
|
||||
case OperandId:
|
||||
case OperandScope:
|
||||
case OperandMemorySemantics:
|
||||
disassembleIds(1);
|
||||
--numOperands;
|
||||
// Get names for printing "(XXX)" for readability, *after* this id
|
||||
if (opCode == OpName)
|
||||
idDescriptor[stream[word - 1]] = decodeString().second;
|
||||
break;
|
||||
case OperandVariableIds:
|
||||
disassembleIds(numOperands);
|
||||
return;
|
||||
case OperandImageOperands:
|
||||
outputMask(OperandImageOperands, stream[word++]);
|
||||
--numOperands;
|
||||
disassembleIds(numOperands);
|
||||
return;
|
||||
case OperandOptionalLiteral:
|
||||
case OperandVariableLiterals:
|
||||
if ((opCode == OpDecorate && stream[word - 1] == DecorationBuiltIn) ||
|
||||
(opCode == OpMemberDecorate && stream[word - 1] == DecorationBuiltIn)) {
|
||||
out << BuiltInString(stream[word++]);
|
||||
--numOperands;
|
||||
++op;
|
||||
}
|
||||
disassembleImmediates(numOperands);
|
||||
return;
|
||||
case OperandVariableIdLiteral:
|
||||
while (numOperands > 0) {
|
||||
out << std::endl;
|
||||
outputResultId(0);
|
||||
outputTypeId(0);
|
||||
outputIndent();
|
||||
out << " Type ";
|
||||
disassembleIds(1);
|
||||
out << ", member ";
|
||||
disassembleImmediates(1);
|
||||
numOperands -= 2;
|
||||
}
|
||||
return;
|
||||
case OperandVariableLiteralId:
|
||||
while (numOperands > 0) {
|
||||
out << std::endl;
|
||||
outputResultId(0);
|
||||
outputTypeId(0);
|
||||
outputIndent();
|
||||
out << " case ";
|
||||
disassembleImmediates(1);
|
||||
out << ": ";
|
||||
disassembleIds(1);
|
||||
numOperands -= 2;
|
||||
}
|
||||
return;
|
||||
case OperandLiteralNumber:
|
||||
disassembleImmediates(1);
|
||||
--numOperands;
|
||||
if (opCode == OpExtInst) {
|
||||
ExtInstSet extInstSet = GLSL450Inst;
|
||||
const char* name = idDescriptor[stream[word - 2]].c_str();
|
||||
if (strcmp("OpenCL.std", name) == 0) {
|
||||
extInstSet = OpenCLExtInst;
|
||||
} else if (strcmp("OpenCL.DebugInfo.100", name) == 0) {
|
||||
extInstSet = OpenCLExtInst;
|
||||
} else if (strcmp("NonSemantic.DebugPrintf", name) == 0) {
|
||||
extInstSet = NonSemanticDebugPrintfExtInst;
|
||||
} else if (strcmp(spv::E_SPV_AMD_shader_ballot, name) == 0 ||
|
||||
strcmp(spv::E_SPV_AMD_shader_trinary_minmax, name) == 0 ||
|
||||
strcmp(spv::E_SPV_AMD_shader_explicit_vertex_parameter, name) == 0 ||
|
||||
strcmp(spv::E_SPV_AMD_gcn_shader, name) == 0) {
|
||||
extInstSet = GLSLextAMDInst;
|
||||
} else if (strcmp(spv::E_SPV_NV_sample_mask_override_coverage, name) == 0 ||
|
||||
strcmp(spv::E_SPV_NV_geometry_shader_passthrough, name) == 0 ||
|
||||
strcmp(spv::E_SPV_NV_viewport_array2, name) == 0 ||
|
||||
strcmp(spv::E_SPV_NVX_multiview_per_view_attributes, name) == 0 ||
|
||||
strcmp(spv::E_SPV_NV_fragment_shader_barycentric, name) == 0 ||
|
||||
strcmp(spv::E_SPV_NV_mesh_shader, name) == 0) {
|
||||
extInstSet = GLSLextNVInst;
|
||||
}
|
||||
unsigned entrypoint = stream[word - 1];
|
||||
if (extInstSet == GLSL450Inst) {
|
||||
if (entrypoint < GLSLstd450Count) {
|
||||
out << "(" << GlslStd450DebugNames[entrypoint] << ")";
|
||||
}
|
||||
} else if (extInstSet == GLSLextAMDInst) {
|
||||
out << "(" << GLSLextAMDGetDebugNames(name, entrypoint) << ")";
|
||||
}
|
||||
else if (extInstSet == GLSLextNVInst) {
|
||||
out << "(" << GLSLextNVGetDebugNames(name, entrypoint) << ")";
|
||||
} else if (extInstSet == NonSemanticDebugPrintfExtInst) {
|
||||
out << "(DebugPrintf)";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OperandOptionalLiteralString:
|
||||
case OperandLiteralString:
|
||||
numOperands -= disassembleString();
|
||||
break;
|
||||
case OperandVariableLiteralStrings:
|
||||
while (numOperands > 0)
|
||||
numOperands -= disassembleString();
|
||||
return;
|
||||
case OperandMemoryAccess:
|
||||
outputMask(OperandMemoryAccess, stream[word++]);
|
||||
--numOperands;
|
||||
// Aligned is the only memory access operand that uses an immediate
|
||||
// value, and it is also the first operand that uses a value at all.
|
||||
if (stream[word-1] & MemoryAccessAlignedMask) {
|
||||
disassembleImmediates(1);
|
||||
numOperands--;
|
||||
if (numOperands)
|
||||
out << " ";
|
||||
}
|
||||
disassembleIds(numOperands);
|
||||
return;
|
||||
default:
|
||||
assert(operandClass >= OperandSource && operandClass < OperandOpcode);
|
||||
|
||||
if (OperandClassParams[operandClass].bitmask)
|
||||
outputMask(operandClass, stream[word++]);
|
||||
else
|
||||
out << OperandClassParams[operandClass].getName(stream[word++]);
|
||||
--numOperands;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void GLSLstd450GetDebugNames(const char** names)
|
||||
{
|
||||
for (int i = 0; i < GLSLstd450Count; ++i)
|
||||
names[i] = "Unknown";
|
||||
|
||||
names[GLSLstd450Round] = "Round";
|
||||
names[GLSLstd450RoundEven] = "RoundEven";
|
||||
names[GLSLstd450Trunc] = "Trunc";
|
||||
names[GLSLstd450FAbs] = "FAbs";
|
||||
names[GLSLstd450SAbs] = "SAbs";
|
||||
names[GLSLstd450FSign] = "FSign";
|
||||
names[GLSLstd450SSign] = "SSign";
|
||||
names[GLSLstd450Floor] = "Floor";
|
||||
names[GLSLstd450Ceil] = "Ceil";
|
||||
names[GLSLstd450Fract] = "Fract";
|
||||
names[GLSLstd450Radians] = "Radians";
|
||||
names[GLSLstd450Degrees] = "Degrees";
|
||||
names[GLSLstd450Sin] = "Sin";
|
||||
names[GLSLstd450Cos] = "Cos";
|
||||
names[GLSLstd450Tan] = "Tan";
|
||||
names[GLSLstd450Asin] = "Asin";
|
||||
names[GLSLstd450Acos] = "Acos";
|
||||
names[GLSLstd450Atan] = "Atan";
|
||||
names[GLSLstd450Sinh] = "Sinh";
|
||||
names[GLSLstd450Cosh] = "Cosh";
|
||||
names[GLSLstd450Tanh] = "Tanh";
|
||||
names[GLSLstd450Asinh] = "Asinh";
|
||||
names[GLSLstd450Acosh] = "Acosh";
|
||||
names[GLSLstd450Atanh] = "Atanh";
|
||||
names[GLSLstd450Atan2] = "Atan2";
|
||||
names[GLSLstd450Pow] = "Pow";
|
||||
names[GLSLstd450Exp] = "Exp";
|
||||
names[GLSLstd450Log] = "Log";
|
||||
names[GLSLstd450Exp2] = "Exp2";
|
||||
names[GLSLstd450Log2] = "Log2";
|
||||
names[GLSLstd450Sqrt] = "Sqrt";
|
||||
names[GLSLstd450InverseSqrt] = "InverseSqrt";
|
||||
names[GLSLstd450Determinant] = "Determinant";
|
||||
names[GLSLstd450MatrixInverse] = "MatrixInverse";
|
||||
names[GLSLstd450Modf] = "Modf";
|
||||
names[GLSLstd450ModfStruct] = "ModfStruct";
|
||||
names[GLSLstd450FMin] = "FMin";
|
||||
names[GLSLstd450SMin] = "SMin";
|
||||
names[GLSLstd450UMin] = "UMin";
|
||||
names[GLSLstd450FMax] = "FMax";
|
||||
names[GLSLstd450SMax] = "SMax";
|
||||
names[GLSLstd450UMax] = "UMax";
|
||||
names[GLSLstd450FClamp] = "FClamp";
|
||||
names[GLSLstd450SClamp] = "SClamp";
|
||||
names[GLSLstd450UClamp] = "UClamp";
|
||||
names[GLSLstd450FMix] = "FMix";
|
||||
names[GLSLstd450Step] = "Step";
|
||||
names[GLSLstd450SmoothStep] = "SmoothStep";
|
||||
names[GLSLstd450Fma] = "Fma";
|
||||
names[GLSLstd450Frexp] = "Frexp";
|
||||
names[GLSLstd450FrexpStruct] = "FrexpStruct";
|
||||
names[GLSLstd450Ldexp] = "Ldexp";
|
||||
names[GLSLstd450PackSnorm4x8] = "PackSnorm4x8";
|
||||
names[GLSLstd450PackUnorm4x8] = "PackUnorm4x8";
|
||||
names[GLSLstd450PackSnorm2x16] = "PackSnorm2x16";
|
||||
names[GLSLstd450PackUnorm2x16] = "PackUnorm2x16";
|
||||
names[GLSLstd450PackHalf2x16] = "PackHalf2x16";
|
||||
names[GLSLstd450PackDouble2x32] = "PackDouble2x32";
|
||||
names[GLSLstd450UnpackSnorm2x16] = "UnpackSnorm2x16";
|
||||
names[GLSLstd450UnpackUnorm2x16] = "UnpackUnorm2x16";
|
||||
names[GLSLstd450UnpackHalf2x16] = "UnpackHalf2x16";
|
||||
names[GLSLstd450UnpackSnorm4x8] = "UnpackSnorm4x8";
|
||||
names[GLSLstd450UnpackUnorm4x8] = "UnpackUnorm4x8";
|
||||
names[GLSLstd450UnpackDouble2x32] = "UnpackDouble2x32";
|
||||
names[GLSLstd450Length] = "Length";
|
||||
names[GLSLstd450Distance] = "Distance";
|
||||
names[GLSLstd450Cross] = "Cross";
|
||||
names[GLSLstd450Normalize] = "Normalize";
|
||||
names[GLSLstd450FaceForward] = "FaceForward";
|
||||
names[GLSLstd450Reflect] = "Reflect";
|
||||
names[GLSLstd450Refract] = "Refract";
|
||||
names[GLSLstd450FindILsb] = "FindILsb";
|
||||
names[GLSLstd450FindSMsb] = "FindSMsb";
|
||||
names[GLSLstd450FindUMsb] = "FindUMsb";
|
||||
names[GLSLstd450InterpolateAtCentroid] = "InterpolateAtCentroid";
|
||||
names[GLSLstd450InterpolateAtSample] = "InterpolateAtSample";
|
||||
names[GLSLstd450InterpolateAtOffset] = "InterpolateAtOffset";
|
||||
names[GLSLstd450NMin] = "NMin";
|
||||
names[GLSLstd450NMax] = "NMax";
|
||||
names[GLSLstd450NClamp] = "NClamp";
|
||||
}
|
||||
|
||||
static const char* GLSLextAMDGetDebugNames(const char* name, unsigned entrypoint)
|
||||
{
|
||||
if (strcmp(name, spv::E_SPV_AMD_shader_ballot) == 0) {
|
||||
switch (entrypoint) {
|
||||
case SwizzleInvocationsAMD: return "SwizzleInvocationsAMD";
|
||||
case SwizzleInvocationsMaskedAMD: return "SwizzleInvocationsMaskedAMD";
|
||||
case WriteInvocationAMD: return "WriteInvocationAMD";
|
||||
case MbcntAMD: return "MbcntAMD";
|
||||
default: return "Bad";
|
||||
}
|
||||
} else if (strcmp(name, spv::E_SPV_AMD_shader_trinary_minmax) == 0) {
|
||||
switch (entrypoint) {
|
||||
case FMin3AMD: return "FMin3AMD";
|
||||
case UMin3AMD: return "UMin3AMD";
|
||||
case SMin3AMD: return "SMin3AMD";
|
||||
case FMax3AMD: return "FMax3AMD";
|
||||
case UMax3AMD: return "UMax3AMD";
|
||||
case SMax3AMD: return "SMax3AMD";
|
||||
case FMid3AMD: return "FMid3AMD";
|
||||
case UMid3AMD: return "UMid3AMD";
|
||||
case SMid3AMD: return "SMid3AMD";
|
||||
default: return "Bad";
|
||||
}
|
||||
} else if (strcmp(name, spv::E_SPV_AMD_shader_explicit_vertex_parameter) == 0) {
|
||||
switch (entrypoint) {
|
||||
case InterpolateAtVertexAMD: return "InterpolateAtVertexAMD";
|
||||
default: return "Bad";
|
||||
}
|
||||
}
|
||||
else if (strcmp(name, spv::E_SPV_AMD_gcn_shader) == 0) {
|
||||
switch (entrypoint) {
|
||||
case CubeFaceIndexAMD: return "CubeFaceIndexAMD";
|
||||
case CubeFaceCoordAMD: return "CubeFaceCoordAMD";
|
||||
case TimeAMD: return "TimeAMD";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return "Bad";
|
||||
}
|
||||
|
||||
static const char* GLSLextNVGetDebugNames(const char* name, unsigned entrypoint)
|
||||
{
|
||||
if (strcmp(name, spv::E_SPV_NV_sample_mask_override_coverage) == 0 ||
|
||||
strcmp(name, spv::E_SPV_NV_geometry_shader_passthrough) == 0 ||
|
||||
strcmp(name, spv::E_ARB_shader_viewport_layer_array) == 0 ||
|
||||
strcmp(name, spv::E_SPV_NV_viewport_array2) == 0 ||
|
||||
strcmp(name, spv::E_SPV_NVX_multiview_per_view_attributes) == 0 ||
|
||||
strcmp(name, spv::E_SPV_NV_fragment_shader_barycentric) == 0 ||
|
||||
strcmp(name, spv::E_SPV_NV_mesh_shader) == 0 ||
|
||||
strcmp(name, spv::E_SPV_NV_shader_image_footprint) == 0) {
|
||||
switch (entrypoint) {
|
||||
// NV builtins
|
||||
case BuiltInViewportMaskNV: return "ViewportMaskNV";
|
||||
case BuiltInSecondaryPositionNV: return "SecondaryPositionNV";
|
||||
case BuiltInSecondaryViewportMaskNV: return "SecondaryViewportMaskNV";
|
||||
case BuiltInPositionPerViewNV: return "PositionPerViewNV";
|
||||
case BuiltInViewportMaskPerViewNV: return "ViewportMaskPerViewNV";
|
||||
case BuiltInBaryCoordNV: return "BaryCoordNV";
|
||||
case BuiltInBaryCoordNoPerspNV: return "BaryCoordNoPerspNV";
|
||||
case BuiltInTaskCountNV: return "TaskCountNV";
|
||||
case BuiltInPrimitiveCountNV: return "PrimitiveCountNV";
|
||||
case BuiltInPrimitiveIndicesNV: return "PrimitiveIndicesNV";
|
||||
case BuiltInClipDistancePerViewNV: return "ClipDistancePerViewNV";
|
||||
case BuiltInCullDistancePerViewNV: return "CullDistancePerViewNV";
|
||||
case BuiltInLayerPerViewNV: return "LayerPerViewNV";
|
||||
case BuiltInMeshViewCountNV: return "MeshViewCountNV";
|
||||
case BuiltInMeshViewIndicesNV: return "MeshViewIndicesNV";
|
||||
|
||||
// NV Capabilities
|
||||
case CapabilityGeometryShaderPassthroughNV: return "GeometryShaderPassthroughNV";
|
||||
case CapabilityShaderViewportMaskNV: return "ShaderViewportMaskNV";
|
||||
case CapabilityShaderStereoViewNV: return "ShaderStereoViewNV";
|
||||
case CapabilityPerViewAttributesNV: return "PerViewAttributesNV";
|
||||
case CapabilityFragmentBarycentricNV: return "FragmentBarycentricNV";
|
||||
case CapabilityMeshShadingNV: return "MeshShadingNV";
|
||||
case CapabilityImageFootprintNV: return "ImageFootprintNV";
|
||||
case CapabilitySampleMaskOverrideCoverageNV:return "SampleMaskOverrideCoverageNV";
|
||||
|
||||
// NV Decorations
|
||||
case DecorationOverrideCoverageNV: return "OverrideCoverageNV";
|
||||
case DecorationPassthroughNV: return "PassthroughNV";
|
||||
case DecorationViewportRelativeNV: return "ViewportRelativeNV";
|
||||
case DecorationSecondaryViewportRelativeNV: return "SecondaryViewportRelativeNV";
|
||||
case DecorationPerVertexNV: return "PerVertexNV";
|
||||
case DecorationPerPrimitiveNV: return "PerPrimitiveNV";
|
||||
case DecorationPerViewNV: return "PerViewNV";
|
||||
case DecorationPerTaskNV: return "PerTaskNV";
|
||||
|
||||
default: return "Bad";
|
||||
}
|
||||
}
|
||||
return "Bad";
|
||||
}
|
||||
|
||||
void Disassemble(std::ostream& out, const std::vector<unsigned int>& stream)
|
||||
{
|
||||
SpirvStream SpirvStream(out, stream);
|
||||
spv::Parameterize();
|
||||
GLSLstd450GetDebugNames(GlslStd450DebugNames);
|
||||
SpirvStream.validate();
|
||||
SpirvStream.processInstructions();
|
||||
}
|
||||
|
||||
}; // end namespace spv
|
||||
53
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/disassemble.h
vendored
Normal file
53
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/disassemble.h
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
//
|
||||
// Copyright (C) 2014-2015 LunarG, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// Disassembler for SPIR-V.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#ifndef disassembler_H
|
||||
#define disassembler_H
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
namespace spv {
|
||||
|
||||
// disassemble with glslang custom disassembler
|
||||
void Disassemble(std::ostream& out, const std::vector<unsigned int>&);
|
||||
|
||||
} // end namespace spv
|
||||
|
||||
#endif // disassembler_H
|
||||
3035
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/doc.cpp
vendored
Normal file
3035
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/doc.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
259
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/doc.h
vendored
Normal file
259
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/doc.h
vendored
Normal file
@ -0,0 +1,259 @@
|
||||
//
|
||||
// Copyright (C) 2014-2015 LunarG, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// Parameterize the SPIR-V enumerants.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "spirv.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace spv {
|
||||
|
||||
// Fill in all the parameters
|
||||
void Parameterize();
|
||||
|
||||
// Return the English names of all the enums.
|
||||
const char* SourceString(int);
|
||||
const char* AddressingString(int);
|
||||
const char* MemoryString(int);
|
||||
const char* ExecutionModelString(int);
|
||||
const char* ExecutionModeString(int);
|
||||
const char* StorageClassString(int);
|
||||
const char* DecorationString(int);
|
||||
const char* BuiltInString(int);
|
||||
const char* DimensionString(int);
|
||||
const char* SelectControlString(int);
|
||||
const char* LoopControlString(int);
|
||||
const char* FunctionControlString(int);
|
||||
const char* SamplerAddressingModeString(int);
|
||||
const char* SamplerFilterModeString(int);
|
||||
const char* ImageFormatString(int);
|
||||
const char* ImageChannelOrderString(int);
|
||||
const char* ImageChannelTypeString(int);
|
||||
const char* ImageChannelDataTypeString(int type);
|
||||
const char* ImageOperandsString(int format);
|
||||
const char* ImageOperands(int);
|
||||
const char* FPFastMathString(int);
|
||||
const char* FPRoundingModeString(int);
|
||||
const char* LinkageTypeString(int);
|
||||
const char* FuncParamAttrString(int);
|
||||
const char* AccessQualifierString(int);
|
||||
const char* MemorySemanticsString(int);
|
||||
const char* MemoryAccessString(int);
|
||||
const char* ExecutionScopeString(int);
|
||||
const char* GroupOperationString(int);
|
||||
const char* KernelEnqueueFlagsString(int);
|
||||
const char* KernelProfilingInfoString(int);
|
||||
const char* CapabilityString(int);
|
||||
const char* OpcodeString(int);
|
||||
const char* ScopeString(int mem);
|
||||
|
||||
// For grouping opcodes into subsections
|
||||
enum OpcodeClass {
|
||||
OpClassMisc,
|
||||
OpClassDebug,
|
||||
OpClassAnnotate,
|
||||
OpClassExtension,
|
||||
OpClassMode,
|
||||
OpClassType,
|
||||
OpClassConstant,
|
||||
OpClassMemory,
|
||||
OpClassFunction,
|
||||
OpClassImage,
|
||||
OpClassConvert,
|
||||
OpClassComposite,
|
||||
OpClassArithmetic,
|
||||
OpClassBit,
|
||||
OpClassRelationalLogical,
|
||||
OpClassDerivative,
|
||||
OpClassFlowControl,
|
||||
OpClassAtomic,
|
||||
OpClassPrimitive,
|
||||
OpClassBarrier,
|
||||
OpClassGroup,
|
||||
OpClassDeviceSideEnqueue,
|
||||
OpClassPipe,
|
||||
|
||||
OpClassCount,
|
||||
OpClassMissing // all instructions start out as missing
|
||||
};
|
||||
|
||||
// For parameterizing operands.
|
||||
enum OperandClass {
|
||||
OperandNone,
|
||||
OperandId,
|
||||
OperandVariableIds,
|
||||
OperandOptionalLiteral,
|
||||
OperandOptionalLiteralString,
|
||||
OperandVariableLiterals,
|
||||
OperandVariableIdLiteral,
|
||||
OperandVariableLiteralId,
|
||||
OperandLiteralNumber,
|
||||
OperandLiteralString,
|
||||
OperandVariableLiteralStrings,
|
||||
OperandSource,
|
||||
OperandExecutionModel,
|
||||
OperandAddressing,
|
||||
OperandMemory,
|
||||
OperandExecutionMode,
|
||||
OperandStorage,
|
||||
OperandDimensionality,
|
||||
OperandSamplerAddressingMode,
|
||||
OperandSamplerFilterMode,
|
||||
OperandSamplerImageFormat,
|
||||
OperandImageChannelOrder,
|
||||
OperandImageChannelDataType,
|
||||
OperandImageOperands,
|
||||
OperandFPFastMath,
|
||||
OperandFPRoundingMode,
|
||||
OperandLinkageType,
|
||||
OperandAccessQualifier,
|
||||
OperandFuncParamAttr,
|
||||
OperandDecoration,
|
||||
OperandBuiltIn,
|
||||
OperandSelect,
|
||||
OperandLoop,
|
||||
OperandFunction,
|
||||
OperandMemorySemantics,
|
||||
OperandMemoryAccess,
|
||||
OperandScope,
|
||||
OperandGroupOperation,
|
||||
OperandKernelEnqueueFlags,
|
||||
OperandKernelProfilingInfo,
|
||||
OperandCapability,
|
||||
|
||||
OperandOpcode,
|
||||
|
||||
OperandCount
|
||||
};
|
||||
|
||||
// Any specific enum can have a set of capabilities that allow it:
|
||||
typedef std::vector<Capability> EnumCaps;
|
||||
|
||||
// Parameterize a set of operands with their OperandClass(es) and descriptions.
|
||||
class OperandParameters {
|
||||
public:
|
||||
OperandParameters() { }
|
||||
void push(OperandClass oc, const char* d, bool opt = false)
|
||||
{
|
||||
opClass.push_back(oc);
|
||||
desc.push_back(d);
|
||||
optional.push_back(opt);
|
||||
}
|
||||
void setOptional();
|
||||
OperandClass getClass(int op) const { return opClass[op]; }
|
||||
const char* getDesc(int op) const { return desc[op]; }
|
||||
bool isOptional(int op) const { return optional[op]; }
|
||||
int getNum() const { return (int)opClass.size(); }
|
||||
|
||||
protected:
|
||||
std::vector<OperandClass> opClass;
|
||||
std::vector<const char*> desc;
|
||||
std::vector<bool> optional;
|
||||
};
|
||||
|
||||
// Parameterize an enumerant
|
||||
class EnumParameters {
|
||||
public:
|
||||
EnumParameters() : desc(0) { }
|
||||
const char* desc;
|
||||
};
|
||||
|
||||
// Parameterize a set of enumerants that form an enum
|
||||
class EnumDefinition : public EnumParameters {
|
||||
public:
|
||||
EnumDefinition() :
|
||||
ceiling(0), bitmask(false), getName(0), enumParams(0), operandParams(0) { }
|
||||
void set(int ceil, const char* (*name)(int), EnumParameters* ep, bool mask = false)
|
||||
{
|
||||
ceiling = ceil;
|
||||
getName = name;
|
||||
bitmask = mask;
|
||||
enumParams = ep;
|
||||
}
|
||||
void setOperands(OperandParameters* op) { operandParams = op; }
|
||||
int ceiling; // ceiling of enumerants
|
||||
bool bitmask; // true if these enumerants combine into a bitmask
|
||||
const char* (*getName)(int); // a function that returns the name for each enumerant value (or shift)
|
||||
EnumParameters* enumParams; // parameters for each individual enumerant
|
||||
OperandParameters* operandParams; // sets of operands
|
||||
};
|
||||
|
||||
// Parameterize an instruction's logical format, including its known set of operands,
|
||||
// per OperandParameters above.
|
||||
class InstructionParameters {
|
||||
public:
|
||||
InstructionParameters() :
|
||||
opDesc("TBD"),
|
||||
opClass(OpClassMissing),
|
||||
typePresent(true), // most normal, only exceptions have to be spelled out
|
||||
resultPresent(true) // most normal, only exceptions have to be spelled out
|
||||
{ }
|
||||
|
||||
void setResultAndType(bool r, bool t)
|
||||
{
|
||||
resultPresent = r;
|
||||
typePresent = t;
|
||||
}
|
||||
|
||||
bool hasResult() const { return resultPresent != 0; }
|
||||
bool hasType() const { return typePresent != 0; }
|
||||
|
||||
const char* opDesc;
|
||||
OpcodeClass opClass;
|
||||
OperandParameters operands;
|
||||
|
||||
protected:
|
||||
int typePresent : 1;
|
||||
int resultPresent : 1;
|
||||
};
|
||||
|
||||
// The set of objects that hold all the instruction/operand
|
||||
// parameterization information.
|
||||
extern InstructionParameters InstructionDesc[];
|
||||
|
||||
// These hold definitions of the enumerants used for operands
|
||||
extern EnumDefinition OperandClassParams[];
|
||||
|
||||
const char* GetOperandDesc(OperandClass operand);
|
||||
void PrintImmediateRow(int imm, const char* name, const EnumParameters* enumParams, bool caps, bool hex = false);
|
||||
const char* AccessQualifierString(int attr);
|
||||
|
||||
void PrintOperands(const OperandParameters& operands, int reservedOperands);
|
||||
|
||||
} // end namespace spv
|
||||
1078
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/hex_float.h
vendored
Normal file
1078
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/hex_float.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2533
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/spirv.hpp
vendored
Normal file
2533
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/spirv.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
520
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/spvIR.h
vendored
Normal file
520
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/SPIRV/spvIR.h
vendored
Normal file
@ -0,0 +1,520 @@
|
||||
//
|
||||
// Copyright (C) 2014 LunarG, Inc.
|
||||
// Copyright (C) 2015-2018 Google, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// SPIRV-IR
|
||||
//
|
||||
// Simple in-memory representation (IR) of SPIRV. Just for holding
|
||||
// Each function's CFG of blocks. Has this hierarchy:
|
||||
// - Module, which is a list of
|
||||
// - Function, which is a list of
|
||||
// - Block, which is a list of
|
||||
// - Instruction
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#ifndef spvIR_H
|
||||
#define spvIR_H
|
||||
|
||||
#include "spirv.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
namespace spv {
|
||||
|
||||
class Block;
|
||||
class Function;
|
||||
class Module;
|
||||
|
||||
const Id NoResult = 0;
|
||||
const Id NoType = 0;
|
||||
|
||||
const Decoration NoPrecision = DecorationMax;
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define POTENTIALLY_UNUSED __attribute__((unused))
|
||||
#else
|
||||
# define POTENTIALLY_UNUSED
|
||||
#endif
|
||||
|
||||
POTENTIALLY_UNUSED
|
||||
const MemorySemanticsMask MemorySemanticsAllMemory =
|
||||
(MemorySemanticsMask)(MemorySemanticsUniformMemoryMask |
|
||||
MemorySemanticsWorkgroupMemoryMask |
|
||||
MemorySemanticsAtomicCounterMemoryMask |
|
||||
MemorySemanticsImageMemoryMask);
|
||||
|
||||
struct IdImmediate {
|
||||
bool isId; // true if word is an Id, false if word is an immediate
|
||||
unsigned word;
|
||||
IdImmediate(bool i, unsigned w) : isId(i), word(w) {}
|
||||
};
|
||||
|
||||
//
|
||||
// SPIR-V IR instruction.
|
||||
//
|
||||
|
||||
class Instruction {
|
||||
public:
|
||||
Instruction(Id resultId, Id typeId, Op opCode) : resultId(resultId), typeId(typeId), opCode(opCode), block(nullptr) { }
|
||||
explicit Instruction(Op opCode) : resultId(NoResult), typeId(NoType), opCode(opCode), block(nullptr) { }
|
||||
virtual ~Instruction() {}
|
||||
void addIdOperand(Id id) {
|
||||
operands.push_back(id);
|
||||
idOperand.push_back(true);
|
||||
}
|
||||
void addImmediateOperand(unsigned int immediate) {
|
||||
operands.push_back(immediate);
|
||||
idOperand.push_back(false);
|
||||
}
|
||||
void setImmediateOperand(unsigned idx, unsigned int immediate) {
|
||||
assert(!idOperand[idx]);
|
||||
operands[idx] = immediate;
|
||||
}
|
||||
|
||||
void addStringOperand(const char* str)
|
||||
{
|
||||
unsigned int word = 0;
|
||||
unsigned int shiftAmount = 0;
|
||||
char c;
|
||||
|
||||
do {
|
||||
c = *(str++);
|
||||
word |= ((unsigned int)c) << shiftAmount;
|
||||
shiftAmount += 8;
|
||||
if (shiftAmount == 32) {
|
||||
addImmediateOperand(word);
|
||||
word = 0;
|
||||
shiftAmount = 0;
|
||||
}
|
||||
} while (c != 0);
|
||||
|
||||
// deal with partial last word
|
||||
if (shiftAmount > 0) {
|
||||
addImmediateOperand(word);
|
||||
}
|
||||
}
|
||||
bool isIdOperand(int op) const { return idOperand[op]; }
|
||||
void setBlock(Block* b) { block = b; }
|
||||
Block* getBlock() const { return block; }
|
||||
Op getOpCode() const { return opCode; }
|
||||
int getNumOperands() const
|
||||
{
|
||||
assert(operands.size() == idOperand.size());
|
||||
return (int)operands.size();
|
||||
}
|
||||
Id getResultId() const { return resultId; }
|
||||
Id getTypeId() const { return typeId; }
|
||||
Id getIdOperand(int op) const {
|
||||
assert(idOperand[op]);
|
||||
return operands[op];
|
||||
}
|
||||
unsigned int getImmediateOperand(int op) const {
|
||||
assert(!idOperand[op]);
|
||||
return operands[op];
|
||||
}
|
||||
|
||||
// Write out the binary form.
|
||||
void dump(std::vector<unsigned int>& out) const
|
||||
{
|
||||
// Compute the wordCount
|
||||
unsigned int wordCount = 1;
|
||||
if (typeId)
|
||||
++wordCount;
|
||||
if (resultId)
|
||||
++wordCount;
|
||||
wordCount += (unsigned int)operands.size();
|
||||
|
||||
// Write out the beginning of the instruction
|
||||
out.push_back(((wordCount) << WordCountShift) | opCode);
|
||||
if (typeId)
|
||||
out.push_back(typeId);
|
||||
if (resultId)
|
||||
out.push_back(resultId);
|
||||
|
||||
// Write out the operands
|
||||
for (int op = 0; op < (int)operands.size(); ++op)
|
||||
out.push_back(operands[op]);
|
||||
}
|
||||
|
||||
protected:
|
||||
Instruction(const Instruction&);
|
||||
Id resultId;
|
||||
Id typeId;
|
||||
Op opCode;
|
||||
std::vector<Id> operands; // operands, both <id> and immediates (both are unsigned int)
|
||||
std::vector<bool> idOperand; // true for operands that are <id>, false for immediates
|
||||
Block* block;
|
||||
};
|
||||
|
||||
//
|
||||
// SPIR-V IR block.
|
||||
//
|
||||
|
||||
class Block {
|
||||
public:
|
||||
Block(Id id, Function& parent);
|
||||
virtual ~Block()
|
||||
{
|
||||
}
|
||||
|
||||
Id getId() { return instructions.front()->getResultId(); }
|
||||
|
||||
Function& getParent() const { return parent; }
|
||||
void addInstruction(std::unique_ptr<Instruction> inst);
|
||||
void addPredecessor(Block* pred) { predecessors.push_back(pred); pred->successors.push_back(this);}
|
||||
void addLocalVariable(std::unique_ptr<Instruction> inst) { localVariables.push_back(std::move(inst)); }
|
||||
const std::vector<Block*>& getPredecessors() const { return predecessors; }
|
||||
const std::vector<Block*>& getSuccessors() const { return successors; }
|
||||
const std::vector<std::unique_ptr<Instruction> >& getInstructions() const {
|
||||
return instructions;
|
||||
}
|
||||
const std::vector<std::unique_ptr<Instruction> >& getLocalVariables() const { return localVariables; }
|
||||
void setUnreachable() { unreachable = true; }
|
||||
bool isUnreachable() const { return unreachable; }
|
||||
// Returns the block's merge instruction, if one exists (otherwise null).
|
||||
const Instruction* getMergeInstruction() const {
|
||||
if (instructions.size() < 2) return nullptr;
|
||||
const Instruction* nextToLast = (instructions.cend() - 2)->get();
|
||||
switch (nextToLast->getOpCode()) {
|
||||
case OpSelectionMerge:
|
||||
case OpLoopMerge:
|
||||
return nextToLast;
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Change this block into a canonical dead merge block. Delete instructions
|
||||
// as necessary. A canonical dead merge block has only an OpLabel and an
|
||||
// OpUnreachable.
|
||||
void rewriteAsCanonicalUnreachableMerge() {
|
||||
assert(localVariables.empty());
|
||||
// Delete all instructions except for the label.
|
||||
assert(instructions.size() > 0);
|
||||
instructions.resize(1);
|
||||
successors.clear();
|
||||
addInstruction(std::unique_ptr<Instruction>(new Instruction(OpUnreachable)));
|
||||
}
|
||||
// Change this block into a canonical dead continue target branching to the
|
||||
// given header ID. Delete instructions as necessary. A canonical dead continue
|
||||
// target has only an OpLabel and an unconditional branch back to the corresponding
|
||||
// header.
|
||||
void rewriteAsCanonicalUnreachableContinue(Block* header) {
|
||||
assert(localVariables.empty());
|
||||
// Delete all instructions except for the label.
|
||||
assert(instructions.size() > 0);
|
||||
instructions.resize(1);
|
||||
successors.clear();
|
||||
// Add OpBranch back to the header.
|
||||
assert(header != nullptr);
|
||||
Instruction* branch = new Instruction(OpBranch);
|
||||
branch->addIdOperand(header->getId());
|
||||
addInstruction(std::unique_ptr<Instruction>(branch));
|
||||
successors.push_back(header);
|
||||
}
|
||||
|
||||
bool isTerminated() const
|
||||
{
|
||||
switch (instructions.back()->getOpCode()) {
|
||||
case OpBranch:
|
||||
case OpBranchConditional:
|
||||
case OpSwitch:
|
||||
case OpKill:
|
||||
case OpTerminateInvocation:
|
||||
case OpReturn:
|
||||
case OpReturnValue:
|
||||
case OpUnreachable:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void dump(std::vector<unsigned int>& out) const
|
||||
{
|
||||
instructions[0]->dump(out);
|
||||
for (int i = 0; i < (int)localVariables.size(); ++i)
|
||||
localVariables[i]->dump(out);
|
||||
for (int i = 1; i < (int)instructions.size(); ++i)
|
||||
instructions[i]->dump(out);
|
||||
}
|
||||
|
||||
protected:
|
||||
Block(const Block&);
|
||||
Block& operator=(Block&);
|
||||
|
||||
// To enforce keeping parent and ownership in sync:
|
||||
friend Function;
|
||||
|
||||
std::vector<std::unique_ptr<Instruction> > instructions;
|
||||
std::vector<Block*> predecessors, successors;
|
||||
std::vector<std::unique_ptr<Instruction> > localVariables;
|
||||
Function& parent;
|
||||
|
||||
// track whether this block is known to be uncreachable (not necessarily
|
||||
// true for all unreachable blocks, but should be set at least
|
||||
// for the extraneous ones introduced by the builder).
|
||||
bool unreachable;
|
||||
};
|
||||
|
||||
// The different reasons for reaching a block in the inReadableOrder traversal.
|
||||
enum ReachReason {
|
||||
// Reachable from the entry block via transfers of control, i.e. branches.
|
||||
ReachViaControlFlow = 0,
|
||||
// A continue target that is not reachable via control flow.
|
||||
ReachDeadContinue,
|
||||
// A merge block that is not reachable via control flow.
|
||||
ReachDeadMerge
|
||||
};
|
||||
|
||||
// Traverses the control-flow graph rooted at root in an order suited for
|
||||
// readable code generation. Invokes callback at every node in the traversal
|
||||
// order. The callback arguments are:
|
||||
// - the block,
|
||||
// - the reason we reached the block,
|
||||
// - if the reason was that block is an unreachable continue or unreachable merge block
|
||||
// then the last parameter is the corresponding header block.
|
||||
void inReadableOrder(Block* root, std::function<void(Block*, ReachReason, Block* header)> callback);
|
||||
|
||||
//
|
||||
// SPIR-V IR Function.
|
||||
//
|
||||
|
||||
class Function {
|
||||
public:
|
||||
Function(Id id, Id resultType, Id functionType, Id firstParam, Module& parent);
|
||||
virtual ~Function()
|
||||
{
|
||||
for (int i = 0; i < (int)parameterInstructions.size(); ++i)
|
||||
delete parameterInstructions[i];
|
||||
|
||||
for (int i = 0; i < (int)blocks.size(); ++i)
|
||||
delete blocks[i];
|
||||
}
|
||||
Id getId() const { return functionInstruction.getResultId(); }
|
||||
Id getParamId(int p) const { return parameterInstructions[p]->getResultId(); }
|
||||
Id getParamType(int p) const { return parameterInstructions[p]->getTypeId(); }
|
||||
|
||||
void addBlock(Block* block) { blocks.push_back(block); }
|
||||
void removeBlock(Block* block)
|
||||
{
|
||||
auto found = find(blocks.begin(), blocks.end(), block);
|
||||
assert(found != blocks.end());
|
||||
blocks.erase(found);
|
||||
delete block;
|
||||
}
|
||||
|
||||
Module& getParent() const { return parent; }
|
||||
Block* getEntryBlock() const { return blocks.front(); }
|
||||
Block* getLastBlock() const { return blocks.back(); }
|
||||
const std::vector<Block*>& getBlocks() const { return blocks; }
|
||||
void addLocalVariable(std::unique_ptr<Instruction> inst);
|
||||
Id getReturnType() const { return functionInstruction.getTypeId(); }
|
||||
Id getFuncId() const { return functionInstruction.getResultId(); }
|
||||
void setReturnPrecision(Decoration precision)
|
||||
{
|
||||
if (precision == DecorationRelaxedPrecision)
|
||||
reducedPrecisionReturn = true;
|
||||
}
|
||||
Decoration getReturnPrecision() const
|
||||
{ return reducedPrecisionReturn ? DecorationRelaxedPrecision : NoPrecision; }
|
||||
|
||||
void setDebugLineInfo(Id fileName, int line, int column) {
|
||||
lineInstruction = std::unique_ptr<Instruction>{new Instruction(OpLine)};
|
||||
lineInstruction->addIdOperand(fileName);
|
||||
lineInstruction->addImmediateOperand(line);
|
||||
lineInstruction->addImmediateOperand(column);
|
||||
}
|
||||
bool hasDebugLineInfo() const { return lineInstruction != nullptr; }
|
||||
|
||||
void setImplicitThis() { implicitThis = true; }
|
||||
bool hasImplicitThis() const { return implicitThis; }
|
||||
|
||||
void addParamPrecision(unsigned param, Decoration precision)
|
||||
{
|
||||
if (precision == DecorationRelaxedPrecision)
|
||||
reducedPrecisionParams.insert(param);
|
||||
}
|
||||
Decoration getParamPrecision(unsigned param) const
|
||||
{
|
||||
return reducedPrecisionParams.find(param) != reducedPrecisionParams.end() ?
|
||||
DecorationRelaxedPrecision : NoPrecision;
|
||||
}
|
||||
|
||||
void dump(std::vector<unsigned int>& out) const
|
||||
{
|
||||
// OpLine
|
||||
if (lineInstruction != nullptr) {
|
||||
lineInstruction->dump(out);
|
||||
}
|
||||
|
||||
// OpFunction
|
||||
functionInstruction.dump(out);
|
||||
|
||||
// OpFunctionParameter
|
||||
for (int p = 0; p < (int)parameterInstructions.size(); ++p)
|
||||
parameterInstructions[p]->dump(out);
|
||||
|
||||
// Blocks
|
||||
inReadableOrder(blocks[0], [&out](const Block* b, ReachReason, Block*) { b->dump(out); });
|
||||
Instruction end(0, 0, OpFunctionEnd);
|
||||
end.dump(out);
|
||||
}
|
||||
|
||||
protected:
|
||||
Function(const Function&);
|
||||
Function& operator=(Function&);
|
||||
|
||||
Module& parent;
|
||||
std::unique_ptr<Instruction> lineInstruction;
|
||||
Instruction functionInstruction;
|
||||
std::vector<Instruction*> parameterInstructions;
|
||||
std::vector<Block*> blocks;
|
||||
bool implicitThis; // true if this is a member function expecting to be passed a 'this' as the first argument
|
||||
bool reducedPrecisionReturn;
|
||||
std::set<int> reducedPrecisionParams; // list of parameter indexes that need a relaxed precision arg
|
||||
};
|
||||
|
||||
//
|
||||
// SPIR-V IR Module.
|
||||
//
|
||||
|
||||
class Module {
|
||||
public:
|
||||
Module() {}
|
||||
virtual ~Module()
|
||||
{
|
||||
// TODO delete things
|
||||
}
|
||||
|
||||
void addFunction(Function *fun) { functions.push_back(fun); }
|
||||
|
||||
void mapInstruction(Instruction *instruction)
|
||||
{
|
||||
spv::Id resultId = instruction->getResultId();
|
||||
// map the instruction's result id
|
||||
if (resultId >= idToInstruction.size())
|
||||
idToInstruction.resize(resultId + 16);
|
||||
idToInstruction[resultId] = instruction;
|
||||
}
|
||||
|
||||
Instruction* getInstruction(Id id) const { return idToInstruction[id]; }
|
||||
const std::vector<Function*>& getFunctions() const { return functions; }
|
||||
spv::Id getTypeId(Id resultId) const {
|
||||
return idToInstruction[resultId] == nullptr ? NoType : idToInstruction[resultId]->getTypeId();
|
||||
}
|
||||
StorageClass getStorageClass(Id typeId) const
|
||||
{
|
||||
assert(idToInstruction[typeId]->getOpCode() == spv::OpTypePointer);
|
||||
return (StorageClass)idToInstruction[typeId]->getImmediateOperand(0);
|
||||
}
|
||||
|
||||
void dump(std::vector<unsigned int>& out) const
|
||||
{
|
||||
for (int f = 0; f < (int)functions.size(); ++f)
|
||||
functions[f]->dump(out);
|
||||
}
|
||||
|
||||
protected:
|
||||
Module(const Module&);
|
||||
std::vector<Function*> functions;
|
||||
|
||||
// map from result id to instruction having that result id
|
||||
std::vector<Instruction*> idToInstruction;
|
||||
|
||||
// map from a result id to its type id
|
||||
};
|
||||
|
||||
//
|
||||
// Implementation (it's here due to circular type definitions).
|
||||
//
|
||||
|
||||
// Add both
|
||||
// - the OpFunction instruction
|
||||
// - all the OpFunctionParameter instructions
|
||||
__inline Function::Function(Id id, Id resultType, Id functionType, Id firstParamId, Module& parent)
|
||||
: parent(parent), lineInstruction(nullptr),
|
||||
functionInstruction(id, resultType, OpFunction), implicitThis(false),
|
||||
reducedPrecisionReturn(false)
|
||||
{
|
||||
// OpFunction
|
||||
functionInstruction.addImmediateOperand(FunctionControlMaskNone);
|
||||
functionInstruction.addIdOperand(functionType);
|
||||
parent.mapInstruction(&functionInstruction);
|
||||
parent.addFunction(this);
|
||||
|
||||
// OpFunctionParameter
|
||||
Instruction* typeInst = parent.getInstruction(functionType);
|
||||
int numParams = typeInst->getNumOperands() - 1;
|
||||
for (int p = 0; p < numParams; ++p) {
|
||||
Instruction* param = new Instruction(firstParamId + p, typeInst->getIdOperand(p + 1), OpFunctionParameter);
|
||||
parent.mapInstruction(param);
|
||||
parameterInstructions.push_back(param);
|
||||
}
|
||||
}
|
||||
|
||||
__inline void Function::addLocalVariable(std::unique_ptr<Instruction> inst)
|
||||
{
|
||||
Instruction* raw_instruction = inst.get();
|
||||
blocks[0]->addLocalVariable(std::move(inst));
|
||||
parent.mapInstruction(raw_instruction);
|
||||
}
|
||||
|
||||
__inline Block::Block(Id id, Function& parent) : parent(parent), unreachable(false)
|
||||
{
|
||||
instructions.push_back(std::unique_ptr<Instruction>(new Instruction(id, NoType, OpLabel)));
|
||||
instructions.back()->setBlock(this);
|
||||
parent.getParent().mapInstruction(instructions.back().get());
|
||||
}
|
||||
|
||||
__inline void Block::addInstruction(std::unique_ptr<Instruction> inst)
|
||||
{
|
||||
Instruction* raw_instruction = inst.get();
|
||||
instructions.push_back(std::move(inst));
|
||||
raw_instruction->setBlock(this);
|
||||
if (raw_instruction->getResultId())
|
||||
parent.getParent().mapInstruction(raw_instruction);
|
||||
}
|
||||
|
||||
} // end spv namespace
|
||||
|
||||
#endif // spvIR_H
|
||||
@ -0,0 +1,149 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2017 Google, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
|
||||
#include "./../glslang/Public/ShaderLang.h"
|
||||
|
||||
// Default include class for normal include convention of search backward
|
||||
// through the stack of active include paths (for nested includes).
|
||||
// Can be overridden to customize.
|
||||
class DirStackFileIncluder : public glslang::TShader::Includer {
|
||||
public:
|
||||
DirStackFileIncluder() : externalLocalDirectoryCount(0) { }
|
||||
|
||||
virtual IncludeResult* includeLocal(const char* headerName,
|
||||
const char* includerName,
|
||||
size_t inclusionDepth) override
|
||||
{
|
||||
return readLocalPath(headerName, includerName, (int)inclusionDepth);
|
||||
}
|
||||
|
||||
virtual IncludeResult* includeSystem(const char* headerName,
|
||||
const char* /*includerName*/,
|
||||
size_t /*inclusionDepth*/) override
|
||||
{
|
||||
return readSystemPath(headerName);
|
||||
}
|
||||
|
||||
// Externally set directories. E.g., from a command-line -I<dir>.
|
||||
// - Most-recently pushed are checked first.
|
||||
// - All these are checked after the parse-time stack of local directories
|
||||
// is checked.
|
||||
// - This only applies to the "local" form of #include.
|
||||
// - Makes its own copy of the path.
|
||||
virtual void pushExternalLocalDirectory(const std::string& dir)
|
||||
{
|
||||
directoryStack.push_back(dir);
|
||||
externalLocalDirectoryCount = (int)directoryStack.size();
|
||||
}
|
||||
|
||||
virtual void releaseInclude(IncludeResult* result) override
|
||||
{
|
||||
if (result != nullptr) {
|
||||
delete [] static_cast<tUserDataElement*>(result->userData);
|
||||
delete result;
|
||||
}
|
||||
}
|
||||
|
||||
virtual std::set<std::string> getIncludedFiles()
|
||||
{
|
||||
return includedFiles;
|
||||
}
|
||||
|
||||
virtual ~DirStackFileIncluder() override { }
|
||||
|
||||
protected:
|
||||
typedef char tUserDataElement;
|
||||
std::vector<std::string> directoryStack;
|
||||
int externalLocalDirectoryCount;
|
||||
std::set<std::string> includedFiles;
|
||||
|
||||
// Search for a valid "local" path based on combining the stack of include
|
||||
// directories and the nominal name of the header.
|
||||
virtual IncludeResult* readLocalPath(const char* headerName, const char* includerName, int depth)
|
||||
{
|
||||
// Discard popped include directories, and
|
||||
// initialize when at parse-time first level.
|
||||
directoryStack.resize(depth + externalLocalDirectoryCount);
|
||||
if (depth == 1)
|
||||
directoryStack.back() = getDirectory(includerName);
|
||||
|
||||
// Find a directory that works, using a reverse search of the include stack.
|
||||
for (auto it = directoryStack.rbegin(); it != directoryStack.rend(); ++it) {
|
||||
std::string path = *it + '/' + headerName;
|
||||
std::replace(path.begin(), path.end(), '\\', '/');
|
||||
std::ifstream file(path, std::ios_base::binary | std::ios_base::ate);
|
||||
if (file) {
|
||||
directoryStack.push_back(getDirectory(path));
|
||||
includedFiles.insert(path);
|
||||
return newIncludeResult(path, file, (int)file.tellg());
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Search for a valid <system> path.
|
||||
// Not implemented yet; returning nullptr signals failure to find.
|
||||
virtual IncludeResult* readSystemPath(const char* /*headerName*/) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Do actual reading of the file, filling in a new include result.
|
||||
virtual IncludeResult* newIncludeResult(const std::string& path, std::ifstream& file, int length) const
|
||||
{
|
||||
char* content = new tUserDataElement [length];
|
||||
file.seekg(0, file.beg);
|
||||
file.read(content, length);
|
||||
return new IncludeResult(path, content, length, content);
|
||||
}
|
||||
|
||||
// If no path markers, return current working directory.
|
||||
// Otherwise, strip file name and return path leading up to it.
|
||||
virtual std::string getDirectory(const std::string path) const
|
||||
{
|
||||
size_t last = path.find_last_of("/\\");
|
||||
return last == std::string::npos ? "." : path.substr(0, last);
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,57 @@
|
||||
//
|
||||
// Copyright (C) 2016 Google, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
|
||||
#define _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../glslang/Include/ResourceLimits.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
// These are the default resources for TBuiltInResources, used for both
|
||||
// - parsing this string for the case where the user didn't supply one,
|
||||
// - dumping out a template for user construction of a config file.
|
||||
extern const TBuiltInResource DefaultTBuiltInResource;
|
||||
|
||||
// Returns the DefaultTBuiltInResource as a human-readable string.
|
||||
std::string GetDefaultTBuiltInResourceString();
|
||||
|
||||
// Decodes the resource limits from |config| to |resources|.
|
||||
void DecodeResourceLimits(TBuiltInResource* resources, char* config);
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
|
||||
62
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/build_info.h.tmpl
vendored
Normal file
62
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/build_info.h.tmpl
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
// Copyright (C) 2020 The Khronos Group Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of The Khronos Group Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GLSLANG_BUILD_INFO
|
||||
#define GLSLANG_BUILD_INFO
|
||||
|
||||
#define GLSLANG_VERSION_MAJOR @major@
|
||||
#define GLSLANG_VERSION_MINOR @minor@
|
||||
#define GLSLANG_VERSION_PATCH @patch@
|
||||
#define GLSLANG_VERSION_FLAVOR "@flavor@"
|
||||
|
||||
#define GLSLANG_VERSION_GREATER_THAN(major, minor, patch) \
|
||||
((GLSLANG_VERSION_MAJOR) > (major) || ((major) == GLSLANG_VERSION_MAJOR && \
|
||||
((GLSLANG_VERSION_MINOR) > (minor) || ((minor) == GLSLANG_VERSION_MINOR && \
|
||||
(GLSLANG_VERSION_PATCH) > (patch)))))
|
||||
|
||||
#define GLSLANG_VERSION_GREATER_OR_EQUAL_TO(major, minor, patch) \
|
||||
((GLSLANG_VERSION_MAJOR) > (major) || ((major) == GLSLANG_VERSION_MAJOR && \
|
||||
((GLSLANG_VERSION_MINOR) > (minor) || ((minor) == GLSLANG_VERSION_MINOR && \
|
||||
(GLSLANG_VERSION_PATCH >= (patch))))))
|
||||
|
||||
#define GLSLANG_VERSION_LESS_THAN(major, minor, patch) \
|
||||
((GLSLANG_VERSION_MAJOR) < (major) || ((major) == GLSLANG_VERSION_MAJOR && \
|
||||
((GLSLANG_VERSION_MINOR) < (minor) || ((minor) == GLSLANG_VERSION_MINOR && \
|
||||
(GLSLANG_VERSION_PATCH) < (patch)))))
|
||||
|
||||
#define GLSLANG_VERSION_LESS_OR_EQUAL_TO(major, minor, patch) \
|
||||
((GLSLANG_VERSION_MAJOR) < (major) || ((major) == GLSLANG_VERSION_MAJOR && \
|
||||
((GLSLANG_VERSION_MINOR) < (minor) || ((minor) == GLSLANG_VERSION_MINOR && \
|
||||
(GLSLANG_VERSION_PATCH <= (patch))))))
|
||||
|
||||
#endif // GLSLANG_BUILD_INFO
|
||||
226
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/build_info.py
vendored
Normal file
226
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/build_info.py
vendored
Normal file
@ -0,0 +1,226 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (c) 2020 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import datetime
|
||||
import errno
|
||||
import os
|
||||
import os.path
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
usage = """{} emits a string to stdout or file with project version information.
|
||||
|
||||
args: <project-dir> [<input-string>] [-i <input-file>] [-o <output-file>]
|
||||
|
||||
Either <input-string> or -i <input-file> needs to be provided.
|
||||
|
||||
The tool will output the provided string or file content with the following
|
||||
tokens substituted:
|
||||
|
||||
<major> - The major version point parsed from the CHANGES.md file.
|
||||
<minor> - The minor version point parsed from the CHANGES.md file.
|
||||
<patch> - The point version point parsed from the CHANGES.md file.
|
||||
<flavor> - The optional dash suffix parsed from the CHANGES.md file (excluding
|
||||
dash prefix).
|
||||
<-flavor> - The optional dash suffix parsed from the CHANGES.md file (including
|
||||
dash prefix).
|
||||
<date> - The optional date of the release in the form YYYY-MM-DD
|
||||
<commit> - The git commit information for the directory taken from
|
||||
"git describe" if that succeeds, or "git rev-parse HEAD"
|
||||
if that succeeds, or otherwise a message containing the phrase
|
||||
"unknown hash".
|
||||
|
||||
-o is an optional flag for writing the output string to the given file. If
|
||||
ommitted then the string is printed to stdout.
|
||||
"""
|
||||
|
||||
def mkdir_p(directory):
|
||||
"""Make the directory, and all its ancestors as required. Any of the
|
||||
directories are allowed to already exist."""
|
||||
|
||||
if directory == "":
|
||||
# We're being asked to make the current directory.
|
||||
return
|
||||
|
||||
try:
|
||||
os.makedirs(directory)
|
||||
except OSError as e:
|
||||
if e.errno == errno.EEXIST and os.path.isdir(directory):
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
def command_output(cmd, directory):
|
||||
"""Runs a command in a directory and returns its standard output stream.
|
||||
|
||||
Captures the standard error stream.
|
||||
|
||||
Raises a RuntimeError if the command fails to launch or otherwise fails.
|
||||
"""
|
||||
p = subprocess.Popen(cmd,
|
||||
cwd=directory,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
(stdout, _) = p.communicate()
|
||||
if p.returncode != 0:
|
||||
raise RuntimeError('Failed to run %s in %s' % (cmd, directory))
|
||||
return stdout
|
||||
|
||||
|
||||
def deduce_software_version(directory):
|
||||
"""Returns a software version number parsed from the CHANGES.md file
|
||||
in the given directory.
|
||||
|
||||
The CHANGES.md file describes most recent versions first.
|
||||
"""
|
||||
|
||||
# Match the first well-formed version-and-date line.
|
||||
# Allow trailing whitespace in the checked-out source code has
|
||||
# unexpected carriage returns on a linefeed-only system such as
|
||||
# Linux.
|
||||
pattern = re.compile(r'^#* +(\d+)\.(\d+)\.(\d+)(-\w+)? (\d\d\d\d-\d\d-\d\d)? *$')
|
||||
changes_file = os.path.join(directory, 'CHANGES.md')
|
||||
with open(changes_file, mode='r') as f:
|
||||
for line in f.readlines():
|
||||
match = pattern.match(line)
|
||||
if match:
|
||||
flavor = match.group(4)
|
||||
if flavor == None:
|
||||
flavor = ""
|
||||
return {
|
||||
"major": match.group(1),
|
||||
"minor": match.group(2),
|
||||
"patch": match.group(3),
|
||||
"flavor": flavor.lstrip("-"),
|
||||
"-flavor": flavor,
|
||||
"date": match.group(5),
|
||||
}
|
||||
raise Exception('No version number found in {}'.format(changes_file))
|
||||
|
||||
|
||||
def describe(directory):
|
||||
"""Returns a string describing the current Git HEAD version as descriptively
|
||||
as possible.
|
||||
|
||||
Runs 'git describe', or alternately 'git rev-parse HEAD', in directory. If
|
||||
successful, returns the output; otherwise returns 'unknown hash, <date>'."""
|
||||
try:
|
||||
# decode() is needed here for Python3 compatibility. In Python2,
|
||||
# str and bytes are the same type, but not in Python3.
|
||||
# Popen.communicate() returns a bytes instance, which needs to be
|
||||
# decoded into text data first in Python3. And this decode() won't
|
||||
# hurt Python2.
|
||||
return command_output(['git', 'describe'], directory).rstrip().decode()
|
||||
except:
|
||||
try:
|
||||
return command_output(
|
||||
['git', 'rev-parse', 'HEAD'], directory).rstrip().decode()
|
||||
except:
|
||||
# This is the fallback case where git gives us no information,
|
||||
# e.g. because the source tree might not be in a git tree.
|
||||
# In this case, usually use a timestamp. However, to ensure
|
||||
# reproducible builds, allow the builder to override the wall
|
||||
# clock time with environment variable SOURCE_DATE_EPOCH
|
||||
# containing a (presumably) fixed timestamp.
|
||||
timestamp = int(os.environ.get('SOURCE_DATE_EPOCH', time.time()))
|
||||
formatted = datetime.datetime.utcfromtimestamp(timestamp).isoformat()
|
||||
return 'unknown hash, {}'.format(formatted)
|
||||
|
||||
def parse_args():
|
||||
directory = None
|
||||
input_string = None
|
||||
input_file = None
|
||||
output_file = None
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
raise Exception("Invalid number of arguments")
|
||||
|
||||
directory = sys.argv[1]
|
||||
i = 2
|
||||
|
||||
if not sys.argv[i].startswith("-"):
|
||||
input_string = sys.argv[i]
|
||||
i = i + 1
|
||||
|
||||
while i < len(sys.argv):
|
||||
opt = sys.argv[i]
|
||||
i = i + 1
|
||||
|
||||
if opt == "-i" or opt == "-o":
|
||||
if i == len(sys.argv):
|
||||
raise Exception("Expected path after {}".format(opt))
|
||||
val = sys.argv[i]
|
||||
i = i + 1
|
||||
if (opt == "-i"):
|
||||
input_file = val
|
||||
elif (opt == "-o"):
|
||||
output_file = val
|
||||
else:
|
||||
raise Exception("Unknown flag {}".format(opt))
|
||||
|
||||
return {
|
||||
"directory": directory,
|
||||
"input_string": input_string,
|
||||
"input_file": input_file,
|
||||
"output_file": output_file,
|
||||
}
|
||||
|
||||
def main():
|
||||
args = None
|
||||
try:
|
||||
args = parse_args()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("\nUsage:\n")
|
||||
print(usage.format(sys.argv[0]))
|
||||
sys.exit(1)
|
||||
|
||||
directory = args["directory"]
|
||||
template = args["input_string"]
|
||||
if template == None:
|
||||
with open(args["input_file"], 'r') as f:
|
||||
template = f.read()
|
||||
output_file = args["output_file"]
|
||||
|
||||
software_version = deduce_software_version(directory)
|
||||
commit = describe(directory)
|
||||
output = template \
|
||||
.replace("@major@", software_version["major"]) \
|
||||
.replace("@minor@", software_version["minor"]) \
|
||||
.replace("@patch@", software_version["patch"]) \
|
||||
.replace("@flavor@", software_version["flavor"]) \
|
||||
.replace("@-flavor@", software_version["-flavor"]) \
|
||||
.replace("@date@", software_version["date"]) \
|
||||
.replace("@commit@", commit)
|
||||
|
||||
if output_file is None:
|
||||
print(output)
|
||||
else:
|
||||
mkdir_p(os.path.dirname(output_file))
|
||||
|
||||
if os.path.isfile(output_file):
|
||||
with open(output_file, 'r') as f:
|
||||
if output == f.read():
|
||||
return
|
||||
|
||||
with open(output_file, 'w') as f:
|
||||
f.write(output)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@ -0,0 +1,482 @@
|
||||
/**
|
||||
This code is based on the glslang_c_interface implementation by Viktor Latypov
|
||||
**/
|
||||
|
||||
/**
|
||||
BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2019, Viktor Latypov
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**/
|
||||
|
||||
#include "glslang/Include/glslang_c_interface.h"
|
||||
|
||||
#include "StandAlone/DirStackFileIncluder.h"
|
||||
#include "StandAlone/ResourceLimits.h"
|
||||
#include "glslang/Include/ShHandle.h"
|
||||
|
||||
#include "glslang/Include/ResourceLimits.h"
|
||||
#include "glslang/MachineIndependent/Versions.h"
|
||||
#include "glslang/MachineIndependent/localintermediate.h"
|
||||
|
||||
static_assert(int(GLSLANG_STAGE_COUNT) == EShLangCount, "");
|
||||
static_assert(int(GLSLANG_STAGE_MASK_COUNT) == EShLanguageMaskCount, "");
|
||||
static_assert(int(GLSLANG_SOURCE_COUNT) == glslang::EShSourceCount, "");
|
||||
static_assert(int(GLSLANG_CLIENT_COUNT) == glslang::EShClientCount, "");
|
||||
static_assert(int(GLSLANG_TARGET_COUNT) == glslang::EShTargetCount, "");
|
||||
static_assert(int(GLSLANG_TARGET_CLIENT_VERSION_COUNT) == glslang::EShTargetClientVersionCount, "");
|
||||
static_assert(int(GLSLANG_TARGET_LANGUAGE_VERSION_COUNT) == glslang::EShTargetLanguageVersionCount, "");
|
||||
static_assert(int(GLSLANG_OPT_LEVEL_COUNT) == EshOptLevelCount, "");
|
||||
static_assert(int(GLSLANG_TEX_SAMP_TRANS_COUNT) == EShTexSampTransCount, "");
|
||||
static_assert(int(GLSLANG_MSG_COUNT) == EShMsgCount, "");
|
||||
static_assert(int(GLSLANG_REFLECTION_COUNT) == EShReflectionCount, "");
|
||||
static_assert(int(GLSLANG_PROFILE_COUNT) == EProfileCount, "");
|
||||
static_assert(sizeof(glslang_limits_t) == sizeof(TLimits), "");
|
||||
static_assert(sizeof(glslang_resource_t) == sizeof(TBuiltInResource), "");
|
||||
|
||||
typedef struct glslang_shader_s {
|
||||
glslang::TShader* shader;
|
||||
std::string preprocessedGLSL;
|
||||
} glslang_shader_t;
|
||||
|
||||
typedef struct glslang_program_s {
|
||||
glslang::TProgram* program;
|
||||
std::vector<unsigned int> spirv;
|
||||
std::string loggerMessages;
|
||||
} glslang_program_t;
|
||||
|
||||
/* Wrapper/Adapter for C glsl_include_callbacks_t functions
|
||||
|
||||
This class contains a 'glsl_include_callbacks_t' structure
|
||||
with C include_local/include_system callback pointers.
|
||||
|
||||
This class implement TShader::Includer interface
|
||||
by redirecting C++ virtual methods to C callbacks.
|
||||
|
||||
The 'IncludeResult' instances produced by this Includer
|
||||
contain a reference to glsl_include_result_t C structure
|
||||
to allow its lifetime management by another C callback
|
||||
(CallbackIncluder::callbacks::free_include_result)
|
||||
*/
|
||||
class CallbackIncluder : public glslang::TShader::Includer {
|
||||
public:
|
||||
/* Wrapper of IncludeResult which stores a glsl_include_result object internally */
|
||||
class CallbackIncludeResult : public glslang::TShader::Includer::IncludeResult {
|
||||
public:
|
||||
CallbackIncludeResult(const std::string& headerName, const char* const headerData, const size_t headerLength,
|
||||
void* userData, glsl_include_result_t* includeResult)
|
||||
: glslang::TShader::Includer::IncludeResult(headerName, headerData, headerLength, userData),
|
||||
includeResult(includeResult)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~CallbackIncludeResult() {}
|
||||
|
||||
protected:
|
||||
friend class CallbackIncluder;
|
||||
|
||||
glsl_include_result_t* includeResult;
|
||||
};
|
||||
|
||||
public:
|
||||
CallbackIncluder(glsl_include_callbacks_t _callbacks, void* _context) : callbacks(_callbacks), context(_context) {}
|
||||
|
||||
virtual ~CallbackIncluder() {}
|
||||
|
||||
virtual IncludeResult* includeSystem(const char* headerName, const char* includerName,
|
||||
size_t inclusionDepth) override
|
||||
{
|
||||
if (this->callbacks.include_system) {
|
||||
glsl_include_result_t* result =
|
||||
this->callbacks.include_system(this->context, headerName, includerName, inclusionDepth);
|
||||
|
||||
return new CallbackIncludeResult(std::string(headerName), result->header_data, result->header_length,
|
||||
nullptr, result);
|
||||
}
|
||||
|
||||
return glslang::TShader::Includer::includeSystem(headerName, includerName, inclusionDepth);
|
||||
}
|
||||
|
||||
virtual IncludeResult* includeLocal(const char* headerName, const char* includerName,
|
||||
size_t inclusionDepth) override
|
||||
{
|
||||
if (this->callbacks.include_local) {
|
||||
glsl_include_result_t* result =
|
||||
this->callbacks.include_local(this->context, headerName, includerName, inclusionDepth);
|
||||
|
||||
return new CallbackIncludeResult(std::string(headerName), result->header_data, result->header_length,
|
||||
nullptr, result);
|
||||
}
|
||||
|
||||
return glslang::TShader::Includer::includeLocal(headerName, includerName, inclusionDepth);
|
||||
}
|
||||
|
||||
/* This function only calls free_include_result callback
|
||||
when the IncludeResult instance is allocated by a C function */
|
||||
virtual void releaseInclude(IncludeResult* result) override
|
||||
{
|
||||
if (result == nullptr)
|
||||
return;
|
||||
|
||||
if (this->callbacks.free_include_result && (result->userData == nullptr)) {
|
||||
CallbackIncludeResult* innerResult = static_cast<CallbackIncludeResult*>(result);
|
||||
/* use internal free() function */
|
||||
this->callbacks.free_include_result(this->context, innerResult->includeResult);
|
||||
/* ignore internal fields of TShader::Includer::IncludeResult */
|
||||
delete result;
|
||||
return;
|
||||
}
|
||||
|
||||
delete[] static_cast<char*>(result->userData);
|
||||
delete result;
|
||||
}
|
||||
|
||||
private:
|
||||
CallbackIncluder() {}
|
||||
|
||||
/* C callback pointers */
|
||||
glsl_include_callbacks_t callbacks;
|
||||
/* User-defined context */
|
||||
void* context;
|
||||
};
|
||||
|
||||
GLSLANG_EXPORT int glslang_initialize_process() { return static_cast<int>(glslang::InitializeProcess()); }
|
||||
|
||||
GLSLANG_EXPORT void glslang_finalize_process() { glslang::FinalizeProcess(); }
|
||||
|
||||
static EShLanguage c_shader_stage(glslang_stage_t stage)
|
||||
{
|
||||
switch (stage) {
|
||||
case GLSLANG_STAGE_VERTEX:
|
||||
return EShLangVertex;
|
||||
case GLSLANG_STAGE_TESSCONTROL:
|
||||
return EShLangTessControl;
|
||||
case GLSLANG_STAGE_TESSEVALUATION:
|
||||
return EShLangTessEvaluation;
|
||||
case GLSLANG_STAGE_GEOMETRY:
|
||||
return EShLangGeometry;
|
||||
case GLSLANG_STAGE_FRAGMENT:
|
||||
return EShLangFragment;
|
||||
case GLSLANG_STAGE_COMPUTE:
|
||||
return EShLangCompute;
|
||||
case GLSLANG_STAGE_RAYGEN_NV:
|
||||
return EShLangRayGen;
|
||||
case GLSLANG_STAGE_INTERSECT_NV:
|
||||
return EShLangIntersect;
|
||||
case GLSLANG_STAGE_ANYHIT_NV:
|
||||
return EShLangAnyHit;
|
||||
case GLSLANG_STAGE_CLOSESTHIT_NV:
|
||||
return EShLangClosestHit;
|
||||
case GLSLANG_STAGE_MISS_NV:
|
||||
return EShLangMiss;
|
||||
case GLSLANG_STAGE_CALLABLE_NV:
|
||||
return EShLangCallable;
|
||||
case GLSLANG_STAGE_TASK:
|
||||
return EShLangTask;
|
||||
case GLSLANG_STAGE_MESH:
|
||||
return EShLangMesh;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return EShLangCount;
|
||||
}
|
||||
|
||||
static int c_shader_messages(glslang_messages_t messages)
|
||||
{
|
||||
#define CONVERT_MSG(in, out) \
|
||||
if ((messages & in) == in) \
|
||||
res |= out;
|
||||
|
||||
int res = 0;
|
||||
|
||||
CONVERT_MSG(GLSLANG_MSG_RELAXED_ERRORS_BIT, EShMsgRelaxedErrors);
|
||||
CONVERT_MSG(GLSLANG_MSG_SUPPRESS_WARNINGS_BIT, EShMsgSuppressWarnings);
|
||||
CONVERT_MSG(GLSLANG_MSG_AST_BIT, EShMsgAST);
|
||||
CONVERT_MSG(GLSLANG_MSG_SPV_RULES_BIT, EShMsgSpvRules);
|
||||
CONVERT_MSG(GLSLANG_MSG_VULKAN_RULES_BIT, EShMsgVulkanRules);
|
||||
CONVERT_MSG(GLSLANG_MSG_ONLY_PREPROCESSOR_BIT, EShMsgOnlyPreprocessor);
|
||||
CONVERT_MSG(GLSLANG_MSG_READ_HLSL_BIT, EShMsgReadHlsl);
|
||||
CONVERT_MSG(GLSLANG_MSG_CASCADING_ERRORS_BIT, EShMsgCascadingErrors);
|
||||
CONVERT_MSG(GLSLANG_MSG_KEEP_UNCALLED_BIT, EShMsgKeepUncalled);
|
||||
CONVERT_MSG(GLSLANG_MSG_HLSL_OFFSETS_BIT, EShMsgHlslOffsets);
|
||||
CONVERT_MSG(GLSLANG_MSG_DEBUG_INFO_BIT, EShMsgDebugInfo);
|
||||
CONVERT_MSG(GLSLANG_MSG_HLSL_ENABLE_16BIT_TYPES_BIT, EShMsgHlslEnable16BitTypes);
|
||||
CONVERT_MSG(GLSLANG_MSG_HLSL_LEGALIZATION_BIT, EShMsgHlslLegalization);
|
||||
CONVERT_MSG(GLSLANG_MSG_HLSL_DX9_COMPATIBLE_BIT, EShMsgHlslDX9Compatible);
|
||||
CONVERT_MSG(GLSLANG_MSG_BUILTIN_SYMBOL_TABLE_BIT, EShMsgBuiltinSymbolTable);
|
||||
return res;
|
||||
#undef CONVERT_MSG
|
||||
}
|
||||
|
||||
static glslang::EShTargetLanguageVersion
|
||||
c_shader_target_language_version(glslang_target_language_version_t target_language_version)
|
||||
{
|
||||
switch (target_language_version) {
|
||||
case GLSLANG_TARGET_SPV_1_0:
|
||||
return glslang::EShTargetSpv_1_0;
|
||||
case GLSLANG_TARGET_SPV_1_1:
|
||||
return glslang::EShTargetSpv_1_1;
|
||||
case GLSLANG_TARGET_SPV_1_2:
|
||||
return glslang::EShTargetSpv_1_2;
|
||||
case GLSLANG_TARGET_SPV_1_3:
|
||||
return glslang::EShTargetSpv_1_3;
|
||||
case GLSLANG_TARGET_SPV_1_4:
|
||||
return glslang::EShTargetSpv_1_4;
|
||||
case GLSLANG_TARGET_SPV_1_5:
|
||||
return glslang::EShTargetSpv_1_5;
|
||||
case GLSLANG_TARGET_SPV_1_6:
|
||||
return glslang::EShTargetSpv_1_6;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return glslang::EShTargetSpv_1_0;
|
||||
}
|
||||
|
||||
static glslang::EShClient c_shader_client(glslang_client_t client)
|
||||
{
|
||||
switch (client) {
|
||||
case GLSLANG_CLIENT_VULKAN:
|
||||
return glslang::EShClientVulkan;
|
||||
case GLSLANG_CLIENT_OPENGL:
|
||||
return glslang::EShClientOpenGL;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return glslang::EShClientNone;
|
||||
}
|
||||
|
||||
static glslang::EShTargetClientVersion c_shader_client_version(glslang_target_client_version_t client_version)
|
||||
{
|
||||
switch (client_version) {
|
||||
case GLSLANG_TARGET_VULKAN_1_1:
|
||||
return glslang::EShTargetVulkan_1_1;
|
||||
case GLSLANG_TARGET_VULKAN_1_2:
|
||||
return glslang::EShTargetVulkan_1_2;
|
||||
case GLSLANG_TARGET_VULKAN_1_3:
|
||||
return glslang::EShTargetVulkan_1_3;
|
||||
case GLSLANG_TARGET_OPENGL_450:
|
||||
return glslang::EShTargetOpenGL_450;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return glslang::EShTargetVulkan_1_0;
|
||||
}
|
||||
|
||||
static glslang::EShTargetLanguage c_shader_target_language(glslang_target_language_t target_language)
|
||||
{
|
||||
if (target_language == GLSLANG_TARGET_NONE)
|
||||
return glslang::EShTargetNone;
|
||||
|
||||
return glslang::EShTargetSpv;
|
||||
}
|
||||
|
||||
static glslang::EShSource c_shader_source(glslang_source_t source)
|
||||
{
|
||||
switch (source) {
|
||||
case GLSLANG_SOURCE_GLSL:
|
||||
return glslang::EShSourceGlsl;
|
||||
case GLSLANG_SOURCE_HLSL:
|
||||
return glslang::EShSourceHlsl;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return glslang::EShSourceNone;
|
||||
}
|
||||
|
||||
static EProfile c_shader_profile(glslang_profile_t profile)
|
||||
{
|
||||
switch (profile) {
|
||||
case GLSLANG_BAD_PROFILE:
|
||||
return EBadProfile;
|
||||
case GLSLANG_NO_PROFILE:
|
||||
return ENoProfile;
|
||||
case GLSLANG_CORE_PROFILE:
|
||||
return ECoreProfile;
|
||||
case GLSLANG_COMPATIBILITY_PROFILE:
|
||||
return ECompatibilityProfile;
|
||||
case GLSLANG_ES_PROFILE:
|
||||
return EEsProfile;
|
||||
case GLSLANG_PROFILE_COUNT: // Should not use this
|
||||
break;
|
||||
}
|
||||
|
||||
return EProfile();
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT glslang_shader_t* glslang_shader_create(const glslang_input_t* input)
|
||||
{
|
||||
if (!input || !input->code) {
|
||||
printf("Error creating shader: null input(%p)/input->code\n", input);
|
||||
|
||||
if (input)
|
||||
printf("input->code = %p\n", input->code);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
glslang_shader_t* shader = new glslang_shader_t();
|
||||
|
||||
shader->shader = new glslang::TShader(c_shader_stage(input->stage));
|
||||
shader->shader->setStrings(&input->code, 1);
|
||||
shader->shader->setEnvInput(c_shader_source(input->language), c_shader_stage(input->stage),
|
||||
c_shader_client(input->client), input->default_version);
|
||||
shader->shader->setEnvClient(c_shader_client(input->client), c_shader_client_version(input->client_version));
|
||||
shader->shader->setEnvTarget(c_shader_target_language(input->target_language),
|
||||
c_shader_target_language_version(input->target_language_version));
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT void glslang_shader_shift_binding(glslang_shader_t* shader, glslang_resource_type_t res, unsigned int base)
|
||||
{
|
||||
const glslang::TResourceType res_type = glslang::TResourceType(res);
|
||||
shader->shader->setShiftBinding(res_type, base);
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT void glslang_shader_shift_binding_for_set(glslang_shader_t* shader, glslang_resource_type_t res, unsigned int base, unsigned int set)
|
||||
{
|
||||
const glslang::TResourceType res_type = glslang::TResourceType(res);
|
||||
shader->shader->setShiftBindingForSet(res_type, base, set);
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT void glslang_shader_set_options(glslang_shader_t* shader, int options)
|
||||
{
|
||||
if (options & GLSLANG_SHADER_AUTO_MAP_BINDINGS) {
|
||||
shader->shader->setAutoMapBindings(true);
|
||||
}
|
||||
|
||||
if (options & GLSLANG_SHADER_AUTO_MAP_LOCATIONS) {
|
||||
shader->shader->setAutoMapLocations(true);
|
||||
}
|
||||
|
||||
if (options & GLSLANG_SHADER_VULKAN_RULES_RELAXED) {
|
||||
shader->shader->setEnvInputVulkanRulesRelaxed();
|
||||
}
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT void glslang_shader_set_glsl_version(glslang_shader_t* shader, int version)
|
||||
{
|
||||
shader->shader->setOverrideVersion(version);
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT const char* glslang_shader_get_preprocessed_code(glslang_shader_t* shader)
|
||||
{
|
||||
return shader->preprocessedGLSL.c_str();
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT int glslang_shader_preprocess(glslang_shader_t* shader, const glslang_input_t* input)
|
||||
{
|
||||
DirStackFileIncluder Includer;
|
||||
/* TODO: use custom callbacks if they are available in 'i->callbacks' */
|
||||
return shader->shader->preprocess(
|
||||
reinterpret_cast<const TBuiltInResource*>(input->resource),
|
||||
input->default_version,
|
||||
c_shader_profile(input->default_profile),
|
||||
input->force_default_version_and_profile != 0,
|
||||
input->forward_compatible != 0,
|
||||
(EShMessages)c_shader_messages(input->messages),
|
||||
&shader->preprocessedGLSL,
|
||||
Includer
|
||||
);
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT int glslang_shader_parse(glslang_shader_t* shader, const glslang_input_t* input)
|
||||
{
|
||||
const char* preprocessedCStr = shader->preprocessedGLSL.c_str();
|
||||
shader->shader->setStrings(&preprocessedCStr, 1);
|
||||
|
||||
return shader->shader->parse(
|
||||
reinterpret_cast<const TBuiltInResource*>(input->resource),
|
||||
input->default_version,
|
||||
input->forward_compatible != 0,
|
||||
(EShMessages)c_shader_messages(input->messages)
|
||||
);
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT const char* glslang_shader_get_info_log(glslang_shader_t* shader) { return shader->shader->getInfoLog(); }
|
||||
|
||||
GLSLANG_EXPORT const char* glslang_shader_get_info_debug_log(glslang_shader_t* shader) { return shader->shader->getInfoDebugLog(); }
|
||||
|
||||
GLSLANG_EXPORT void glslang_shader_delete(glslang_shader_t* shader)
|
||||
{
|
||||
if (!shader)
|
||||
return;
|
||||
|
||||
delete (shader->shader);
|
||||
delete (shader);
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT glslang_program_t* glslang_program_create()
|
||||
{
|
||||
glslang_program_t* p = new glslang_program_t();
|
||||
p->program = new glslang::TProgram();
|
||||
return p;
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT void glslang_program_delete(glslang_program_t* program)
|
||||
{
|
||||
if (!program)
|
||||
return;
|
||||
|
||||
delete (program->program);
|
||||
delete (program);
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT void glslang_program_add_shader(glslang_program_t* program, glslang_shader_t* shader)
|
||||
{
|
||||
program->program->addShader(shader->shader);
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT int glslang_program_link(glslang_program_t* program, int messages)
|
||||
{
|
||||
return (int)program->program->link((EShMessages)messages);
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT void glslang_program_add_source_text(glslang_program_t* program, glslang_stage_t stage, const char* text, size_t len) {
|
||||
glslang::TIntermediate* intermediate = program->program->getIntermediate(c_shader_stage(stage));
|
||||
intermediate->addSourceText(text, len);
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT void glslang_program_set_source_file(glslang_program_t* program, glslang_stage_t stage, const char* file) {
|
||||
glslang::TIntermediate* intermediate = program->program->getIntermediate(c_shader_stage(stage));
|
||||
intermediate->setSourceFile(file);
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT int glslang_program_map_io(glslang_program_t* program)
|
||||
{
|
||||
return (int)program->program->mapIO();
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT const char* glslang_program_get_info_log(glslang_program_t* program)
|
||||
{
|
||||
return program->program->getInfoLog();
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT const char* glslang_program_get_info_debug_log(glslang_program_t* program)
|
||||
{
|
||||
return program->program->getInfoDebugLog();
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#include "../Include/Common.h"
|
||||
#include "../Include/ShHandle.h"
|
||||
#include "../MachineIndependent/Versions.h"
|
||||
|
||||
//
|
||||
// Here is where real machine specific high-level data would be defined.
|
||||
//
|
||||
class TGenericCompiler : public TCompiler {
|
||||
public:
|
||||
TGenericCompiler(EShLanguage l, int dOptions) : TCompiler(l, infoSink), debugOptions(dOptions) { }
|
||||
virtual bool compile(TIntermNode* root, int version = 0, EProfile profile = ENoProfile);
|
||||
TInfoSink infoSink;
|
||||
int debugOptions;
|
||||
};
|
||||
|
||||
//
|
||||
// This function must be provided to create the actual
|
||||
// compile object used by higher level code. It returns
|
||||
// a subclass of TCompiler.
|
||||
//
|
||||
TCompiler* ConstructCompiler(EShLanguage language, int debugOptions)
|
||||
{
|
||||
return new TGenericCompiler(language, debugOptions);
|
||||
}
|
||||
|
||||
//
|
||||
// Delete the compiler made by ConstructCompiler
|
||||
//
|
||||
void DeleteCompiler(TCompiler* compiler)
|
||||
{
|
||||
delete compiler;
|
||||
}
|
||||
|
||||
//
|
||||
// Generate code from the given parse tree
|
||||
//
|
||||
bool TGenericCompiler::compile(TIntermNode* /*root*/, int /*version*/, EProfile /*profile*/)
|
||||
{
|
||||
haveValidObjectCode = true;
|
||||
|
||||
return haveValidObjectCode;
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
//
|
||||
// The top level algorithms for linking multiple
|
||||
// shaders together.
|
||||
//
|
||||
#include "../Include/Common.h"
|
||||
#include "../Include/ShHandle.h"
|
||||
|
||||
//
|
||||
// Actual link object, derived from the shader handle base classes.
|
||||
//
|
||||
class TGenericLinker : public TLinker {
|
||||
public:
|
||||
TGenericLinker(EShExecutable e, int dOptions) : TLinker(e, infoSink), debugOptions(dOptions) { }
|
||||
bool link(TCompilerList&, TUniformMap*) { return true; }
|
||||
void getAttributeBindings(ShBindingTable const **) const { }
|
||||
TInfoSink infoSink;
|
||||
int debugOptions;
|
||||
};
|
||||
|
||||
//
|
||||
// The internal view of a uniform/float object exchanged with the driver.
|
||||
//
|
||||
class TUniformLinkedMap : public TUniformMap {
|
||||
public:
|
||||
TUniformLinkedMap() { }
|
||||
virtual int getLocation(const char*) { return 0; }
|
||||
};
|
||||
|
||||
TShHandleBase* ConstructLinker(EShExecutable executable, int debugOptions)
|
||||
{
|
||||
return new TGenericLinker(executable, debugOptions);
|
||||
}
|
||||
|
||||
void DeleteLinker(TShHandleBase* linker)
|
||||
{
|
||||
delete linker;
|
||||
}
|
||||
|
||||
TUniformMap* ConstructUniformMap()
|
||||
{
|
||||
return new TUniformLinkedMap();
|
||||
}
|
||||
|
||||
void DeleteUniformMap(TUniformMap* map)
|
||||
{
|
||||
delete map;
|
||||
}
|
||||
|
||||
TShHandleBase* ConstructBindings()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DeleteBindingList(TShHandleBase* bindingList)
|
||||
{
|
||||
delete bindingList;
|
||||
}
|
||||
@ -0,0 +1,149 @@
|
||||
//
|
||||
// Copyright (C) 2016 LunarG, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of Google, Inc., nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#include "hlslAttributes.h"
|
||||
#include "hlslParseHelper.h"
|
||||
|
||||
namespace glslang {
|
||||
// Map the given string to an attribute enum from TAttributeType,
|
||||
// or EatNone if invalid.
|
||||
TAttributeType HlslParseContext::attributeFromName(const TString& nameSpace, const TString& name) const
|
||||
{
|
||||
// handle names within a namespace
|
||||
|
||||
if (nameSpace == "vk") {
|
||||
if (name == "input_attachment_index")
|
||||
return EatInputAttachment;
|
||||
else if (name == "location")
|
||||
return EatLocation;
|
||||
else if (name == "binding")
|
||||
return EatBinding;
|
||||
else if (name == "global_cbuffer_binding")
|
||||
return EatGlobalBinding;
|
||||
else if (name == "builtin")
|
||||
return EatBuiltIn;
|
||||
else if (name == "constant_id")
|
||||
return EatConstantId;
|
||||
else if (name == "push_constant")
|
||||
return EatPushConstant;
|
||||
} else if (nameSpace == "spv") {
|
||||
if (name == "format_rgba32f") return EatFormatRgba32f;
|
||||
if (name == "format_rgba16f") return EatFormatRgba16f;
|
||||
if (name == "format_r32f") return EatFormatR32f;
|
||||
if (name == "format_rgba8") return EatFormatRgba8;
|
||||
if (name == "format_rgba8snorm") return EatFormatRgba8Snorm;
|
||||
if (name == "format_rg32f") return EatFormatRg32f;
|
||||
if (name == "format_rg16f") return EatFormatRg16f;
|
||||
if (name == "format_r11fg11fb10f") return EatFormatR11fG11fB10f;
|
||||
if (name == "format_r16f") return EatFormatR16f;
|
||||
if (name == "format_rgba16") return EatFormatRgba16;
|
||||
if (name == "format_rgb10a2") return EatFormatRgb10A2;
|
||||
if (name == "format_rg16") return EatFormatRg16;
|
||||
if (name == "format_rg8") return EatFormatRg8;
|
||||
if (name == "format_r16") return EatFormatR16;
|
||||
if (name == "format_r8") return EatFormatR8;
|
||||
if (name == "format_rgba16snorm") return EatFormatRgba16Snorm;
|
||||
if (name == "format_rg16snorm") return EatFormatRg16Snorm;
|
||||
if (name == "format_rg8snorm") return EatFormatRg8Snorm;
|
||||
if (name == "format_r16snorm") return EatFormatR16Snorm;
|
||||
if (name == "format_r8snorm") return EatFormatR8Snorm;
|
||||
if (name == "format_rgba32i") return EatFormatRgba32i;
|
||||
if (name == "format_rgba16i") return EatFormatRgba16i;
|
||||
if (name == "format_rgba8i") return EatFormatRgba8i;
|
||||
if (name == "format_r32i") return EatFormatR32i;
|
||||
if (name == "format_rg32i") return EatFormatRg32i;
|
||||
if (name == "format_rg16i") return EatFormatRg16i;
|
||||
if (name == "format_rg8i") return EatFormatRg8i;
|
||||
if (name == "format_r16i") return EatFormatR16i;
|
||||
if (name == "format_r8i") return EatFormatR8i;
|
||||
if (name == "format_rgba32ui") return EatFormatRgba32ui;
|
||||
if (name == "format_rgba16ui") return EatFormatRgba16ui;
|
||||
if (name == "format_rgba8ui") return EatFormatRgba8ui;
|
||||
if (name == "format_r32ui") return EatFormatR32ui;
|
||||
if (name == "format_rgb10a2ui") return EatFormatRgb10a2ui;
|
||||
if (name == "format_rg32ui") return EatFormatRg32ui;
|
||||
if (name == "format_rg16ui") return EatFormatRg16ui;
|
||||
if (name == "format_rg8ui") return EatFormatRg8ui;
|
||||
if (name == "format_r16ui") return EatFormatR16ui;
|
||||
if (name == "format_r8ui") return EatFormatR8ui;
|
||||
|
||||
if (name == "nonwritable") return EatNonWritable;
|
||||
if (name == "nonreadable") return EatNonReadable;
|
||||
} else if (nameSpace.size() > 0)
|
||||
return EatNone;
|
||||
|
||||
// handle names with no namespace
|
||||
|
||||
if (name == "allow_uav_condition")
|
||||
return EatAllow_uav_condition;
|
||||
else if (name == "branch")
|
||||
return EatBranch;
|
||||
else if (name == "call")
|
||||
return EatCall;
|
||||
else if (name == "domain")
|
||||
return EatDomain;
|
||||
else if (name == "earlydepthstencil")
|
||||
return EatEarlyDepthStencil;
|
||||
else if (name == "fastopt")
|
||||
return EatFastOpt;
|
||||
else if (name == "flatten")
|
||||
return EatFlatten;
|
||||
else if (name == "forcecase")
|
||||
return EatForceCase;
|
||||
else if (name == "instance")
|
||||
return EatInstance;
|
||||
else if (name == "maxtessfactor")
|
||||
return EatMaxTessFactor;
|
||||
else if (name == "maxvertexcount")
|
||||
return EatMaxVertexCount;
|
||||
else if (name == "numthreads")
|
||||
return EatNumThreads;
|
||||
else if (name == "outputcontrolpoints")
|
||||
return EatOutputControlPoints;
|
||||
else if (name == "outputtopology")
|
||||
return EatOutputTopology;
|
||||
else if (name == "partitioning")
|
||||
return EatPartitioning;
|
||||
else if (name == "patchconstantfunc")
|
||||
return EatPatchConstantFunc;
|
||||
else if (name == "unroll")
|
||||
return EatUnroll;
|
||||
else if (name == "loop")
|
||||
return EatLoop;
|
||||
else
|
||||
return EatNone;
|
||||
}
|
||||
|
||||
} // end namespace glslang
|
||||
@ -0,0 +1,59 @@
|
||||
//
|
||||
// Copyright (C) 2016 LunarG, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of Google, Inc., nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef HLSLATTRIBUTES_H_
|
||||
#define HLSLATTRIBUTES_H_
|
||||
|
||||
#include <unordered_map>
|
||||
#include <functional>
|
||||
|
||||
#include "../MachineIndependent/attribute.h"
|
||||
#include "../MachineIndependent/SymbolTable.h"
|
||||
#include "hlslScanContext.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
class TFunctionDeclarator {
|
||||
public:
|
||||
TFunctionDeclarator() : function(nullptr), body(nullptr) { }
|
||||
TSourceLoc loc;
|
||||
TFunction* function;
|
||||
TAttributes attributes;
|
||||
TVector<HlslToken>* body;
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // HLSLATTRIBUTES_H_
|
||||
4192
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/HLSL/hlslGrammar.cpp
vendored
Normal file
4192
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/HLSL/hlslGrammar.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
142
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/HLSL/hlslGrammar.h
vendored
Normal file
142
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/HLSL/hlslGrammar.h
vendored
Normal file
@ -0,0 +1,142 @@
|
||||
//
|
||||
// Copyright (C) 2016-2018 Google, Inc.
|
||||
// Copyright (C) 2016 LunarG, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of Google, Inc., nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef HLSLGRAMMAR_H_
|
||||
#define HLSLGRAMMAR_H_
|
||||
|
||||
#include "hlslParseHelper.h"
|
||||
#include "hlslOpMap.h"
|
||||
#include "hlslTokenStream.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
class TFunctionDeclarator;
|
||||
|
||||
// Should just be the grammar aspect of HLSL.
|
||||
// Described in more detail in hlslGrammar.cpp.
|
||||
|
||||
class HlslGrammar : public HlslTokenStream {
|
||||
public:
|
||||
HlslGrammar(HlslScanContext& scanner, HlslParseContext& parseContext)
|
||||
: HlslTokenStream(scanner), parseContext(parseContext), intermediate(parseContext.intermediate),
|
||||
typeIdentifiers(false), unitNode(nullptr) { }
|
||||
virtual ~HlslGrammar() { }
|
||||
|
||||
bool parse();
|
||||
|
||||
protected:
|
||||
HlslGrammar();
|
||||
HlslGrammar& operator=(const HlslGrammar&);
|
||||
|
||||
void expected(const char*);
|
||||
void unimplemented(const char*);
|
||||
bool acceptIdentifier(HlslToken&);
|
||||
bool acceptCompilationUnit();
|
||||
bool acceptDeclarationList(TIntermNode*&);
|
||||
bool acceptDeclaration(TIntermNode*&);
|
||||
bool acceptControlDeclaration(TIntermNode*& node);
|
||||
bool acceptSamplerDeclarationDX9(TType&);
|
||||
bool acceptSamplerState();
|
||||
bool acceptFullySpecifiedType(TType&, const TAttributes&);
|
||||
bool acceptFullySpecifiedType(TType&, TIntermNode*& nodeList, const TAttributes&, bool forbidDeclarators = false);
|
||||
bool acceptQualifier(TQualifier&);
|
||||
bool acceptLayoutQualifierList(TQualifier&);
|
||||
bool acceptType(TType&);
|
||||
bool acceptType(TType&, TIntermNode*& nodeList);
|
||||
bool acceptTemplateVecMatBasicType(TBasicType&);
|
||||
bool acceptVectorTemplateType(TType&);
|
||||
bool acceptMatrixTemplateType(TType&);
|
||||
bool acceptTessellationDeclType(TBuiltInVariable&);
|
||||
bool acceptTessellationPatchTemplateType(TType&);
|
||||
bool acceptStreamOutTemplateType(TType&, TLayoutGeometry&);
|
||||
bool acceptOutputPrimitiveGeometry(TLayoutGeometry&);
|
||||
bool acceptAnnotations(TQualifier&);
|
||||
bool acceptSamplerTypeDX9(TType &);
|
||||
bool acceptSamplerType(TType&);
|
||||
bool acceptTextureType(TType&);
|
||||
bool acceptSubpassInputType(TType&);
|
||||
bool acceptStructBufferType(TType&);
|
||||
bool acceptTextureBufferType(TType&);
|
||||
bool acceptConstantBufferType(TType&);
|
||||
bool acceptStruct(TType&, TIntermNode*& nodeList);
|
||||
bool acceptStructDeclarationList(TTypeList*&, TIntermNode*& nodeList, TVector<TFunctionDeclarator>&);
|
||||
bool acceptMemberFunctionDefinition(TIntermNode*& nodeList, const TType&, TString& memberName,
|
||||
TFunctionDeclarator&);
|
||||
bool acceptFunctionParameters(TFunction&);
|
||||
bool acceptParameterDeclaration(TFunction&);
|
||||
bool acceptFunctionDefinition(TFunctionDeclarator&, TIntermNode*& nodeList, TVector<HlslToken>* deferredTokens);
|
||||
bool acceptFunctionBody(TFunctionDeclarator& declarator, TIntermNode*& nodeList);
|
||||
bool acceptParenExpression(TIntermTyped*&);
|
||||
bool acceptExpression(TIntermTyped*&);
|
||||
bool acceptInitializer(TIntermTyped*&);
|
||||
bool acceptAssignmentExpression(TIntermTyped*&);
|
||||
bool acceptConditionalExpression(TIntermTyped*&);
|
||||
bool acceptBinaryExpression(TIntermTyped*&, PrecedenceLevel);
|
||||
bool acceptUnaryExpression(TIntermTyped*&);
|
||||
bool acceptPostfixExpression(TIntermTyped*&);
|
||||
bool acceptConstructor(TIntermTyped*&);
|
||||
bool acceptFunctionCall(const TSourceLoc&, TString& name, TIntermTyped*&, TIntermTyped* objectBase);
|
||||
bool acceptArguments(TFunction*, TIntermTyped*&);
|
||||
bool acceptLiteral(TIntermTyped*&);
|
||||
bool acceptSimpleStatement(TIntermNode*&);
|
||||
bool acceptCompoundStatement(TIntermNode*&);
|
||||
bool acceptScopedStatement(TIntermNode*&);
|
||||
bool acceptScopedCompoundStatement(TIntermNode*&);
|
||||
bool acceptStatement(TIntermNode*&);
|
||||
bool acceptNestedStatement(TIntermNode*&);
|
||||
void acceptAttributes(TAttributes&);
|
||||
bool acceptSelectionStatement(TIntermNode*&, const TAttributes&);
|
||||
bool acceptSwitchStatement(TIntermNode*&, const TAttributes&);
|
||||
bool acceptIterationStatement(TIntermNode*&, const TAttributes&);
|
||||
bool acceptJumpStatement(TIntermNode*&);
|
||||
bool acceptCaseLabel(TIntermNode*&);
|
||||
bool acceptDefaultLabel(TIntermNode*&);
|
||||
void acceptArraySpecifier(TArraySizes*&);
|
||||
bool acceptPostDecls(TQualifier&);
|
||||
bool acceptDefaultParameterDeclaration(const TType&, TIntermTyped*&);
|
||||
|
||||
bool captureBlockTokens(TVector<HlslToken>& tokens);
|
||||
const char* getTypeString(EHlslTokenClass tokenClass) const;
|
||||
|
||||
HlslParseContext& parseContext; // state of parsing and helper functions for building the intermediate
|
||||
TIntermediate& intermediate; // the final product, the intermediate representation, includes the AST
|
||||
bool typeIdentifiers; // shader uses some types as identifiers
|
||||
TIntermNode* unitNode;
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // HLSLGRAMMAR_H_
|
||||
173
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/HLSL/hlslOpMap.cpp
vendored
Normal file
173
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/HLSL/hlslOpMap.cpp
vendored
Normal file
@ -0,0 +1,173 @@
|
||||
//
|
||||
// Copyright (C) 2016 Google, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of Google, Inc., nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
// Map from physical token form (e.g. '-') to logical operator
|
||||
// form (e.g., binary subtract or unary negate).
|
||||
|
||||
#include "hlslOpMap.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
// Map parsing tokens that could be assignments into assignment operators.
|
||||
TOperator HlslOpMap::assignment(EHlslTokenClass op)
|
||||
{
|
||||
switch (op) {
|
||||
case EHTokAssign: return EOpAssign;
|
||||
case EHTokMulAssign: return EOpMulAssign;
|
||||
case EHTokDivAssign: return EOpDivAssign;
|
||||
case EHTokAddAssign: return EOpAddAssign;
|
||||
case EHTokModAssign: return EOpModAssign;
|
||||
case EHTokLeftAssign: return EOpLeftShiftAssign;
|
||||
case EHTokRightAssign: return EOpRightShiftAssign;
|
||||
case EHTokAndAssign: return EOpAndAssign;
|
||||
case EHTokXorAssign: return EOpExclusiveOrAssign;
|
||||
case EHTokOrAssign: return EOpInclusiveOrAssign;
|
||||
case EHTokSubAssign: return EOpSubAssign;
|
||||
|
||||
default:
|
||||
return EOpNull;
|
||||
}
|
||||
}
|
||||
|
||||
// Map parsing tokens that could be binary operations into binary operators.
|
||||
TOperator HlslOpMap::binary(EHlslTokenClass op)
|
||||
{
|
||||
switch (op) {
|
||||
case EHTokPlus: return EOpAdd;
|
||||
case EHTokDash: return EOpSub;
|
||||
case EHTokStar: return EOpMul;
|
||||
case EHTokSlash: return EOpDiv;
|
||||
case EHTokPercent: return EOpMod;
|
||||
case EHTokRightOp: return EOpRightShift;
|
||||
case EHTokLeftOp: return EOpLeftShift;
|
||||
case EHTokAmpersand: return EOpAnd;
|
||||
case EHTokVerticalBar: return EOpInclusiveOr;
|
||||
case EHTokCaret: return EOpExclusiveOr;
|
||||
case EHTokEqOp: return EOpEqual;
|
||||
case EHTokNeOp: return EOpNotEqual;
|
||||
case EHTokLeftAngle: return EOpLessThan;
|
||||
case EHTokRightAngle: return EOpGreaterThan;
|
||||
case EHTokLeOp: return EOpLessThanEqual;
|
||||
case EHTokGeOp: return EOpGreaterThanEqual;
|
||||
case EHTokOrOp: return EOpLogicalOr;
|
||||
case EHTokXorOp: return EOpLogicalXor;
|
||||
case EHTokAndOp: return EOpLogicalAnd;
|
||||
|
||||
default:
|
||||
return EOpNull;
|
||||
}
|
||||
}
|
||||
|
||||
// Map parsing tokens that could be unary operations into unary operators.
|
||||
// These are just the ones that can appear in front of its operand.
|
||||
TOperator HlslOpMap::preUnary(EHlslTokenClass op)
|
||||
{
|
||||
switch (op) {
|
||||
case EHTokPlus: return EOpAdd; // means no-op, but still a unary op was present
|
||||
case EHTokDash: return EOpNegative;
|
||||
case EHTokBang: return EOpLogicalNot;
|
||||
case EHTokTilde: return EOpBitwiseNot;
|
||||
|
||||
case EHTokIncOp: return EOpPreIncrement;
|
||||
case EHTokDecOp: return EOpPreDecrement;
|
||||
|
||||
default: return EOpNull; // means not a pre-unary op
|
||||
}
|
||||
}
|
||||
|
||||
// Map parsing tokens that could be unary operations into unary operators.
|
||||
// These are just the ones that can appear behind its operand.
|
||||
TOperator HlslOpMap::postUnary(EHlslTokenClass op)
|
||||
{
|
||||
switch (op) {
|
||||
case EHTokDot: return EOpIndexDirectStruct;
|
||||
case EHTokLeftBracket: return EOpIndexIndirect;
|
||||
|
||||
case EHTokIncOp: return EOpPostIncrement;
|
||||
case EHTokDecOp: return EOpPostDecrement;
|
||||
|
||||
case EHTokColonColon: return EOpScoping;
|
||||
|
||||
default: return EOpNull; // means not a post-unary op
|
||||
}
|
||||
}
|
||||
|
||||
// Map operators into their level of precedence.
|
||||
PrecedenceLevel HlslOpMap::precedenceLevel(TOperator op)
|
||||
{
|
||||
switch (op) {
|
||||
case EOpLogicalOr:
|
||||
return PlLogicalOr;
|
||||
case EOpLogicalXor:
|
||||
return PlLogicalXor;
|
||||
case EOpLogicalAnd:
|
||||
return PlLogicalAnd;
|
||||
|
||||
case EOpInclusiveOr:
|
||||
return PlBitwiseOr;
|
||||
case EOpExclusiveOr:
|
||||
return PlBitwiseXor;
|
||||
case EOpAnd:
|
||||
return PlBitwiseAnd;
|
||||
|
||||
case EOpEqual:
|
||||
case EOpNotEqual:
|
||||
return PlEquality;
|
||||
|
||||
case EOpLessThan:
|
||||
case EOpGreaterThan:
|
||||
case EOpLessThanEqual:
|
||||
case EOpGreaterThanEqual:
|
||||
return PlRelational;
|
||||
|
||||
case EOpRightShift:
|
||||
case EOpLeftShift:
|
||||
return PlShift;
|
||||
|
||||
case EOpAdd:
|
||||
case EOpSub:
|
||||
return PlAdd;
|
||||
|
||||
case EOpMul:
|
||||
case EOpDiv:
|
||||
case EOpMod:
|
||||
return PlMul;
|
||||
|
||||
default:
|
||||
return PlBad;
|
||||
}
|
||||
}
|
||||
|
||||
} // end namespace glslang
|
||||
@ -0,0 +1,69 @@
|
||||
//
|
||||
// Copyright (C) 2016 Google, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of Google, Inc., nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef HLSLOPMAP_H_
|
||||
#define HLSLOPMAP_H_
|
||||
|
||||
#include "hlslScanContext.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
enum PrecedenceLevel {
|
||||
PlBad,
|
||||
PlLogicalOr,
|
||||
PlLogicalXor,
|
||||
PlLogicalAnd,
|
||||
PlBitwiseOr,
|
||||
PlBitwiseXor,
|
||||
PlBitwiseAnd,
|
||||
PlEquality,
|
||||
PlRelational,
|
||||
PlShift,
|
||||
PlAdd,
|
||||
PlMul
|
||||
};
|
||||
|
||||
class HlslOpMap {
|
||||
public:
|
||||
static TOperator assignment(EHlslTokenClass op);
|
||||
static TOperator binary(EHlslTokenClass op);
|
||||
static TOperator preUnary(EHlslTokenClass op);
|
||||
static TOperator postUnary(EHlslTokenClass op);
|
||||
static PrecedenceLevel precedenceLevel(TOperator);
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // HLSLOPMAP_H_
|
||||
10282
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/HLSL/hlslParseHelper.cpp
vendored
Normal file
10282
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/HLSL/hlslParseHelper.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,517 @@
|
||||
//
|
||||
// Copyright (C) 2016-2018 Google, Inc.
|
||||
// Copyright (C) 2016 LunarG, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
#ifndef HLSL_PARSE_INCLUDED_
|
||||
#define HLSL_PARSE_INCLUDED_
|
||||
|
||||
#include "../MachineIndependent/parseVersions.h"
|
||||
#include "../MachineIndependent/ParseHelper.h"
|
||||
#include "../MachineIndependent/attribute.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace glslang {
|
||||
|
||||
class TFunctionDeclarator;
|
||||
|
||||
class HlslParseContext : public TParseContextBase {
|
||||
public:
|
||||
HlslParseContext(TSymbolTable&, TIntermediate&, bool parsingBuiltins,
|
||||
int version, EProfile, const SpvVersion& spvVersion, EShLanguage, TInfoSink&,
|
||||
const TString sourceEntryPointName,
|
||||
bool forwardCompatible = false, EShMessages messages = EShMsgDefault);
|
||||
virtual ~HlslParseContext();
|
||||
void initializeExtensionBehavior() override;
|
||||
|
||||
void setLimits(const TBuiltInResource&) override;
|
||||
bool parseShaderStrings(TPpContext&, TInputScanner& input, bool versionWillBeError = false) override;
|
||||
virtual const char* getGlobalUniformBlockName() const override { return "$Global"; }
|
||||
virtual void setUniformBlockDefaults(TType& block) const override
|
||||
{
|
||||
block.getQualifier().layoutPacking = globalUniformDefaults.layoutPacking;
|
||||
block.getQualifier().layoutMatrix = globalUniformDefaults.layoutMatrix;
|
||||
}
|
||||
|
||||
void reservedPpErrorCheck(const TSourceLoc&, const char* /*name*/, const char* /*op*/) override { }
|
||||
bool lineContinuationCheck(const TSourceLoc&, bool /*endOfComment*/) override { return true; }
|
||||
bool lineDirectiveShouldSetNextLine() const override { return true; }
|
||||
bool builtInName(const TString&);
|
||||
|
||||
void handlePragma(const TSourceLoc&, const TVector<TString>&) override;
|
||||
TIntermTyped* handleVariable(const TSourceLoc&, const TString* string);
|
||||
TIntermTyped* handleBracketDereference(const TSourceLoc&, TIntermTyped* base, TIntermTyped* index);
|
||||
TIntermTyped* handleBracketOperator(const TSourceLoc&, TIntermTyped* base, TIntermTyped* index);
|
||||
|
||||
TIntermTyped* handleBinaryMath(const TSourceLoc&, const char* str, TOperator op, TIntermTyped* left, TIntermTyped* right);
|
||||
TIntermTyped* handleUnaryMath(const TSourceLoc&, const char* str, TOperator op, TIntermTyped* childNode);
|
||||
TIntermTyped* handleDotDereference(const TSourceLoc&, TIntermTyped* base, const TString& field);
|
||||
bool isBuiltInMethod(const TSourceLoc&, TIntermTyped* base, const TString& field);
|
||||
void assignToInterface(TVariable& variable);
|
||||
void handleFunctionDeclarator(const TSourceLoc&, TFunction& function, bool prototype);
|
||||
TIntermAggregate* handleFunctionDefinition(const TSourceLoc&, TFunction&, const TAttributes&, TIntermNode*& entryPointTree);
|
||||
TIntermNode* transformEntryPoint(const TSourceLoc&, TFunction&, const TAttributes&);
|
||||
void handleEntryPointAttributes(const TSourceLoc&, const TAttributes&);
|
||||
void transferTypeAttributes(const TSourceLoc&, const TAttributes&, TType&, bool allowEntry = false);
|
||||
void handleFunctionBody(const TSourceLoc&, TFunction&, TIntermNode* functionBody, TIntermNode*& node);
|
||||
void remapEntryPointIO(TFunction& function, TVariable*& returnValue, TVector<TVariable*>& inputs, TVector<TVariable*>& outputs);
|
||||
void remapNonEntryPointIO(TFunction& function);
|
||||
TIntermNode* handleDeclare(const TSourceLoc&, TIntermTyped*);
|
||||
TIntermNode* handleReturnValue(const TSourceLoc&, TIntermTyped*);
|
||||
void handleFunctionArgument(TFunction*, TIntermTyped*& arguments, TIntermTyped* newArg);
|
||||
TIntermTyped* handleAssign(const TSourceLoc&, TOperator, TIntermTyped* left, TIntermTyped* right);
|
||||
TIntermTyped* handleAssignToMatrixSwizzle(const TSourceLoc&, TOperator, TIntermTyped* left, TIntermTyped* right);
|
||||
TIntermTyped* handleFunctionCall(const TSourceLoc&, TFunction*, TIntermTyped*);
|
||||
TIntermAggregate* assignClipCullDistance(const TSourceLoc&, TOperator, int semanticId, TIntermTyped* left, TIntermTyped* right);
|
||||
TIntermTyped* assignPosition(const TSourceLoc&, TOperator, TIntermTyped* left, TIntermTyped* right);
|
||||
TIntermTyped* assignFromFragCoord(const TSourceLoc&, TOperator, TIntermTyped* left, TIntermTyped* right);
|
||||
void decomposeIntrinsic(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
|
||||
void decomposeSampleMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
|
||||
void decomposeStructBufferMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
|
||||
void decomposeGeometryMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
|
||||
void pushFrontArguments(TIntermTyped* front, TIntermTyped*& arguments);
|
||||
void addInputArgumentConversions(const TFunction&, TIntermTyped*&);
|
||||
void expandArguments(const TSourceLoc&, const TFunction&, TIntermTyped*&);
|
||||
TIntermTyped* addOutputArgumentConversions(const TFunction&, TIntermOperator&);
|
||||
void builtInOpCheck(const TSourceLoc&, const TFunction&, TIntermOperator&);
|
||||
TFunction* makeConstructorCall(const TSourceLoc&, const TType&);
|
||||
void handleSemantic(TSourceLoc, TQualifier&, TBuiltInVariable, const TString& upperCase);
|
||||
void handlePackOffset(const TSourceLoc&, TQualifier&, const glslang::TString& location,
|
||||
const glslang::TString* component);
|
||||
void handleRegister(const TSourceLoc&, TQualifier&, const glslang::TString* profile, const glslang::TString& desc,
|
||||
int subComponent, const glslang::TString*);
|
||||
TIntermTyped* convertConditionalExpression(const TSourceLoc&, TIntermTyped*, bool mustBeScalar = true);
|
||||
TIntermAggregate* handleSamplerTextureCombine(const TSourceLoc& loc, TIntermTyped* argTex, TIntermTyped* argSampler);
|
||||
|
||||
bool parseMatrixSwizzleSelector(const TSourceLoc&, const TString&, int cols, int rows, TSwizzleSelectors<TMatrixSelector>&);
|
||||
int getMatrixComponentsColumn(int rows, const TSwizzleSelectors<TMatrixSelector>&);
|
||||
void assignError(const TSourceLoc&, const char* op, TString left, TString right);
|
||||
void unaryOpError(const TSourceLoc&, const char* op, TString operand);
|
||||
void binaryOpError(const TSourceLoc&, const char* op, TString left, TString right);
|
||||
void variableCheck(TIntermTyped*& nodePtr);
|
||||
void constantValueCheck(TIntermTyped* node, const char* token);
|
||||
void integerCheck(const TIntermTyped* node, const char* token);
|
||||
void globalCheck(const TSourceLoc&, const char* token);
|
||||
bool constructorError(const TSourceLoc&, TIntermNode*, TFunction&, TOperator, TType&);
|
||||
void arraySizeCheck(const TSourceLoc&, TIntermTyped* expr, TArraySize&);
|
||||
void arraySizeRequiredCheck(const TSourceLoc&, const TArraySizes&);
|
||||
void structArrayCheck(const TSourceLoc&, const TType& structure);
|
||||
bool voidErrorCheck(const TSourceLoc&, const TString&, TBasicType);
|
||||
void globalQualifierFix(const TSourceLoc&, TQualifier&);
|
||||
bool structQualifierErrorCheck(const TSourceLoc&, const TPublicType& pType);
|
||||
void mergeQualifiers(TQualifier& dst, const TQualifier& src);
|
||||
int computeSamplerTypeIndex(TSampler&);
|
||||
TSymbol* redeclareBuiltinVariable(const TSourceLoc&, const TString&, const TQualifier&, const TShaderQualifiers&);
|
||||
void paramFix(TType& type);
|
||||
void specializationCheck(const TSourceLoc&, const TType&, const char* op);
|
||||
|
||||
void setLayoutQualifier(const TSourceLoc&, TQualifier&, TString&);
|
||||
void setLayoutQualifier(const TSourceLoc&, TQualifier&, TString&, const TIntermTyped*);
|
||||
void setSpecConstantId(const TSourceLoc&, TQualifier&, int value);
|
||||
void mergeObjectLayoutQualifiers(TQualifier& dest, const TQualifier& src, bool inheritOnly);
|
||||
void checkNoShaderLayouts(const TSourceLoc&, const TShaderQualifiers&);
|
||||
|
||||
const TFunction* findFunction(const TSourceLoc& loc, TFunction& call, bool& builtIn, int& thisDepth, TIntermTyped*& args);
|
||||
void addGenMulArgumentConversion(const TSourceLoc& loc, TFunction& call, TIntermTyped*& args);
|
||||
void declareTypedef(const TSourceLoc&, const TString& identifier, const TType&);
|
||||
void declareStruct(const TSourceLoc&, TString& structName, TType&);
|
||||
TSymbol* lookupUserType(const TString&, TType&);
|
||||
TIntermNode* declareVariable(const TSourceLoc&, const TString& identifier, TType&, TIntermTyped* initializer = 0);
|
||||
void lengthenList(const TSourceLoc&, TIntermSequence& list, int size, TIntermTyped* scalarInit);
|
||||
TIntermTyped* handleConstructor(const TSourceLoc&, TIntermTyped*, const TType&);
|
||||
TIntermTyped* addConstructor(const TSourceLoc&, TIntermTyped*, const TType&);
|
||||
TIntermTyped* convertArray(TIntermTyped*, const TType&);
|
||||
TIntermTyped* constructAggregate(TIntermNode*, const TType&, int, const TSourceLoc&);
|
||||
TIntermTyped* constructBuiltIn(const TType&, TOperator, TIntermTyped*, const TSourceLoc&, bool subset);
|
||||
void declareBlock(const TSourceLoc&, TType&, const TString* instanceName = 0);
|
||||
void declareStructBufferCounter(const TSourceLoc& loc, const TType& bufferType, const TString& name);
|
||||
void fixBlockLocations(const TSourceLoc&, TQualifier&, TTypeList&, bool memberWithLocation, bool memberWithoutLocation);
|
||||
void fixXfbOffsets(TQualifier&, TTypeList&);
|
||||
void fixBlockUniformOffsets(const TQualifier&, TTypeList&);
|
||||
void addQualifierToExisting(const TSourceLoc&, TQualifier, const TString& identifier);
|
||||
void addQualifierToExisting(const TSourceLoc&, TQualifier, TIdentifierList&);
|
||||
void updateStandaloneQualifierDefaults(const TSourceLoc&, const TPublicType&);
|
||||
void wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode);
|
||||
TIntermNode* addSwitch(const TSourceLoc&, TIntermTyped* expression, TIntermAggregate* body, const TAttributes&);
|
||||
|
||||
void nestLooping() { ++loopNestingLevel; }
|
||||
void unnestLooping() { --loopNestingLevel; }
|
||||
void nestAnnotations() { ++annotationNestingLevel; }
|
||||
void unnestAnnotations() { --annotationNestingLevel; }
|
||||
int getAnnotationNestingLevel() { return annotationNestingLevel; }
|
||||
void pushScope() { symbolTable.push(); }
|
||||
void popScope() { symbolTable.pop(0); }
|
||||
|
||||
void pushThisScope(const TType&, const TVector<TFunctionDeclarator>&);
|
||||
void popThisScope() { symbolTable.pop(0); }
|
||||
|
||||
void pushImplicitThis(TVariable* thisParameter) { implicitThisStack.push_back(thisParameter); }
|
||||
void popImplicitThis() { implicitThisStack.pop_back(); }
|
||||
TVariable* getImplicitThis(int thisDepth) const { return implicitThisStack[implicitThisStack.size() - thisDepth]; }
|
||||
|
||||
void pushNamespace(const TString& name);
|
||||
void popNamespace();
|
||||
void getFullNamespaceName(TString*&) const;
|
||||
void addScopeMangler(TString&);
|
||||
|
||||
void beginParameterParsing(TFunction& function)
|
||||
{
|
||||
parsingEntrypointParameters = isEntrypointName(function.getName());
|
||||
}
|
||||
|
||||
void pushSwitchSequence(TIntermSequence* sequence) { switchSequenceStack.push_back(sequence); }
|
||||
void popSwitchSequence() { switchSequenceStack.pop_back(); }
|
||||
|
||||
virtual void growGlobalUniformBlock(const TSourceLoc&, TType&, const TString& memberName,
|
||||
TTypeList* typeList = nullptr) override;
|
||||
|
||||
// Apply L-value conversions. E.g, turning a write to a RWTexture into an ImageStore.
|
||||
TIntermTyped* handleLvalue(const TSourceLoc&, const char* op, TIntermTyped*& node);
|
||||
bool lValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*) override;
|
||||
|
||||
TLayoutFormat getLayoutFromTxType(const TSourceLoc&, const TType&);
|
||||
|
||||
bool handleOutputGeometry(const TSourceLoc&, const TLayoutGeometry& geometry);
|
||||
bool handleInputGeometry(const TSourceLoc&, const TLayoutGeometry& geometry);
|
||||
|
||||
// Determine selection control from attributes
|
||||
void handleSelectionAttributes(const TSourceLoc& loc, TIntermSelection*, const TAttributes& attributes);
|
||||
void handleSwitchAttributes(const TSourceLoc& loc, TIntermSwitch*, const TAttributes& attributes);
|
||||
|
||||
// Determine loop control from attributes
|
||||
void handleLoopAttributes(const TSourceLoc& loc, TIntermLoop*, const TAttributes& attributes);
|
||||
|
||||
// Share struct buffer deep types
|
||||
void shareStructBufferType(TType&);
|
||||
|
||||
// Set texture return type of the given sampler. Returns success (not all types are valid).
|
||||
bool setTextureReturnType(TSampler& sampler, const TType& retType, const TSourceLoc& loc);
|
||||
|
||||
// Obtain the sampler return type of the given sampler in retType.
|
||||
void getTextureReturnType(const TSampler& sampler, TType& retType) const;
|
||||
|
||||
TAttributeType attributeFromName(const TString& nameSpace, const TString& name) const;
|
||||
|
||||
protected:
|
||||
struct TFlattenData {
|
||||
TFlattenData() : nextBinding(TQualifier::layoutBindingEnd),
|
||||
nextLocation(TQualifier::layoutLocationEnd) { }
|
||||
TFlattenData(int nb, int nl) : nextBinding(nb), nextLocation(nl) { }
|
||||
|
||||
TVector<TVariable*> members; // individual flattened variables
|
||||
TVector<int> offsets; // offset to next tree level
|
||||
unsigned int nextBinding; // next binding to use.
|
||||
unsigned int nextLocation; // next location to use
|
||||
};
|
||||
|
||||
void fixConstInit(const TSourceLoc&, const TString& identifier, TType& type, TIntermTyped*& initializer);
|
||||
void inheritGlobalDefaults(TQualifier& dst) const;
|
||||
TVariable* makeInternalVariable(const char* name, const TType&) const;
|
||||
TVariable* makeInternalVariable(const TString& name, const TType& type) const {
|
||||
return makeInternalVariable(name.c_str(), type);
|
||||
}
|
||||
TIntermSymbol* makeInternalVariableNode(const TSourceLoc&, const char* name, const TType&) const;
|
||||
TVariable* declareNonArray(const TSourceLoc&, const TString& identifier, const TType&, bool track);
|
||||
void declareArray(const TSourceLoc&, const TString& identifier, const TType&, TSymbol*&, bool track);
|
||||
TIntermNode* executeDeclaration(const TSourceLoc&, TVariable* variable);
|
||||
TIntermNode* executeInitializer(const TSourceLoc&, TIntermTyped* initializer, TVariable* variable);
|
||||
TIntermTyped* convertInitializerList(const TSourceLoc&, const TType&, TIntermTyped* initializer, TIntermTyped* scalarInit);
|
||||
bool isScalarConstructor(const TIntermNode*);
|
||||
TOperator mapAtomicOp(const TSourceLoc& loc, TOperator op, bool isImage);
|
||||
bool isEntrypointName(const TString& name) { return name.compare(intermediate.getEntryPointName().c_str()) == 0; }
|
||||
|
||||
// Return true if this node requires L-value conversion (e.g, to an imageStore).
|
||||
bool shouldConvertLValue(const TIntermNode*) const;
|
||||
|
||||
// Array and struct flattening
|
||||
TIntermTyped* flattenAccess(TIntermTyped* base, int member);
|
||||
TIntermTyped* flattenAccess(long long uniqueId, int member, TStorageQualifier outerStorage, const TType&, int subset = -1);
|
||||
int findSubtreeOffset(const TIntermNode&) const;
|
||||
int findSubtreeOffset(const TType&, int subset, const TVector<int>& offsets) const;
|
||||
bool shouldFlatten(const TType&, TStorageQualifier, bool topLevel) const;
|
||||
bool wasFlattened(const TIntermTyped* node) const;
|
||||
bool wasFlattened(long long id) const { return flattenMap.find(id) != flattenMap.end(); }
|
||||
int addFlattenedMember(const TVariable&, const TType&, TFlattenData&, const TString& name, bool linkage,
|
||||
const TQualifier& outerQualifier, const TArraySizes* builtInArraySizes);
|
||||
|
||||
// Structure splitting (splits interstage built-in types into its own struct)
|
||||
void split(const TVariable&);
|
||||
void splitBuiltIn(const TString& baseName, const TType& memberType, const TArraySizes*, const TQualifier&);
|
||||
const TType& split(const TType& type, const TString& name, const TQualifier&);
|
||||
bool wasSplit(const TIntermTyped* node) const;
|
||||
bool wasSplit(long long id) const { return splitNonIoVars.find(id) != splitNonIoVars.end(); }
|
||||
TVariable* getSplitNonIoVar(long long id) const;
|
||||
void addPatchConstantInvocation();
|
||||
void fixTextureShadowModes();
|
||||
void finalizeAppendMethods();
|
||||
TIntermTyped* makeIntegerIndex(TIntermTyped*);
|
||||
|
||||
void fixBuiltInIoType(TType&);
|
||||
|
||||
void flatten(const TVariable& variable, bool linkage, bool arrayed = false);
|
||||
int flatten(const TVariable& variable, const TType&, TFlattenData&, TString name, bool linkage,
|
||||
const TQualifier& outerQualifier, const TArraySizes* builtInArraySizes);
|
||||
int flattenStruct(const TVariable& variable, const TType&, TFlattenData&, TString name, bool linkage,
|
||||
const TQualifier& outerQualifier, const TArraySizes* builtInArraySizes);
|
||||
int flattenArray(const TVariable& variable, const TType&, TFlattenData&, TString name, bool linkage,
|
||||
const TQualifier& outerQualifier);
|
||||
|
||||
bool hasUniform(const TQualifier& qualifier) const;
|
||||
void clearUniform(TQualifier& qualifier);
|
||||
bool isInputBuiltIn(const TQualifier& qualifier) const;
|
||||
bool hasInput(const TQualifier& qualifier) const;
|
||||
void correctOutput(TQualifier& qualifier);
|
||||
bool isOutputBuiltIn(const TQualifier& qualifier) const;
|
||||
bool hasOutput(const TQualifier& qualifier) const;
|
||||
void correctInput(TQualifier& qualifier);
|
||||
void correctUniform(TQualifier& qualifier);
|
||||
void clearUniformInputOutput(TQualifier& qualifier);
|
||||
|
||||
// Test method names
|
||||
bool isStructBufferMethod(const TString& name) const;
|
||||
void counterBufferType(const TSourceLoc& loc, TType& type);
|
||||
|
||||
// Return standard sample position array
|
||||
TIntermConstantUnion* getSamplePosArray(int count);
|
||||
|
||||
TType* getStructBufferContentType(const TType& type) const;
|
||||
bool isStructBufferType(const TType& type) const { return getStructBufferContentType(type) != nullptr; }
|
||||
TIntermTyped* indexStructBufferContent(const TSourceLoc& loc, TIntermTyped* buffer) const;
|
||||
TIntermTyped* getStructBufferCounter(const TSourceLoc& loc, TIntermTyped* buffer);
|
||||
TString getStructBuffCounterName(const TString&) const;
|
||||
void addStructBuffArguments(const TSourceLoc& loc, TIntermAggregate*&);
|
||||
void addStructBufferHiddenCounterParam(const TSourceLoc& loc, TParameter&, TIntermAggregate*&);
|
||||
|
||||
// Return true if this type is a reference. This is not currently a type method in case that's
|
||||
// a language specific answer.
|
||||
bool isReference(const TType& type) const { return isStructBufferType(type); }
|
||||
|
||||
// Return true if this a buffer type that has an associated counter buffer.
|
||||
bool hasStructBuffCounter(const TType&) const;
|
||||
|
||||
// Finalization step: remove unused buffer blocks from linkage (we don't know until the
|
||||
// shader is entirely compiled)
|
||||
void removeUnusedStructBufferCounters();
|
||||
|
||||
static bool isClipOrCullDistance(TBuiltInVariable);
|
||||
static bool isClipOrCullDistance(const TQualifier& qual) { return isClipOrCullDistance(qual.builtIn); }
|
||||
static bool isClipOrCullDistance(const TType& type) { return isClipOrCullDistance(type.getQualifier()); }
|
||||
|
||||
// Find the patch constant function (issues error, returns nullptr if not found)
|
||||
const TFunction* findPatchConstantFunction(const TSourceLoc& loc);
|
||||
|
||||
// Pass through to base class after remembering built-in mappings.
|
||||
using TParseContextBase::trackLinkage;
|
||||
void trackLinkage(TSymbol& variable) override;
|
||||
|
||||
void finish() override; // post-processing
|
||||
|
||||
// Linkage symbol helpers
|
||||
TIntermSymbol* findTessLinkageSymbol(TBuiltInVariable biType) const;
|
||||
|
||||
// Current state of parsing
|
||||
int annotationNestingLevel; // 0 if outside all annotations
|
||||
|
||||
HlslParseContext(HlslParseContext&);
|
||||
HlslParseContext& operator=(HlslParseContext&);
|
||||
|
||||
static const int maxSamplerIndex = EsdNumDims * (EbtNumTypes * (2 * 2 * 2)); // see computeSamplerTypeIndex()
|
||||
TQualifier globalBufferDefaults;
|
||||
TQualifier globalUniformDefaults;
|
||||
TQualifier globalInputDefaults;
|
||||
TQualifier globalOutputDefaults;
|
||||
TString currentCaller; // name of last function body entered (not valid when at global scope)
|
||||
TIdSetType inductiveLoopIds;
|
||||
TVector<TIntermTyped*> needsIndexLimitationChecking;
|
||||
|
||||
//
|
||||
// Geometry shader input arrays:
|
||||
// - array sizing is based on input primitive and/or explicit size
|
||||
//
|
||||
// Tessellation control output arrays:
|
||||
// - array sizing is based on output layout(vertices=...) and/or explicit size
|
||||
//
|
||||
// Both:
|
||||
// - array sizing is retroactive
|
||||
// - built-in block redeclarations interact with this
|
||||
//
|
||||
// Design:
|
||||
// - use a per-context "resize-list", a list of symbols whose array sizes
|
||||
// can be fixed
|
||||
//
|
||||
// - the resize-list starts empty at beginning of user-shader compilation, it does
|
||||
// not have built-ins in it
|
||||
//
|
||||
// - on built-in array use: copyUp() symbol and add it to the resize-list
|
||||
//
|
||||
// - on user array declaration: add it to the resize-list
|
||||
//
|
||||
// - on block redeclaration: copyUp() symbol and add it to the resize-list
|
||||
// * note, that appropriately gives an error if redeclaring a block that
|
||||
// was already used and hence already copied-up
|
||||
//
|
||||
// - on seeing a layout declaration that sizes the array, fix everything in the
|
||||
// resize-list, giving errors for mismatch
|
||||
//
|
||||
// - on seeing an array size declaration, give errors on mismatch between it and previous
|
||||
// array-sizing declarations
|
||||
//
|
||||
TVector<TSymbol*> ioArraySymbolResizeList;
|
||||
|
||||
TMap<long long, TFlattenData> flattenMap;
|
||||
|
||||
// IO-type map. Maps a pure symbol-table form of a structure-member list into
|
||||
// each of the (up to) three kinds of IO, as each as different allowed decorations,
|
||||
// but HLSL allows mixing all in the same structure.
|
||||
struct tIoKinds {
|
||||
TTypeList* input;
|
||||
TTypeList* output;
|
||||
TTypeList* uniform;
|
||||
};
|
||||
TMap<const TTypeList*, tIoKinds> ioTypeMap;
|
||||
|
||||
// Structure splitting data:
|
||||
TMap<long long, TVariable*> splitNonIoVars; // variables with the built-in interstage IO removed, indexed by unique ID.
|
||||
|
||||
// Structuredbuffer shared types. Typically there are only a few.
|
||||
TVector<TType*> structBufferTypes;
|
||||
|
||||
// This tracks texture sample user structure return types. Only a limited number are supported, as
|
||||
// may fit in TSampler::structReturnIndex.
|
||||
TVector<TTypeList*> textureReturnStruct;
|
||||
|
||||
TMap<TString, bool> structBufferCounter; // true if counter buffer is in use
|
||||
|
||||
// The built-in interstage IO map considers e.g, EvqPosition on input and output separately, so that we
|
||||
// can build the linkage correctly if position appears on both sides. Otherwise, multiple positions
|
||||
// are considered identical.
|
||||
struct tInterstageIoData {
|
||||
tInterstageIoData(TBuiltInVariable bi, TStorageQualifier q) :
|
||||
builtIn(bi), storage(q) { }
|
||||
|
||||
TBuiltInVariable builtIn;
|
||||
TStorageQualifier storage;
|
||||
|
||||
// ordering for maps
|
||||
bool operator<(const tInterstageIoData d) const {
|
||||
return (builtIn != d.builtIn) ? (builtIn < d.builtIn) : (storage < d.storage);
|
||||
}
|
||||
};
|
||||
|
||||
TMap<tInterstageIoData, TVariable*> splitBuiltIns; // split built-ins, indexed by built-in type.
|
||||
TVariable* inputPatch; // input patch is special for PCF: it's the only non-builtin PCF input,
|
||||
// and is handled as a pseudo-builtin.
|
||||
|
||||
unsigned int nextInLocation;
|
||||
unsigned int nextOutLocation;
|
||||
|
||||
TFunction* entryPointFunction;
|
||||
TIntermNode* entryPointFunctionBody;
|
||||
|
||||
TString patchConstantFunctionName; // hull shader patch constant function name, from function level attribute.
|
||||
TMap<TBuiltInVariable, TSymbol*> builtInTessLinkageSymbols; // used for tessellation, finding declared built-ins
|
||||
|
||||
TVector<TString> currentTypePrefix; // current scoping prefix for nested structures
|
||||
TVector<TVariable*> implicitThisStack; // currently active 'this' variables for nested structures
|
||||
|
||||
TVariable* gsStreamOutput; // geometry shader stream outputs, for emit (Append method)
|
||||
|
||||
TVariable* clipDistanceOutput; // synthesized clip distance out variable (shader might have >1)
|
||||
TVariable* cullDistanceOutput; // synthesized cull distance out variable (shader might have >1)
|
||||
TVariable* clipDistanceInput; // synthesized clip distance in variable (shader might have >1)
|
||||
TVariable* cullDistanceInput; // synthesized cull distance in variable (shader might have >1)
|
||||
|
||||
static const int maxClipCullRegs = 2;
|
||||
std::array<int, maxClipCullRegs> clipSemanticNSizeIn; // vector, indexed by clip semantic ID
|
||||
std::array<int, maxClipCullRegs> cullSemanticNSizeIn; // vector, indexed by cull semantic ID
|
||||
std::array<int, maxClipCullRegs> clipSemanticNSizeOut; // vector, indexed by clip semantic ID
|
||||
std::array<int, maxClipCullRegs> cullSemanticNSizeOut; // vector, indexed by cull semantic ID
|
||||
|
||||
// This tracks the first (mip level) argument to the .mips[][] operator. Since this can be nested as
|
||||
// in tx.mips[tx.mips[0][1].x][2], we need a stack. We also track the TSourceLoc for error reporting
|
||||
// purposes.
|
||||
struct tMipsOperatorData {
|
||||
tMipsOperatorData(TSourceLoc l, TIntermTyped* m) : loc(l), mipLevel(m) { }
|
||||
TSourceLoc loc;
|
||||
TIntermTyped* mipLevel;
|
||||
};
|
||||
|
||||
TVector<tMipsOperatorData> mipsOperatorMipArg;
|
||||
|
||||
// The geometry output stream is not copied out from the entry point as a typical output variable
|
||||
// is. It's written via EmitVertex (hlsl=Append), which may happen in arbitrary control flow.
|
||||
// For this we need the real output symbol. Since it may not be known at the time and Append()
|
||||
// method is parsed, the sequence will be patched during finalization.
|
||||
struct tGsAppendData {
|
||||
TIntermAggregate* node;
|
||||
TSourceLoc loc;
|
||||
};
|
||||
|
||||
TVector<tGsAppendData> gsAppends;
|
||||
|
||||
// A texture object may be used with shadow and non-shadow samplers, but both may not be
|
||||
// alive post-DCE in the same shader. We do not know at compilation time which are alive: that's
|
||||
// only known post-DCE. If a texture is used both ways, we create two textures, and
|
||||
// leave the elimiation of one to the optimizer. This maps the shader variant to
|
||||
// the shadow variant.
|
||||
//
|
||||
// This can be removed if and when the texture shadow code in
|
||||
// HlslParseContext::handleSamplerTextureCombine is removed.
|
||||
struct tShadowTextureSymbols {
|
||||
tShadowTextureSymbols() { symId.fill(-1); }
|
||||
|
||||
void set(bool shadow, long long id) { symId[int(shadow)] = id; }
|
||||
long long get(bool shadow) const { return symId[int(shadow)]; }
|
||||
|
||||
// True if this texture has been seen with both shadow and non-shadow modes
|
||||
bool overloaded() const { return symId[0] != -1 && symId[1] != -1; }
|
||||
bool isShadowId(long long id) const { return symId[1] == id; }
|
||||
|
||||
private:
|
||||
std::array<long long, 2> symId;
|
||||
};
|
||||
|
||||
TMap<long long, tShadowTextureSymbols*> textureShadowVariant;
|
||||
bool parsingEntrypointParameters;
|
||||
};
|
||||
|
||||
// This is the prefix we use for built-in methods to avoid namespace collisions with
|
||||
// global scope user functions.
|
||||
// TODO: this would be better as a nonparseable character, but that would
|
||||
// require changing the scanner.
|
||||
#define BUILTIN_PREFIX "__BI_"
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // HLSL_PARSE_INCLUDED_
|
||||
1259
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/HLSL/hlslParseables.cpp
vendored
Normal file
1259
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/HLSL/hlslParseables.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,64 @@
|
||||
//
|
||||
// Copyright (C) 2016 LunarG, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef _HLSLPARSEABLES_INCLUDED_
|
||||
#define _HLSLPARSEABLES_INCLUDED_
|
||||
|
||||
#include "../MachineIndependent/Initialize.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
//
|
||||
// This is an HLSL specific derivation of TBuiltInParseables. See comment
|
||||
// above TBuiltInParseables for details.
|
||||
//
|
||||
class TBuiltInParseablesHlsl : public TBuiltInParseables {
|
||||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
TBuiltInParseablesHlsl();
|
||||
void initialize(int version, EProfile, const SpvVersion& spvVersion);
|
||||
void initialize(const TBuiltInResource& resources, int version, EProfile, const SpvVersion& spvVersion, EShLanguage);
|
||||
|
||||
void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable);
|
||||
|
||||
void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources);
|
||||
|
||||
private:
|
||||
void createMatTimesMat();
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _HLSLPARSEABLES_INCLUDED_
|
||||
@ -0,0 +1,903 @@
|
||||
//
|
||||
// Copyright (C) 2016 Google, Inc.
|
||||
// Copyright (C) 2016 LunarG, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of Google, Inc., nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
//
|
||||
// HLSL scanning, leveraging the scanning done by the preprocessor.
|
||||
//
|
||||
|
||||
#include <cstring>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "../Include/Types.h"
|
||||
#include "../MachineIndependent/SymbolTable.h"
|
||||
#include "../MachineIndependent/ParseHelper.h"
|
||||
#include "hlslScanContext.h"
|
||||
#include "hlslTokens.h"
|
||||
|
||||
// preprocessor includes
|
||||
#include "../MachineIndependent/preprocessor/PpContext.h"
|
||||
#include "../MachineIndependent/preprocessor/PpTokens.h"
|
||||
|
||||
namespace {
|
||||
|
||||
struct str_eq
|
||||
{
|
||||
bool operator()(const char* lhs, const char* rhs) const
|
||||
{
|
||||
return strcmp(lhs, rhs) == 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct str_hash
|
||||
{
|
||||
size_t operator()(const char* str) const
|
||||
{
|
||||
// djb2
|
||||
unsigned long hash = 5381;
|
||||
int c;
|
||||
|
||||
while ((c = *str++) != 0)
|
||||
hash = ((hash << 5) + hash) + c;
|
||||
|
||||
return hash;
|
||||
}
|
||||
};
|
||||
|
||||
// A single global usable by all threads, by all versions, by all languages.
|
||||
// After a single process-level initialization, this is read only and thread safe
|
||||
std::unordered_map<const char*, glslang::EHlslTokenClass, str_hash, str_eq>* KeywordMap = nullptr;
|
||||
std::unordered_set<const char*, str_hash, str_eq>* ReservedSet = nullptr;
|
||||
std::unordered_map<const char*, glslang::TBuiltInVariable, str_hash, str_eq>* SemanticMap = nullptr;
|
||||
|
||||
};
|
||||
|
||||
namespace glslang {
|
||||
|
||||
void HlslScanContext::fillInKeywordMap()
|
||||
{
|
||||
if (KeywordMap != nullptr) {
|
||||
// this is really an error, as this should called only once per process
|
||||
// but, the only risk is if two threads called simultaneously
|
||||
return;
|
||||
}
|
||||
KeywordMap = new std::unordered_map<const char*, EHlslTokenClass, str_hash, str_eq>;
|
||||
|
||||
(*KeywordMap)["static"] = EHTokStatic;
|
||||
(*KeywordMap)["const"] = EHTokConst;
|
||||
(*KeywordMap)["unorm"] = EHTokUnorm;
|
||||
(*KeywordMap)["snorm"] = EHTokSNorm;
|
||||
(*KeywordMap)["extern"] = EHTokExtern;
|
||||
(*KeywordMap)["uniform"] = EHTokUniform;
|
||||
(*KeywordMap)["volatile"] = EHTokVolatile;
|
||||
(*KeywordMap)["precise"] = EHTokPrecise;
|
||||
(*KeywordMap)["shared"] = EHTokShared;
|
||||
(*KeywordMap)["groupshared"] = EHTokGroupShared;
|
||||
(*KeywordMap)["linear"] = EHTokLinear;
|
||||
(*KeywordMap)["centroid"] = EHTokCentroid;
|
||||
(*KeywordMap)["nointerpolation"] = EHTokNointerpolation;
|
||||
(*KeywordMap)["noperspective"] = EHTokNoperspective;
|
||||
(*KeywordMap)["sample"] = EHTokSample;
|
||||
(*KeywordMap)["row_major"] = EHTokRowMajor;
|
||||
(*KeywordMap)["column_major"] = EHTokColumnMajor;
|
||||
(*KeywordMap)["packoffset"] = EHTokPackOffset;
|
||||
(*KeywordMap)["in"] = EHTokIn;
|
||||
(*KeywordMap)["out"] = EHTokOut;
|
||||
(*KeywordMap)["inout"] = EHTokInOut;
|
||||
(*KeywordMap)["layout"] = EHTokLayout;
|
||||
(*KeywordMap)["globallycoherent"] = EHTokGloballyCoherent;
|
||||
(*KeywordMap)["inline"] = EHTokInline;
|
||||
|
||||
(*KeywordMap)["point"] = EHTokPoint;
|
||||
(*KeywordMap)["line"] = EHTokLine;
|
||||
(*KeywordMap)["triangle"] = EHTokTriangle;
|
||||
(*KeywordMap)["lineadj"] = EHTokLineAdj;
|
||||
(*KeywordMap)["triangleadj"] = EHTokTriangleAdj;
|
||||
|
||||
(*KeywordMap)["PointStream"] = EHTokPointStream;
|
||||
(*KeywordMap)["LineStream"] = EHTokLineStream;
|
||||
(*KeywordMap)["TriangleStream"] = EHTokTriangleStream;
|
||||
|
||||
(*KeywordMap)["InputPatch"] = EHTokInputPatch;
|
||||
(*KeywordMap)["OutputPatch"] = EHTokOutputPatch;
|
||||
|
||||
(*KeywordMap)["Buffer"] = EHTokBuffer;
|
||||
(*KeywordMap)["vector"] = EHTokVector;
|
||||
(*KeywordMap)["matrix"] = EHTokMatrix;
|
||||
|
||||
(*KeywordMap)["void"] = EHTokVoid;
|
||||
(*KeywordMap)["string"] = EHTokString;
|
||||
(*KeywordMap)["bool"] = EHTokBool;
|
||||
(*KeywordMap)["int"] = EHTokInt;
|
||||
(*KeywordMap)["uint"] = EHTokUint;
|
||||
(*KeywordMap)["uint64_t"] = EHTokUint64;
|
||||
(*KeywordMap)["dword"] = EHTokDword;
|
||||
(*KeywordMap)["half"] = EHTokHalf;
|
||||
(*KeywordMap)["float"] = EHTokFloat;
|
||||
(*KeywordMap)["double"] = EHTokDouble;
|
||||
(*KeywordMap)["min16float"] = EHTokMin16float;
|
||||
(*KeywordMap)["min10float"] = EHTokMin10float;
|
||||
(*KeywordMap)["min16int"] = EHTokMin16int;
|
||||
(*KeywordMap)["min12int"] = EHTokMin12int;
|
||||
(*KeywordMap)["min16uint"] = EHTokMin16uint;
|
||||
|
||||
(*KeywordMap)["bool1"] = EHTokBool1;
|
||||
(*KeywordMap)["bool2"] = EHTokBool2;
|
||||
(*KeywordMap)["bool3"] = EHTokBool3;
|
||||
(*KeywordMap)["bool4"] = EHTokBool4;
|
||||
(*KeywordMap)["float1"] = EHTokFloat1;
|
||||
(*KeywordMap)["float2"] = EHTokFloat2;
|
||||
(*KeywordMap)["float3"] = EHTokFloat3;
|
||||
(*KeywordMap)["float4"] = EHTokFloat4;
|
||||
(*KeywordMap)["int1"] = EHTokInt1;
|
||||
(*KeywordMap)["int2"] = EHTokInt2;
|
||||
(*KeywordMap)["int3"] = EHTokInt3;
|
||||
(*KeywordMap)["int4"] = EHTokInt4;
|
||||
(*KeywordMap)["double1"] = EHTokDouble1;
|
||||
(*KeywordMap)["double2"] = EHTokDouble2;
|
||||
(*KeywordMap)["double3"] = EHTokDouble3;
|
||||
(*KeywordMap)["double4"] = EHTokDouble4;
|
||||
(*KeywordMap)["uint1"] = EHTokUint1;
|
||||
(*KeywordMap)["uint2"] = EHTokUint2;
|
||||
(*KeywordMap)["uint3"] = EHTokUint3;
|
||||
(*KeywordMap)["uint4"] = EHTokUint4;
|
||||
|
||||
(*KeywordMap)["half1"] = EHTokHalf1;
|
||||
(*KeywordMap)["half2"] = EHTokHalf2;
|
||||
(*KeywordMap)["half3"] = EHTokHalf3;
|
||||
(*KeywordMap)["half4"] = EHTokHalf4;
|
||||
(*KeywordMap)["min16float1"] = EHTokMin16float1;
|
||||
(*KeywordMap)["min16float2"] = EHTokMin16float2;
|
||||
(*KeywordMap)["min16float3"] = EHTokMin16float3;
|
||||
(*KeywordMap)["min16float4"] = EHTokMin16float4;
|
||||
(*KeywordMap)["min10float1"] = EHTokMin10float1;
|
||||
(*KeywordMap)["min10float2"] = EHTokMin10float2;
|
||||
(*KeywordMap)["min10float3"] = EHTokMin10float3;
|
||||
(*KeywordMap)["min10float4"] = EHTokMin10float4;
|
||||
(*KeywordMap)["min16int1"] = EHTokMin16int1;
|
||||
(*KeywordMap)["min16int2"] = EHTokMin16int2;
|
||||
(*KeywordMap)["min16int3"] = EHTokMin16int3;
|
||||
(*KeywordMap)["min16int4"] = EHTokMin16int4;
|
||||
(*KeywordMap)["min12int1"] = EHTokMin12int1;
|
||||
(*KeywordMap)["min12int2"] = EHTokMin12int2;
|
||||
(*KeywordMap)["min12int3"] = EHTokMin12int3;
|
||||
(*KeywordMap)["min12int4"] = EHTokMin12int4;
|
||||
(*KeywordMap)["min16uint1"] = EHTokMin16uint1;
|
||||
(*KeywordMap)["min16uint2"] = EHTokMin16uint2;
|
||||
(*KeywordMap)["min16uint3"] = EHTokMin16uint3;
|
||||
(*KeywordMap)["min16uint4"] = EHTokMin16uint4;
|
||||
|
||||
(*KeywordMap)["bool1x1"] = EHTokBool1x1;
|
||||
(*KeywordMap)["bool1x2"] = EHTokBool1x2;
|
||||
(*KeywordMap)["bool1x3"] = EHTokBool1x3;
|
||||
(*KeywordMap)["bool1x4"] = EHTokBool1x4;
|
||||
(*KeywordMap)["bool2x1"] = EHTokBool2x1;
|
||||
(*KeywordMap)["bool2x2"] = EHTokBool2x2;
|
||||
(*KeywordMap)["bool2x3"] = EHTokBool2x3;
|
||||
(*KeywordMap)["bool2x4"] = EHTokBool2x4;
|
||||
(*KeywordMap)["bool3x1"] = EHTokBool3x1;
|
||||
(*KeywordMap)["bool3x2"] = EHTokBool3x2;
|
||||
(*KeywordMap)["bool3x3"] = EHTokBool3x3;
|
||||
(*KeywordMap)["bool3x4"] = EHTokBool3x4;
|
||||
(*KeywordMap)["bool4x1"] = EHTokBool4x1;
|
||||
(*KeywordMap)["bool4x2"] = EHTokBool4x2;
|
||||
(*KeywordMap)["bool4x3"] = EHTokBool4x3;
|
||||
(*KeywordMap)["bool4x4"] = EHTokBool4x4;
|
||||
(*KeywordMap)["int1x1"] = EHTokInt1x1;
|
||||
(*KeywordMap)["int1x2"] = EHTokInt1x2;
|
||||
(*KeywordMap)["int1x3"] = EHTokInt1x3;
|
||||
(*KeywordMap)["int1x4"] = EHTokInt1x4;
|
||||
(*KeywordMap)["int2x1"] = EHTokInt2x1;
|
||||
(*KeywordMap)["int2x2"] = EHTokInt2x2;
|
||||
(*KeywordMap)["int2x3"] = EHTokInt2x3;
|
||||
(*KeywordMap)["int2x4"] = EHTokInt2x4;
|
||||
(*KeywordMap)["int3x1"] = EHTokInt3x1;
|
||||
(*KeywordMap)["int3x2"] = EHTokInt3x2;
|
||||
(*KeywordMap)["int3x3"] = EHTokInt3x3;
|
||||
(*KeywordMap)["int3x4"] = EHTokInt3x4;
|
||||
(*KeywordMap)["int4x1"] = EHTokInt4x1;
|
||||
(*KeywordMap)["int4x2"] = EHTokInt4x2;
|
||||
(*KeywordMap)["int4x3"] = EHTokInt4x3;
|
||||
(*KeywordMap)["int4x4"] = EHTokInt4x4;
|
||||
(*KeywordMap)["uint1x1"] = EHTokUint1x1;
|
||||
(*KeywordMap)["uint1x2"] = EHTokUint1x2;
|
||||
(*KeywordMap)["uint1x3"] = EHTokUint1x3;
|
||||
(*KeywordMap)["uint1x4"] = EHTokUint1x4;
|
||||
(*KeywordMap)["uint2x1"] = EHTokUint2x1;
|
||||
(*KeywordMap)["uint2x2"] = EHTokUint2x2;
|
||||
(*KeywordMap)["uint2x3"] = EHTokUint2x3;
|
||||
(*KeywordMap)["uint2x4"] = EHTokUint2x4;
|
||||
(*KeywordMap)["uint3x1"] = EHTokUint3x1;
|
||||
(*KeywordMap)["uint3x2"] = EHTokUint3x2;
|
||||
(*KeywordMap)["uint3x3"] = EHTokUint3x3;
|
||||
(*KeywordMap)["uint3x4"] = EHTokUint3x4;
|
||||
(*KeywordMap)["uint4x1"] = EHTokUint4x1;
|
||||
(*KeywordMap)["uint4x2"] = EHTokUint4x2;
|
||||
(*KeywordMap)["uint4x3"] = EHTokUint4x3;
|
||||
(*KeywordMap)["uint4x4"] = EHTokUint4x4;
|
||||
(*KeywordMap)["bool1x1"] = EHTokBool1x1;
|
||||
(*KeywordMap)["bool1x2"] = EHTokBool1x2;
|
||||
(*KeywordMap)["bool1x3"] = EHTokBool1x3;
|
||||
(*KeywordMap)["bool1x4"] = EHTokBool1x4;
|
||||
(*KeywordMap)["bool2x1"] = EHTokBool2x1;
|
||||
(*KeywordMap)["bool2x2"] = EHTokBool2x2;
|
||||
(*KeywordMap)["bool2x3"] = EHTokBool2x3;
|
||||
(*KeywordMap)["bool2x4"] = EHTokBool2x4;
|
||||
(*KeywordMap)["bool3x1"] = EHTokBool3x1;
|
||||
(*KeywordMap)["bool3x2"] = EHTokBool3x2;
|
||||
(*KeywordMap)["bool3x3"] = EHTokBool3x3;
|
||||
(*KeywordMap)["bool3x4"] = EHTokBool3x4;
|
||||
(*KeywordMap)["bool4x1"] = EHTokBool4x1;
|
||||
(*KeywordMap)["bool4x2"] = EHTokBool4x2;
|
||||
(*KeywordMap)["bool4x3"] = EHTokBool4x3;
|
||||
(*KeywordMap)["bool4x4"] = EHTokBool4x4;
|
||||
(*KeywordMap)["float1x1"] = EHTokFloat1x1;
|
||||
(*KeywordMap)["float1x2"] = EHTokFloat1x2;
|
||||
(*KeywordMap)["float1x3"] = EHTokFloat1x3;
|
||||
(*KeywordMap)["float1x4"] = EHTokFloat1x4;
|
||||
(*KeywordMap)["float2x1"] = EHTokFloat2x1;
|
||||
(*KeywordMap)["float2x2"] = EHTokFloat2x2;
|
||||
(*KeywordMap)["float2x3"] = EHTokFloat2x3;
|
||||
(*KeywordMap)["float2x4"] = EHTokFloat2x4;
|
||||
(*KeywordMap)["float3x1"] = EHTokFloat3x1;
|
||||
(*KeywordMap)["float3x2"] = EHTokFloat3x2;
|
||||
(*KeywordMap)["float3x3"] = EHTokFloat3x3;
|
||||
(*KeywordMap)["float3x4"] = EHTokFloat3x4;
|
||||
(*KeywordMap)["float4x1"] = EHTokFloat4x1;
|
||||
(*KeywordMap)["float4x2"] = EHTokFloat4x2;
|
||||
(*KeywordMap)["float4x3"] = EHTokFloat4x3;
|
||||
(*KeywordMap)["float4x4"] = EHTokFloat4x4;
|
||||
(*KeywordMap)["half1x1"] = EHTokHalf1x1;
|
||||
(*KeywordMap)["half1x2"] = EHTokHalf1x2;
|
||||
(*KeywordMap)["half1x3"] = EHTokHalf1x3;
|
||||
(*KeywordMap)["half1x4"] = EHTokHalf1x4;
|
||||
(*KeywordMap)["half2x1"] = EHTokHalf2x1;
|
||||
(*KeywordMap)["half2x2"] = EHTokHalf2x2;
|
||||
(*KeywordMap)["half2x3"] = EHTokHalf2x3;
|
||||
(*KeywordMap)["half2x4"] = EHTokHalf2x4;
|
||||
(*KeywordMap)["half3x1"] = EHTokHalf3x1;
|
||||
(*KeywordMap)["half3x2"] = EHTokHalf3x2;
|
||||
(*KeywordMap)["half3x3"] = EHTokHalf3x3;
|
||||
(*KeywordMap)["half3x4"] = EHTokHalf3x4;
|
||||
(*KeywordMap)["half4x1"] = EHTokHalf4x1;
|
||||
(*KeywordMap)["half4x2"] = EHTokHalf4x2;
|
||||
(*KeywordMap)["half4x3"] = EHTokHalf4x3;
|
||||
(*KeywordMap)["half4x4"] = EHTokHalf4x4;
|
||||
(*KeywordMap)["double1x1"] = EHTokDouble1x1;
|
||||
(*KeywordMap)["double1x2"] = EHTokDouble1x2;
|
||||
(*KeywordMap)["double1x3"] = EHTokDouble1x3;
|
||||
(*KeywordMap)["double1x4"] = EHTokDouble1x4;
|
||||
(*KeywordMap)["double2x1"] = EHTokDouble2x1;
|
||||
(*KeywordMap)["double2x2"] = EHTokDouble2x2;
|
||||
(*KeywordMap)["double2x3"] = EHTokDouble2x3;
|
||||
(*KeywordMap)["double2x4"] = EHTokDouble2x4;
|
||||
(*KeywordMap)["double3x1"] = EHTokDouble3x1;
|
||||
(*KeywordMap)["double3x2"] = EHTokDouble3x2;
|
||||
(*KeywordMap)["double3x3"] = EHTokDouble3x3;
|
||||
(*KeywordMap)["double3x4"] = EHTokDouble3x4;
|
||||
(*KeywordMap)["double4x1"] = EHTokDouble4x1;
|
||||
(*KeywordMap)["double4x2"] = EHTokDouble4x2;
|
||||
(*KeywordMap)["double4x3"] = EHTokDouble4x3;
|
||||
(*KeywordMap)["double4x4"] = EHTokDouble4x4;
|
||||
|
||||
(*KeywordMap)["sampler"] = EHTokSampler;
|
||||
(*KeywordMap)["sampler1D"] = EHTokSampler1d;
|
||||
(*KeywordMap)["sampler2D"] = EHTokSampler2d;
|
||||
(*KeywordMap)["sampler3D"] = EHTokSampler3d;
|
||||
(*KeywordMap)["samplerCUBE"] = EHTokSamplerCube;
|
||||
(*KeywordMap)["sampler_state"] = EHTokSamplerState;
|
||||
(*KeywordMap)["SamplerState"] = EHTokSamplerState;
|
||||
(*KeywordMap)["SamplerComparisonState"] = EHTokSamplerComparisonState;
|
||||
(*KeywordMap)["texture"] = EHTokTexture;
|
||||
(*KeywordMap)["Texture1D"] = EHTokTexture1d;
|
||||
(*KeywordMap)["Texture1DArray"] = EHTokTexture1darray;
|
||||
(*KeywordMap)["Texture2D"] = EHTokTexture2d;
|
||||
(*KeywordMap)["Texture2DArray"] = EHTokTexture2darray;
|
||||
(*KeywordMap)["Texture3D"] = EHTokTexture3d;
|
||||
(*KeywordMap)["TextureCube"] = EHTokTextureCube;
|
||||
(*KeywordMap)["TextureCubeArray"] = EHTokTextureCubearray;
|
||||
(*KeywordMap)["Texture2DMS"] = EHTokTexture2DMS;
|
||||
(*KeywordMap)["Texture2DMSArray"] = EHTokTexture2DMSarray;
|
||||
(*KeywordMap)["RWTexture1D"] = EHTokRWTexture1d;
|
||||
(*KeywordMap)["RWTexture1DArray"] = EHTokRWTexture1darray;
|
||||
(*KeywordMap)["RWTexture2D"] = EHTokRWTexture2d;
|
||||
(*KeywordMap)["RWTexture2DArray"] = EHTokRWTexture2darray;
|
||||
(*KeywordMap)["RWTexture3D"] = EHTokRWTexture3d;
|
||||
(*KeywordMap)["RWBuffer"] = EHTokRWBuffer;
|
||||
(*KeywordMap)["SubpassInput"] = EHTokSubpassInput;
|
||||
(*KeywordMap)["SubpassInputMS"] = EHTokSubpassInputMS;
|
||||
|
||||
(*KeywordMap)["AppendStructuredBuffer"] = EHTokAppendStructuredBuffer;
|
||||
(*KeywordMap)["ByteAddressBuffer"] = EHTokByteAddressBuffer;
|
||||
(*KeywordMap)["ConsumeStructuredBuffer"] = EHTokConsumeStructuredBuffer;
|
||||
(*KeywordMap)["RWByteAddressBuffer"] = EHTokRWByteAddressBuffer;
|
||||
(*KeywordMap)["RWStructuredBuffer"] = EHTokRWStructuredBuffer;
|
||||
(*KeywordMap)["StructuredBuffer"] = EHTokStructuredBuffer;
|
||||
(*KeywordMap)["TextureBuffer"] = EHTokTextureBuffer;
|
||||
|
||||
(*KeywordMap)["class"] = EHTokClass;
|
||||
(*KeywordMap)["struct"] = EHTokStruct;
|
||||
(*KeywordMap)["cbuffer"] = EHTokCBuffer;
|
||||
(*KeywordMap)["ConstantBuffer"] = EHTokConstantBuffer;
|
||||
(*KeywordMap)["tbuffer"] = EHTokTBuffer;
|
||||
(*KeywordMap)["typedef"] = EHTokTypedef;
|
||||
(*KeywordMap)["this"] = EHTokThis;
|
||||
(*KeywordMap)["namespace"] = EHTokNamespace;
|
||||
|
||||
(*KeywordMap)["true"] = EHTokBoolConstant;
|
||||
(*KeywordMap)["false"] = EHTokBoolConstant;
|
||||
|
||||
(*KeywordMap)["for"] = EHTokFor;
|
||||
(*KeywordMap)["do"] = EHTokDo;
|
||||
(*KeywordMap)["while"] = EHTokWhile;
|
||||
(*KeywordMap)["break"] = EHTokBreak;
|
||||
(*KeywordMap)["continue"] = EHTokContinue;
|
||||
(*KeywordMap)["if"] = EHTokIf;
|
||||
(*KeywordMap)["else"] = EHTokElse;
|
||||
(*KeywordMap)["discard"] = EHTokDiscard;
|
||||
(*KeywordMap)["return"] = EHTokReturn;
|
||||
(*KeywordMap)["switch"] = EHTokSwitch;
|
||||
(*KeywordMap)["case"] = EHTokCase;
|
||||
(*KeywordMap)["default"] = EHTokDefault;
|
||||
|
||||
// TODO: get correct set here
|
||||
ReservedSet = new std::unordered_set<const char*, str_hash, str_eq>;
|
||||
|
||||
ReservedSet->insert("auto");
|
||||
ReservedSet->insert("catch");
|
||||
ReservedSet->insert("char");
|
||||
ReservedSet->insert("const_cast");
|
||||
ReservedSet->insert("enum");
|
||||
ReservedSet->insert("explicit");
|
||||
ReservedSet->insert("friend");
|
||||
ReservedSet->insert("goto");
|
||||
ReservedSet->insert("long");
|
||||
ReservedSet->insert("mutable");
|
||||
ReservedSet->insert("new");
|
||||
ReservedSet->insert("operator");
|
||||
ReservedSet->insert("private");
|
||||
ReservedSet->insert("protected");
|
||||
ReservedSet->insert("public");
|
||||
ReservedSet->insert("reinterpret_cast");
|
||||
ReservedSet->insert("short");
|
||||
ReservedSet->insert("signed");
|
||||
ReservedSet->insert("sizeof");
|
||||
ReservedSet->insert("static_cast");
|
||||
ReservedSet->insert("template");
|
||||
ReservedSet->insert("throw");
|
||||
ReservedSet->insert("try");
|
||||
ReservedSet->insert("typename");
|
||||
ReservedSet->insert("union");
|
||||
ReservedSet->insert("unsigned");
|
||||
ReservedSet->insert("using");
|
||||
ReservedSet->insert("virtual");
|
||||
|
||||
SemanticMap = new std::unordered_map<const char*, glslang::TBuiltInVariable, str_hash, str_eq>;
|
||||
|
||||
// in DX9, all outputs had to have a semantic associated with them, that was either consumed
|
||||
// by the system or was a specific register assignment
|
||||
// in DX10+, only semantics with the SV_ prefix have any meaning beyond decoration
|
||||
// Fxc will only accept DX9 style semantics in compat mode
|
||||
// Also, in DX10 if a SV value is present as the input of a stage, but isn't appropriate for that
|
||||
// stage, it would just be ignored as it is likely there as part of an output struct from one stage
|
||||
// to the next
|
||||
bool bParseDX9 = false;
|
||||
if (bParseDX9) {
|
||||
(*SemanticMap)["PSIZE"] = EbvPointSize;
|
||||
(*SemanticMap)["FOG"] = EbvFogFragCoord;
|
||||
(*SemanticMap)["DEPTH"] = EbvFragDepth;
|
||||
(*SemanticMap)["VFACE"] = EbvFace;
|
||||
(*SemanticMap)["VPOS"] = EbvFragCoord;
|
||||
}
|
||||
|
||||
(*SemanticMap)["SV_POSITION"] = EbvPosition;
|
||||
(*SemanticMap)["SV_VERTEXID"] = EbvVertexIndex;
|
||||
(*SemanticMap)["SV_VIEWPORTARRAYINDEX"] = EbvViewportIndex;
|
||||
(*SemanticMap)["SV_TESSFACTOR"] = EbvTessLevelOuter;
|
||||
(*SemanticMap)["SV_SAMPLEINDEX"] = EbvSampleId;
|
||||
(*SemanticMap)["SV_RENDERTARGETARRAYINDEX"] = EbvLayer;
|
||||
(*SemanticMap)["SV_PRIMITIVEID"] = EbvPrimitiveId;
|
||||
(*SemanticMap)["SV_OUTPUTCONTROLPOINTID"] = EbvInvocationId;
|
||||
(*SemanticMap)["SV_ISFRONTFACE"] = EbvFace;
|
||||
(*SemanticMap)["SV_INSTANCEID"] = EbvInstanceIndex;
|
||||
(*SemanticMap)["SV_INSIDETESSFACTOR"] = EbvTessLevelInner;
|
||||
(*SemanticMap)["SV_GSINSTANCEID"] = EbvInvocationId;
|
||||
(*SemanticMap)["SV_DISPATCHTHREADID"] = EbvGlobalInvocationId;
|
||||
(*SemanticMap)["SV_GROUPTHREADID"] = EbvLocalInvocationId;
|
||||
(*SemanticMap)["SV_GROUPINDEX"] = EbvLocalInvocationIndex;
|
||||
(*SemanticMap)["SV_GROUPID"] = EbvWorkGroupId;
|
||||
(*SemanticMap)["SV_DOMAINLOCATION"] = EbvTessCoord;
|
||||
(*SemanticMap)["SV_DEPTH"] = EbvFragDepth;
|
||||
(*SemanticMap)["SV_COVERAGE"] = EbvSampleMask;
|
||||
(*SemanticMap)["SV_DEPTHGREATEREQUAL"] = EbvFragDepthGreater;
|
||||
(*SemanticMap)["SV_DEPTHLESSEQUAL"] = EbvFragDepthLesser;
|
||||
(*SemanticMap)["SV_STENCILREF"] = EbvFragStencilRef;
|
||||
}
|
||||
|
||||
void HlslScanContext::deleteKeywordMap()
|
||||
{
|
||||
delete KeywordMap;
|
||||
KeywordMap = nullptr;
|
||||
delete ReservedSet;
|
||||
ReservedSet = nullptr;
|
||||
delete SemanticMap;
|
||||
SemanticMap = nullptr;
|
||||
}
|
||||
|
||||
// Wrapper for tokenizeClass() to get everything inside the token.
|
||||
void HlslScanContext::tokenize(HlslToken& token)
|
||||
{
|
||||
EHlslTokenClass tokenClass = tokenizeClass(token);
|
||||
token.tokenClass = tokenClass;
|
||||
}
|
||||
|
||||
glslang::TBuiltInVariable HlslScanContext::mapSemantic(const char* upperCase)
|
||||
{
|
||||
auto it = SemanticMap->find(upperCase);
|
||||
if (it != SemanticMap->end())
|
||||
return it->second;
|
||||
else
|
||||
return glslang::EbvNone;
|
||||
}
|
||||
|
||||
//
|
||||
// Fill in token information for the next token, except for the token class.
|
||||
// Returns the enum value of the token class of the next token found.
|
||||
// Return 0 (EndOfTokens) on end of input.
|
||||
//
|
||||
EHlslTokenClass HlslScanContext::tokenizeClass(HlslToken& token)
|
||||
{
|
||||
do {
|
||||
parserToken = &token;
|
||||
TPpToken ppToken;
|
||||
int token = ppContext.tokenize(ppToken);
|
||||
if (token == EndOfInput)
|
||||
return EHTokNone;
|
||||
|
||||
tokenText = ppToken.name;
|
||||
loc = ppToken.loc;
|
||||
parserToken->loc = loc;
|
||||
switch (token) {
|
||||
case ';': return EHTokSemicolon;
|
||||
case ',': return EHTokComma;
|
||||
case ':': return EHTokColon;
|
||||
case '=': return EHTokAssign;
|
||||
case '(': return EHTokLeftParen;
|
||||
case ')': return EHTokRightParen;
|
||||
case '.': return EHTokDot;
|
||||
case '!': return EHTokBang;
|
||||
case '-': return EHTokDash;
|
||||
case '~': return EHTokTilde;
|
||||
case '+': return EHTokPlus;
|
||||
case '*': return EHTokStar;
|
||||
case '/': return EHTokSlash;
|
||||
case '%': return EHTokPercent;
|
||||
case '<': return EHTokLeftAngle;
|
||||
case '>': return EHTokRightAngle;
|
||||
case '|': return EHTokVerticalBar;
|
||||
case '^': return EHTokCaret;
|
||||
case '&': return EHTokAmpersand;
|
||||
case '?': return EHTokQuestion;
|
||||
case '[': return EHTokLeftBracket;
|
||||
case ']': return EHTokRightBracket;
|
||||
case '{': return EHTokLeftBrace;
|
||||
case '}': return EHTokRightBrace;
|
||||
case '\\':
|
||||
parseContext.error(loc, "illegal use of escape character", "\\", "");
|
||||
break;
|
||||
|
||||
case PPAtomAddAssign: return EHTokAddAssign;
|
||||
case PPAtomSubAssign: return EHTokSubAssign;
|
||||
case PPAtomMulAssign: return EHTokMulAssign;
|
||||
case PPAtomDivAssign: return EHTokDivAssign;
|
||||
case PPAtomModAssign: return EHTokModAssign;
|
||||
|
||||
case PpAtomRight: return EHTokRightOp;
|
||||
case PpAtomLeft: return EHTokLeftOp;
|
||||
|
||||
case PpAtomRightAssign: return EHTokRightAssign;
|
||||
case PpAtomLeftAssign: return EHTokLeftAssign;
|
||||
case PpAtomAndAssign: return EHTokAndAssign;
|
||||
case PpAtomOrAssign: return EHTokOrAssign;
|
||||
case PpAtomXorAssign: return EHTokXorAssign;
|
||||
|
||||
case PpAtomAnd: return EHTokAndOp;
|
||||
case PpAtomOr: return EHTokOrOp;
|
||||
case PpAtomXor: return EHTokXorOp;
|
||||
|
||||
case PpAtomEQ: return EHTokEqOp;
|
||||
case PpAtomGE: return EHTokGeOp;
|
||||
case PpAtomNE: return EHTokNeOp;
|
||||
case PpAtomLE: return EHTokLeOp;
|
||||
|
||||
case PpAtomDecrement: return EHTokDecOp;
|
||||
case PpAtomIncrement: return EHTokIncOp;
|
||||
|
||||
case PpAtomColonColon: return EHTokColonColon;
|
||||
|
||||
case PpAtomConstInt: parserToken->i = ppToken.ival; return EHTokIntConstant;
|
||||
case PpAtomConstUint: parserToken->i = ppToken.ival; return EHTokUintConstant;
|
||||
case PpAtomConstFloat16: parserToken->d = ppToken.dval; return EHTokFloat16Constant;
|
||||
case PpAtomConstFloat: parserToken->d = ppToken.dval; return EHTokFloatConstant;
|
||||
case PpAtomConstDouble: parserToken->d = ppToken.dval; return EHTokDoubleConstant;
|
||||
case PpAtomIdentifier:
|
||||
{
|
||||
EHlslTokenClass token = tokenizeIdentifier();
|
||||
return token;
|
||||
}
|
||||
|
||||
case PpAtomConstString: {
|
||||
parserToken->string = NewPoolTString(tokenText);
|
||||
return EHTokStringConstant;
|
||||
}
|
||||
|
||||
case EndOfInput: return EHTokNone;
|
||||
|
||||
default:
|
||||
if (token < PpAtomMaxSingle) {
|
||||
char buf[2];
|
||||
buf[0] = (char)token;
|
||||
buf[1] = 0;
|
||||
parseContext.error(loc, "unexpected token", buf, "");
|
||||
} else if (tokenText[0] != 0)
|
||||
parseContext.error(loc, "unexpected token", tokenText, "");
|
||||
else
|
||||
parseContext.error(loc, "unexpected token", "", "");
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
EHlslTokenClass HlslScanContext::tokenizeIdentifier()
|
||||
{
|
||||
if (ReservedSet->find(tokenText) != ReservedSet->end())
|
||||
return reservedWord();
|
||||
|
||||
auto it = KeywordMap->find(tokenText);
|
||||
if (it == KeywordMap->end()) {
|
||||
// Should have an identifier of some sort
|
||||
return identifierOrType();
|
||||
}
|
||||
keyword = it->second;
|
||||
|
||||
switch (keyword) {
|
||||
|
||||
// qualifiers
|
||||
case EHTokStatic:
|
||||
case EHTokConst:
|
||||
case EHTokSNorm:
|
||||
case EHTokUnorm:
|
||||
case EHTokExtern:
|
||||
case EHTokUniform:
|
||||
case EHTokVolatile:
|
||||
case EHTokShared:
|
||||
case EHTokGroupShared:
|
||||
case EHTokLinear:
|
||||
case EHTokCentroid:
|
||||
case EHTokNointerpolation:
|
||||
case EHTokNoperspective:
|
||||
case EHTokSample:
|
||||
case EHTokRowMajor:
|
||||
case EHTokColumnMajor:
|
||||
case EHTokPackOffset:
|
||||
case EHTokIn:
|
||||
case EHTokOut:
|
||||
case EHTokInOut:
|
||||
case EHTokPrecise:
|
||||
case EHTokLayout:
|
||||
case EHTokGloballyCoherent:
|
||||
case EHTokInline:
|
||||
return keyword;
|
||||
|
||||
// primitive types
|
||||
case EHTokPoint:
|
||||
case EHTokLine:
|
||||
case EHTokTriangle:
|
||||
case EHTokLineAdj:
|
||||
case EHTokTriangleAdj:
|
||||
return keyword;
|
||||
|
||||
// stream out types
|
||||
case EHTokPointStream:
|
||||
case EHTokLineStream:
|
||||
case EHTokTriangleStream:
|
||||
return keyword;
|
||||
|
||||
// Tessellation patches
|
||||
case EHTokInputPatch:
|
||||
case EHTokOutputPatch:
|
||||
return keyword;
|
||||
|
||||
case EHTokBuffer:
|
||||
case EHTokVector:
|
||||
case EHTokMatrix:
|
||||
return keyword;
|
||||
|
||||
// scalar types
|
||||
case EHTokVoid:
|
||||
case EHTokString:
|
||||
case EHTokBool:
|
||||
case EHTokInt:
|
||||
case EHTokUint:
|
||||
case EHTokUint64:
|
||||
case EHTokDword:
|
||||
case EHTokHalf:
|
||||
case EHTokFloat:
|
||||
case EHTokDouble:
|
||||
case EHTokMin16float:
|
||||
case EHTokMin10float:
|
||||
case EHTokMin16int:
|
||||
case EHTokMin12int:
|
||||
case EHTokMin16uint:
|
||||
|
||||
// vector types
|
||||
case EHTokBool1:
|
||||
case EHTokBool2:
|
||||
case EHTokBool3:
|
||||
case EHTokBool4:
|
||||
case EHTokFloat1:
|
||||
case EHTokFloat2:
|
||||
case EHTokFloat3:
|
||||
case EHTokFloat4:
|
||||
case EHTokInt1:
|
||||
case EHTokInt2:
|
||||
case EHTokInt3:
|
||||
case EHTokInt4:
|
||||
case EHTokDouble1:
|
||||
case EHTokDouble2:
|
||||
case EHTokDouble3:
|
||||
case EHTokDouble4:
|
||||
case EHTokUint1:
|
||||
case EHTokUint2:
|
||||
case EHTokUint3:
|
||||
case EHTokUint4:
|
||||
case EHTokHalf1:
|
||||
case EHTokHalf2:
|
||||
case EHTokHalf3:
|
||||
case EHTokHalf4:
|
||||
case EHTokMin16float1:
|
||||
case EHTokMin16float2:
|
||||
case EHTokMin16float3:
|
||||
case EHTokMin16float4:
|
||||
case EHTokMin10float1:
|
||||
case EHTokMin10float2:
|
||||
case EHTokMin10float3:
|
||||
case EHTokMin10float4:
|
||||
case EHTokMin16int1:
|
||||
case EHTokMin16int2:
|
||||
case EHTokMin16int3:
|
||||
case EHTokMin16int4:
|
||||
case EHTokMin12int1:
|
||||
case EHTokMin12int2:
|
||||
case EHTokMin12int3:
|
||||
case EHTokMin12int4:
|
||||
case EHTokMin16uint1:
|
||||
case EHTokMin16uint2:
|
||||
case EHTokMin16uint3:
|
||||
case EHTokMin16uint4:
|
||||
|
||||
// matrix types
|
||||
case EHTokBool1x1:
|
||||
case EHTokBool1x2:
|
||||
case EHTokBool1x3:
|
||||
case EHTokBool1x4:
|
||||
case EHTokBool2x1:
|
||||
case EHTokBool2x2:
|
||||
case EHTokBool2x3:
|
||||
case EHTokBool2x4:
|
||||
case EHTokBool3x1:
|
||||
case EHTokBool3x2:
|
||||
case EHTokBool3x3:
|
||||
case EHTokBool3x4:
|
||||
case EHTokBool4x1:
|
||||
case EHTokBool4x2:
|
||||
case EHTokBool4x3:
|
||||
case EHTokBool4x4:
|
||||
case EHTokInt1x1:
|
||||
case EHTokInt1x2:
|
||||
case EHTokInt1x3:
|
||||
case EHTokInt1x4:
|
||||
case EHTokInt2x1:
|
||||
case EHTokInt2x2:
|
||||
case EHTokInt2x3:
|
||||
case EHTokInt2x4:
|
||||
case EHTokInt3x1:
|
||||
case EHTokInt3x2:
|
||||
case EHTokInt3x3:
|
||||
case EHTokInt3x4:
|
||||
case EHTokInt4x1:
|
||||
case EHTokInt4x2:
|
||||
case EHTokInt4x3:
|
||||
case EHTokInt4x4:
|
||||
case EHTokUint1x1:
|
||||
case EHTokUint1x2:
|
||||
case EHTokUint1x3:
|
||||
case EHTokUint1x4:
|
||||
case EHTokUint2x1:
|
||||
case EHTokUint2x2:
|
||||
case EHTokUint2x3:
|
||||
case EHTokUint2x4:
|
||||
case EHTokUint3x1:
|
||||
case EHTokUint3x2:
|
||||
case EHTokUint3x3:
|
||||
case EHTokUint3x4:
|
||||
case EHTokUint4x1:
|
||||
case EHTokUint4x2:
|
||||
case EHTokUint4x3:
|
||||
case EHTokUint4x4:
|
||||
case EHTokFloat1x1:
|
||||
case EHTokFloat1x2:
|
||||
case EHTokFloat1x3:
|
||||
case EHTokFloat1x4:
|
||||
case EHTokFloat2x1:
|
||||
case EHTokFloat2x2:
|
||||
case EHTokFloat2x3:
|
||||
case EHTokFloat2x4:
|
||||
case EHTokFloat3x1:
|
||||
case EHTokFloat3x2:
|
||||
case EHTokFloat3x3:
|
||||
case EHTokFloat3x4:
|
||||
case EHTokFloat4x1:
|
||||
case EHTokFloat4x2:
|
||||
case EHTokFloat4x3:
|
||||
case EHTokFloat4x4:
|
||||
case EHTokHalf1x1:
|
||||
case EHTokHalf1x2:
|
||||
case EHTokHalf1x3:
|
||||
case EHTokHalf1x4:
|
||||
case EHTokHalf2x1:
|
||||
case EHTokHalf2x2:
|
||||
case EHTokHalf2x3:
|
||||
case EHTokHalf2x4:
|
||||
case EHTokHalf3x1:
|
||||
case EHTokHalf3x2:
|
||||
case EHTokHalf3x3:
|
||||
case EHTokHalf3x4:
|
||||
case EHTokHalf4x1:
|
||||
case EHTokHalf4x2:
|
||||
case EHTokHalf4x3:
|
||||
case EHTokHalf4x4:
|
||||
case EHTokDouble1x1:
|
||||
case EHTokDouble1x2:
|
||||
case EHTokDouble1x3:
|
||||
case EHTokDouble1x4:
|
||||
case EHTokDouble2x1:
|
||||
case EHTokDouble2x2:
|
||||
case EHTokDouble2x3:
|
||||
case EHTokDouble2x4:
|
||||
case EHTokDouble3x1:
|
||||
case EHTokDouble3x2:
|
||||
case EHTokDouble3x3:
|
||||
case EHTokDouble3x4:
|
||||
case EHTokDouble4x1:
|
||||
case EHTokDouble4x2:
|
||||
case EHTokDouble4x3:
|
||||
case EHTokDouble4x4:
|
||||
return keyword;
|
||||
|
||||
// texturing types
|
||||
case EHTokSampler:
|
||||
case EHTokSampler1d:
|
||||
case EHTokSampler2d:
|
||||
case EHTokSampler3d:
|
||||
case EHTokSamplerCube:
|
||||
case EHTokSamplerState:
|
||||
case EHTokSamplerComparisonState:
|
||||
case EHTokTexture:
|
||||
case EHTokTexture1d:
|
||||
case EHTokTexture1darray:
|
||||
case EHTokTexture2d:
|
||||
case EHTokTexture2darray:
|
||||
case EHTokTexture3d:
|
||||
case EHTokTextureCube:
|
||||
case EHTokTextureCubearray:
|
||||
case EHTokTexture2DMS:
|
||||
case EHTokTexture2DMSarray:
|
||||
case EHTokRWTexture1d:
|
||||
case EHTokRWTexture1darray:
|
||||
case EHTokRWTexture2d:
|
||||
case EHTokRWTexture2darray:
|
||||
case EHTokRWTexture3d:
|
||||
case EHTokRWBuffer:
|
||||
case EHTokAppendStructuredBuffer:
|
||||
case EHTokByteAddressBuffer:
|
||||
case EHTokConsumeStructuredBuffer:
|
||||
case EHTokRWByteAddressBuffer:
|
||||
case EHTokRWStructuredBuffer:
|
||||
case EHTokStructuredBuffer:
|
||||
case EHTokTextureBuffer:
|
||||
case EHTokSubpassInput:
|
||||
case EHTokSubpassInputMS:
|
||||
return keyword;
|
||||
|
||||
// variable, user type, ...
|
||||
case EHTokClass:
|
||||
case EHTokStruct:
|
||||
case EHTokTypedef:
|
||||
case EHTokCBuffer:
|
||||
case EHTokConstantBuffer:
|
||||
case EHTokTBuffer:
|
||||
case EHTokThis:
|
||||
case EHTokNamespace:
|
||||
return keyword;
|
||||
|
||||
case EHTokBoolConstant:
|
||||
if (strcmp("true", tokenText) == 0)
|
||||
parserToken->b = true;
|
||||
else
|
||||
parserToken->b = false;
|
||||
return keyword;
|
||||
|
||||
// control flow
|
||||
case EHTokFor:
|
||||
case EHTokDo:
|
||||
case EHTokWhile:
|
||||
case EHTokBreak:
|
||||
case EHTokContinue:
|
||||
case EHTokIf:
|
||||
case EHTokElse:
|
||||
case EHTokDiscard:
|
||||
case EHTokReturn:
|
||||
case EHTokCase:
|
||||
case EHTokSwitch:
|
||||
case EHTokDefault:
|
||||
return keyword;
|
||||
|
||||
default:
|
||||
parseContext.infoSink.info.message(EPrefixInternalError, "Unknown glslang keyword", loc);
|
||||
return EHTokNone;
|
||||
}
|
||||
}
|
||||
|
||||
EHlslTokenClass HlslScanContext::identifierOrType()
|
||||
{
|
||||
parserToken->string = NewPoolTString(tokenText);
|
||||
|
||||
return EHTokIdentifier;
|
||||
}
|
||||
|
||||
// Give an error for use of a reserved symbol.
|
||||
// However, allow built-in declarations to use reserved words, to allow
|
||||
// extension support before the extension is enabled.
|
||||
EHlslTokenClass HlslScanContext::reservedWord()
|
||||
{
|
||||
if (! parseContext.symbolTable.atBuiltInLevel())
|
||||
parseContext.error(loc, "Reserved word.", tokenText, "", "");
|
||||
|
||||
return EHTokNone;
|
||||
}
|
||||
|
||||
} // end namespace glslang
|
||||
@ -0,0 +1,109 @@
|
||||
//
|
||||
// Copyright (C) 2016 Google, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of Google, Inc., nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
//
|
||||
// This holds context specific to the HLSL scanner, which
|
||||
// sits between the preprocessor scanner and HLSL parser.
|
||||
//
|
||||
|
||||
#ifndef HLSLSCANCONTEXT_H_
|
||||
#define HLSLSCANCONTEXT_H_
|
||||
|
||||
#include "../MachineIndependent/ParseHelper.h"
|
||||
#include "hlslTokens.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
class TPpContext;
|
||||
class TPpToken;
|
||||
|
||||
|
||||
//
|
||||
// Everything needed to fully describe a token.
|
||||
//
|
||||
struct HlslToken {
|
||||
HlslToken() : string(nullptr) { loc.init(); }
|
||||
TSourceLoc loc; // location of token in the source
|
||||
EHlslTokenClass tokenClass; // what kind of token it is
|
||||
union { // what data the token holds
|
||||
glslang::TString *string; // for identifiers
|
||||
int i; // for literals
|
||||
unsigned int u;
|
||||
bool b;
|
||||
double d;
|
||||
};
|
||||
};
|
||||
|
||||
//
|
||||
// The state of scanning and translating raw tokens to slightly richer
|
||||
// semantics, like knowing if an identifier is an existing symbol, or
|
||||
// user-defined type.
|
||||
//
|
||||
class HlslScanContext {
|
||||
public:
|
||||
HlslScanContext(TParseContextBase& parseContext, TPpContext& ppContext)
|
||||
: parseContext(parseContext), ppContext(ppContext) { }
|
||||
virtual ~HlslScanContext() { }
|
||||
|
||||
static void fillInKeywordMap();
|
||||
static void deleteKeywordMap();
|
||||
|
||||
void tokenize(HlslToken&);
|
||||
glslang::TBuiltInVariable mapSemantic(const char*);
|
||||
|
||||
protected:
|
||||
HlslScanContext(HlslScanContext&);
|
||||
HlslScanContext& operator=(HlslScanContext&);
|
||||
|
||||
EHlslTokenClass tokenizeClass(HlslToken&);
|
||||
EHlslTokenClass tokenizeIdentifier();
|
||||
EHlslTokenClass identifierOrType();
|
||||
EHlslTokenClass reservedWord();
|
||||
EHlslTokenClass identifierOrReserved(bool reserved);
|
||||
EHlslTokenClass nonreservedKeyword(int version);
|
||||
|
||||
TParseContextBase& parseContext;
|
||||
TPpContext& ppContext;
|
||||
TSourceLoc loc;
|
||||
TPpToken* ppToken;
|
||||
HlslToken* parserToken;
|
||||
|
||||
const char* tokenText;
|
||||
EHlslTokenClass keyword;
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // HLSLSCANCONTEXT_H_
|
||||
@ -0,0 +1,150 @@
|
||||
//
|
||||
// Copyright (C) 2016 Google, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of Google, Inc., nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#include "hlslTokenStream.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
void HlslTokenStream::pushPreToken(const HlslToken& tok)
|
||||
{
|
||||
assert(preTokenStackSize < tokenBufferSize);
|
||||
preTokenStack[preTokenStackSize++] = tok;
|
||||
}
|
||||
|
||||
HlslToken HlslTokenStream::popPreToken()
|
||||
{
|
||||
assert(preTokenStackSize > 0);
|
||||
|
||||
return preTokenStack[--preTokenStackSize];
|
||||
}
|
||||
|
||||
void HlslTokenStream::pushTokenBuffer(const HlslToken& tok)
|
||||
{
|
||||
tokenBuffer[tokenBufferPos] = tok;
|
||||
tokenBufferPos = (tokenBufferPos+1) % tokenBufferSize;
|
||||
}
|
||||
|
||||
HlslToken HlslTokenStream::popTokenBuffer()
|
||||
{
|
||||
// Back up
|
||||
tokenBufferPos = (tokenBufferPos+tokenBufferSize-1) % tokenBufferSize;
|
||||
|
||||
return tokenBuffer[tokenBufferPos];
|
||||
}
|
||||
|
||||
//
|
||||
// Make a new source of tokens, not from the source, but from an
|
||||
// already pre-processed token stream.
|
||||
//
|
||||
// This interrupts current token processing which must be restored
|
||||
// later. Some simplifying assumptions are made (and asserted).
|
||||
//
|
||||
void HlslTokenStream::pushTokenStream(const TVector<HlslToken>* tokens)
|
||||
{
|
||||
// not yet setup to interrupt a stream that has been receded
|
||||
// and not yet reconsumed
|
||||
assert(preTokenStackSize == 0);
|
||||
|
||||
// save current state
|
||||
currentTokenStack.push_back(token);
|
||||
|
||||
// set up new token stream
|
||||
tokenStreamStack.push_back(tokens);
|
||||
|
||||
// start position at first token:
|
||||
token = (*tokens)[0];
|
||||
tokenPosition.push_back(0);
|
||||
}
|
||||
|
||||
// Undo pushTokenStream(), see above
|
||||
void HlslTokenStream::popTokenStream()
|
||||
{
|
||||
tokenStreamStack.pop_back();
|
||||
tokenPosition.pop_back();
|
||||
token = currentTokenStack.back();
|
||||
currentTokenStack.pop_back();
|
||||
}
|
||||
|
||||
// Load 'token' with the next token in the stream of tokens.
|
||||
void HlslTokenStream::advanceToken()
|
||||
{
|
||||
pushTokenBuffer(token);
|
||||
if (preTokenStackSize > 0)
|
||||
token = popPreToken();
|
||||
else {
|
||||
if (tokenStreamStack.size() == 0)
|
||||
scanner.tokenize(token);
|
||||
else {
|
||||
++tokenPosition.back();
|
||||
if (tokenPosition.back() >= (int)tokenStreamStack.back()->size())
|
||||
token.tokenClass = EHTokNone;
|
||||
else
|
||||
token = (*tokenStreamStack.back())[tokenPosition.back()];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HlslTokenStream::recedeToken()
|
||||
{
|
||||
pushPreToken(token);
|
||||
token = popTokenBuffer();
|
||||
}
|
||||
|
||||
// Return the current token class.
|
||||
EHlslTokenClass HlslTokenStream::peek() const
|
||||
{
|
||||
return token.tokenClass;
|
||||
}
|
||||
|
||||
// Return true, without advancing to the next token, if the current token is
|
||||
// the expected (passed in) token class.
|
||||
bool HlslTokenStream::peekTokenClass(EHlslTokenClass tokenClass) const
|
||||
{
|
||||
return peek() == tokenClass;
|
||||
}
|
||||
|
||||
// Return true and advance to the next token if the current token is the
|
||||
// expected (passed in) token class.
|
||||
bool HlslTokenStream::acceptTokenClass(EHlslTokenClass tokenClass)
|
||||
{
|
||||
if (peekTokenClass(tokenClass)) {
|
||||
advanceToken();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // end namespace glslang
|
||||
@ -0,0 +1,96 @@
|
||||
//
|
||||
// Copyright (C) 2016 Google, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of Google, Inc., nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef HLSLTOKENSTREAM_H_
|
||||
#define HLSLTOKENSTREAM_H_
|
||||
|
||||
#include "hlslScanContext.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
class HlslTokenStream {
|
||||
public:
|
||||
explicit HlslTokenStream(HlslScanContext& scanner)
|
||||
: scanner(scanner), preTokenStackSize(0), tokenBufferPos(0) { }
|
||||
virtual ~HlslTokenStream() { }
|
||||
|
||||
public:
|
||||
void advanceToken();
|
||||
void recedeToken();
|
||||
bool acceptTokenClass(EHlslTokenClass);
|
||||
EHlslTokenClass peek() const;
|
||||
bool peekTokenClass(EHlslTokenClass) const;
|
||||
glslang::TBuiltInVariable mapSemantic(const char* upperCase) { return scanner.mapSemantic(upperCase); }
|
||||
|
||||
void pushTokenStream(const TVector<HlslToken>* tokens);
|
||||
void popTokenStream();
|
||||
|
||||
protected:
|
||||
HlslToken token; // the token we are currently looking at, but have not yet accepted
|
||||
|
||||
private:
|
||||
HlslTokenStream();
|
||||
HlslTokenStream& operator=(const HlslTokenStream&);
|
||||
|
||||
HlslScanContext& scanner; // lexical scanner, to get next token from source file
|
||||
TVector<const TVector<HlslToken>*> tokenStreamStack; // for getting the next token from an existing vector of tokens
|
||||
TVector<int> tokenPosition;
|
||||
TVector<HlslToken> currentTokenStack;
|
||||
|
||||
// This is the number of tokens we can recedeToken() over.
|
||||
static const int tokenBufferSize = 2;
|
||||
|
||||
// Previously scanned tokens, returned for future advances,
|
||||
// so logically in front of the token stream.
|
||||
// Is logically a stack; needs last in last out semantics.
|
||||
// Currently implemented as a stack of size 2.
|
||||
HlslToken preTokenStack[tokenBufferSize];
|
||||
int preTokenStackSize;
|
||||
void pushPreToken(const HlslToken&);
|
||||
HlslToken popPreToken();
|
||||
|
||||
// Previously scanned tokens, not yet returned for future advances,
|
||||
// but available for that.
|
||||
// Is logically a fifo for normal advances, and a stack for recession.
|
||||
// Currently implemented with an intrinsic size of 2.
|
||||
HlslToken tokenBuffer[tokenBufferSize];
|
||||
int tokenBufferPos;
|
||||
void pushTokenBuffer(const HlslToken&);
|
||||
HlslToken popTokenBuffer();
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // HLSLTOKENSTREAM_H_
|
||||
374
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/HLSL/hlslTokens.h
vendored
Normal file
374
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/HLSL/hlslTokens.h
vendored
Normal file
@ -0,0 +1,374 @@
|
||||
//
|
||||
// Copyright (C) 2016 Google, Inc.
|
||||
// Copyright (C) 2016 LunarG, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of Google, Inc., nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef EHLSLTOKENS_H_
|
||||
#define EHLSLTOKENS_H_
|
||||
|
||||
namespace glslang {
|
||||
|
||||
enum EHlslTokenClass {
|
||||
EHTokNone = 0,
|
||||
|
||||
// qualifiers
|
||||
EHTokStatic,
|
||||
EHTokConst,
|
||||
EHTokSNorm,
|
||||
EHTokUnorm,
|
||||
EHTokExtern,
|
||||
EHTokUniform,
|
||||
EHTokVolatile,
|
||||
EHTokPrecise,
|
||||
EHTokShared,
|
||||
EHTokGroupShared,
|
||||
EHTokLinear,
|
||||
EHTokCentroid,
|
||||
EHTokNointerpolation,
|
||||
EHTokNoperspective,
|
||||
EHTokSample,
|
||||
EHTokRowMajor,
|
||||
EHTokColumnMajor,
|
||||
EHTokPackOffset,
|
||||
EHTokIn,
|
||||
EHTokOut,
|
||||
EHTokInOut,
|
||||
EHTokLayout,
|
||||
EHTokGloballyCoherent,
|
||||
EHTokInline,
|
||||
|
||||
// primitive types
|
||||
EHTokPoint,
|
||||
EHTokLine,
|
||||
EHTokTriangle,
|
||||
EHTokLineAdj,
|
||||
EHTokTriangleAdj,
|
||||
|
||||
// stream out types
|
||||
EHTokPointStream,
|
||||
EHTokLineStream,
|
||||
EHTokTriangleStream,
|
||||
|
||||
// Tessellation patches
|
||||
EHTokInputPatch,
|
||||
EHTokOutputPatch,
|
||||
|
||||
// template types
|
||||
EHTokBuffer,
|
||||
EHTokVector,
|
||||
EHTokMatrix,
|
||||
|
||||
// scalar types
|
||||
EHTokVoid,
|
||||
EHTokString,
|
||||
EHTokBool,
|
||||
EHTokInt,
|
||||
EHTokUint,
|
||||
EHTokUint64,
|
||||
EHTokDword,
|
||||
EHTokHalf,
|
||||
EHTokFloat,
|
||||
EHTokDouble,
|
||||
EHTokMin16float,
|
||||
EHTokMin10float,
|
||||
EHTokMin16int,
|
||||
EHTokMin12int,
|
||||
EHTokMin16uint,
|
||||
|
||||
// vector types
|
||||
EHTokBool1,
|
||||
EHTokBool2,
|
||||
EHTokBool3,
|
||||
EHTokBool4,
|
||||
EHTokFloat1,
|
||||
EHTokFloat2,
|
||||
EHTokFloat3,
|
||||
EHTokFloat4,
|
||||
EHTokInt1,
|
||||
EHTokInt2,
|
||||
EHTokInt3,
|
||||
EHTokInt4,
|
||||
EHTokDouble1,
|
||||
EHTokDouble2,
|
||||
EHTokDouble3,
|
||||
EHTokDouble4,
|
||||
EHTokUint1,
|
||||
EHTokUint2,
|
||||
EHTokUint3,
|
||||
EHTokUint4,
|
||||
EHTokHalf1,
|
||||
EHTokHalf2,
|
||||
EHTokHalf3,
|
||||
EHTokHalf4,
|
||||
EHTokMin16float1,
|
||||
EHTokMin16float2,
|
||||
EHTokMin16float3,
|
||||
EHTokMin16float4,
|
||||
EHTokMin10float1,
|
||||
EHTokMin10float2,
|
||||
EHTokMin10float3,
|
||||
EHTokMin10float4,
|
||||
EHTokMin16int1,
|
||||
EHTokMin16int2,
|
||||
EHTokMin16int3,
|
||||
EHTokMin16int4,
|
||||
EHTokMin12int1,
|
||||
EHTokMin12int2,
|
||||
EHTokMin12int3,
|
||||
EHTokMin12int4,
|
||||
EHTokMin16uint1,
|
||||
EHTokMin16uint2,
|
||||
EHTokMin16uint3,
|
||||
EHTokMin16uint4,
|
||||
|
||||
// matrix types
|
||||
EHTokInt1x1,
|
||||
EHTokInt1x2,
|
||||
EHTokInt1x3,
|
||||
EHTokInt1x4,
|
||||
EHTokInt2x1,
|
||||
EHTokInt2x2,
|
||||
EHTokInt2x3,
|
||||
EHTokInt2x4,
|
||||
EHTokInt3x1,
|
||||
EHTokInt3x2,
|
||||
EHTokInt3x3,
|
||||
EHTokInt3x4,
|
||||
EHTokInt4x1,
|
||||
EHTokInt4x2,
|
||||
EHTokInt4x3,
|
||||
EHTokInt4x4,
|
||||
EHTokUint1x1,
|
||||
EHTokUint1x2,
|
||||
EHTokUint1x3,
|
||||
EHTokUint1x4,
|
||||
EHTokUint2x1,
|
||||
EHTokUint2x2,
|
||||
EHTokUint2x3,
|
||||
EHTokUint2x4,
|
||||
EHTokUint3x1,
|
||||
EHTokUint3x2,
|
||||
EHTokUint3x3,
|
||||
EHTokUint3x4,
|
||||
EHTokUint4x1,
|
||||
EHTokUint4x2,
|
||||
EHTokUint4x3,
|
||||
EHTokUint4x4,
|
||||
EHTokBool1x1,
|
||||
EHTokBool1x2,
|
||||
EHTokBool1x3,
|
||||
EHTokBool1x4,
|
||||
EHTokBool2x1,
|
||||
EHTokBool2x2,
|
||||
EHTokBool2x3,
|
||||
EHTokBool2x4,
|
||||
EHTokBool3x1,
|
||||
EHTokBool3x2,
|
||||
EHTokBool3x3,
|
||||
EHTokBool3x4,
|
||||
EHTokBool4x1,
|
||||
EHTokBool4x2,
|
||||
EHTokBool4x3,
|
||||
EHTokBool4x4,
|
||||
EHTokFloat1x1,
|
||||
EHTokFloat1x2,
|
||||
EHTokFloat1x3,
|
||||
EHTokFloat1x4,
|
||||
EHTokFloat2x1,
|
||||
EHTokFloat2x2,
|
||||
EHTokFloat2x3,
|
||||
EHTokFloat2x4,
|
||||
EHTokFloat3x1,
|
||||
EHTokFloat3x2,
|
||||
EHTokFloat3x3,
|
||||
EHTokFloat3x4,
|
||||
EHTokFloat4x1,
|
||||
EHTokFloat4x2,
|
||||
EHTokFloat4x3,
|
||||
EHTokFloat4x4,
|
||||
EHTokHalf1x1,
|
||||
EHTokHalf1x2,
|
||||
EHTokHalf1x3,
|
||||
EHTokHalf1x4,
|
||||
EHTokHalf2x1,
|
||||
EHTokHalf2x2,
|
||||
EHTokHalf2x3,
|
||||
EHTokHalf2x4,
|
||||
EHTokHalf3x1,
|
||||
EHTokHalf3x2,
|
||||
EHTokHalf3x3,
|
||||
EHTokHalf3x4,
|
||||
EHTokHalf4x1,
|
||||
EHTokHalf4x2,
|
||||
EHTokHalf4x3,
|
||||
EHTokHalf4x4,
|
||||
EHTokDouble1x1,
|
||||
EHTokDouble1x2,
|
||||
EHTokDouble1x3,
|
||||
EHTokDouble1x4,
|
||||
EHTokDouble2x1,
|
||||
EHTokDouble2x2,
|
||||
EHTokDouble2x3,
|
||||
EHTokDouble2x4,
|
||||
EHTokDouble3x1,
|
||||
EHTokDouble3x2,
|
||||
EHTokDouble3x3,
|
||||
EHTokDouble3x4,
|
||||
EHTokDouble4x1,
|
||||
EHTokDouble4x2,
|
||||
EHTokDouble4x3,
|
||||
EHTokDouble4x4,
|
||||
|
||||
// texturing types
|
||||
EHTokSampler,
|
||||
EHTokSampler1d,
|
||||
EHTokSampler2d,
|
||||
EHTokSampler3d,
|
||||
EHTokSamplerCube,
|
||||
EHTokSamplerState,
|
||||
EHTokSamplerComparisonState,
|
||||
EHTokTexture,
|
||||
EHTokTexture1d,
|
||||
EHTokTexture1darray,
|
||||
EHTokTexture2d,
|
||||
EHTokTexture2darray,
|
||||
EHTokTexture3d,
|
||||
EHTokTextureCube,
|
||||
EHTokTextureCubearray,
|
||||
EHTokTexture2DMS,
|
||||
EHTokTexture2DMSarray,
|
||||
EHTokRWTexture1d,
|
||||
EHTokRWTexture1darray,
|
||||
EHTokRWTexture2d,
|
||||
EHTokRWTexture2darray,
|
||||
EHTokRWTexture3d,
|
||||
EHTokRWBuffer,
|
||||
EHTokSubpassInput,
|
||||
EHTokSubpassInputMS,
|
||||
|
||||
// Structure buffer variants
|
||||
EHTokAppendStructuredBuffer,
|
||||
EHTokByteAddressBuffer,
|
||||
EHTokConsumeStructuredBuffer,
|
||||
EHTokRWByteAddressBuffer,
|
||||
EHTokRWStructuredBuffer,
|
||||
EHTokStructuredBuffer,
|
||||
EHTokTextureBuffer,
|
||||
|
||||
// variable, user type, ...
|
||||
EHTokIdentifier,
|
||||
EHTokClass,
|
||||
EHTokStruct,
|
||||
EHTokCBuffer,
|
||||
EHTokTBuffer,
|
||||
EHTokTypedef,
|
||||
EHTokThis,
|
||||
EHTokNamespace,
|
||||
EHTokConstantBuffer,
|
||||
|
||||
// constant
|
||||
EHTokFloat16Constant,
|
||||
EHTokFloatConstant,
|
||||
EHTokDoubleConstant,
|
||||
EHTokIntConstant,
|
||||
EHTokUintConstant,
|
||||
EHTokBoolConstant,
|
||||
EHTokStringConstant,
|
||||
|
||||
// control flow
|
||||
EHTokFor,
|
||||
EHTokDo,
|
||||
EHTokWhile,
|
||||
EHTokBreak,
|
||||
EHTokContinue,
|
||||
EHTokIf,
|
||||
EHTokElse,
|
||||
EHTokDiscard,
|
||||
EHTokReturn,
|
||||
EHTokSwitch,
|
||||
EHTokCase,
|
||||
EHTokDefault,
|
||||
|
||||
// expressions
|
||||
EHTokLeftOp,
|
||||
EHTokRightOp,
|
||||
EHTokIncOp,
|
||||
EHTokDecOp,
|
||||
EHTokLeOp,
|
||||
EHTokGeOp,
|
||||
EHTokEqOp,
|
||||
EHTokNeOp,
|
||||
EHTokAndOp,
|
||||
EHTokOrOp,
|
||||
EHTokXorOp,
|
||||
EHTokAssign,
|
||||
EHTokMulAssign,
|
||||
EHTokDivAssign,
|
||||
EHTokAddAssign,
|
||||
EHTokModAssign,
|
||||
EHTokLeftAssign,
|
||||
EHTokRightAssign,
|
||||
EHTokAndAssign,
|
||||
EHTokXorAssign,
|
||||
EHTokOrAssign,
|
||||
EHTokSubAssign,
|
||||
EHTokLeftParen,
|
||||
EHTokRightParen,
|
||||
EHTokLeftBracket,
|
||||
EHTokRightBracket,
|
||||
EHTokLeftBrace,
|
||||
EHTokRightBrace,
|
||||
EHTokDot,
|
||||
EHTokComma,
|
||||
EHTokColon,
|
||||
EHTokColonColon,
|
||||
EHTokSemicolon,
|
||||
EHTokBang,
|
||||
EHTokDash,
|
||||
EHTokTilde,
|
||||
EHTokPlus,
|
||||
EHTokStar,
|
||||
EHTokSlash,
|
||||
EHTokPercent,
|
||||
EHTokLeftAngle,
|
||||
EHTokRightAngle,
|
||||
EHTokVerticalBar,
|
||||
EHTokCaret,
|
||||
EHTokAmpersand,
|
||||
EHTokQuestion,
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // EHLSLTOKENS_H_
|
||||
53
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/HLSL/pch.h
vendored
Normal file
53
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/HLSL/pch.h
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
#ifndef _PCH_H
|
||||
#define _PCH_H
|
||||
//
|
||||
// Copyright (C) 2018 The Khronos Group Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#include "hlslAttributes.h"
|
||||
#include "hlslGrammar.h"
|
||||
#include "hlslParseHelper.h"
|
||||
#include "hlslScanContext.h"
|
||||
|
||||
#include "../MachineIndependent/Scan.h"
|
||||
#include "../MachineIndependent/preprocessor/PpContext.h"
|
||||
|
||||
#include "../OSDependent/osinclude.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cctype>
|
||||
#include <functional>
|
||||
#include <set>
|
||||
|
||||
#endif /* _PCH_H */
|
||||
609
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/Include/BaseTypes.h
vendored
Normal file
609
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/Include/BaseTypes.h
vendored
Normal file
@ -0,0 +1,609 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2012-2013 LunarG, Inc.
|
||||
// Copyright (C) 2017 ARM Limited.
|
||||
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef _BASICTYPES_INCLUDED_
|
||||
#define _BASICTYPES_INCLUDED_
|
||||
|
||||
namespace glslang {
|
||||
|
||||
//
|
||||
// Basic type. Arrays, vectors, sampler details, etc., are orthogonal to this.
|
||||
//
|
||||
enum TBasicType {
|
||||
EbtVoid,
|
||||
EbtFloat,
|
||||
EbtDouble,
|
||||
EbtFloat16,
|
||||
EbtInt8,
|
||||
EbtUint8,
|
||||
EbtInt16,
|
||||
EbtUint16,
|
||||
EbtInt,
|
||||
EbtUint,
|
||||
EbtInt64,
|
||||
EbtUint64,
|
||||
EbtBool,
|
||||
EbtAtomicUint,
|
||||
EbtSampler,
|
||||
EbtStruct,
|
||||
EbtBlock,
|
||||
EbtAccStruct,
|
||||
EbtReference,
|
||||
EbtRayQuery,
|
||||
#ifndef GLSLANG_WEB
|
||||
// SPIR-V type defined by spirv_type
|
||||
EbtSpirvType,
|
||||
#endif
|
||||
|
||||
// HLSL types that live only temporarily.
|
||||
EbtString,
|
||||
|
||||
EbtNumTypes
|
||||
};
|
||||
|
||||
//
|
||||
// Storage qualifiers. Should align with different kinds of storage or
|
||||
// resource or GLSL storage qualifier. Expansion is deprecated.
|
||||
//
|
||||
// N.B.: You probably DON'T want to add anything here, but rather just add it
|
||||
// to the built-in variables. See the comment above TBuiltInVariable.
|
||||
//
|
||||
// A new built-in variable will normally be an existing qualifier, like 'in', 'out', etc.
|
||||
// DO NOT follow the design pattern of, say EvqInstanceId, etc.
|
||||
//
|
||||
enum TStorageQualifier {
|
||||
EvqTemporary, // For temporaries (within a function), read/write
|
||||
EvqGlobal, // For globals read/write
|
||||
EvqConst, // User-defined constant values, will be semantically constant and constant folded
|
||||
EvqVaryingIn, // pipeline input, read only, also supercategory for all built-ins not included in this enum (see TBuiltInVariable)
|
||||
EvqVaryingOut, // pipeline output, read/write, also supercategory for all built-ins not included in this enum (see TBuiltInVariable)
|
||||
EvqUniform, // read only, shared with app
|
||||
EvqBuffer, // read/write, shared with app
|
||||
EvqShared, // compute shader's read/write 'shared' qualifier
|
||||
#ifndef GLSLANG_WEB
|
||||
EvqSpirvStorageClass, // spirv_storage_class
|
||||
#endif
|
||||
|
||||
EvqPayload,
|
||||
EvqPayloadIn,
|
||||
EvqHitAttr,
|
||||
EvqCallableData,
|
||||
EvqCallableDataIn,
|
||||
|
||||
EvqtaskPayloadSharedEXT,
|
||||
|
||||
// parameters
|
||||
EvqIn, // also, for 'in' in the grammar before we know if it's a pipeline input or an 'in' parameter
|
||||
EvqOut, // also, for 'out' in the grammar before we know if it's a pipeline output or an 'out' parameter
|
||||
EvqInOut,
|
||||
EvqConstReadOnly, // input; also other read-only types having neither a constant value nor constant-value semantics
|
||||
|
||||
// built-ins read by vertex shader
|
||||
EvqVertexId,
|
||||
EvqInstanceId,
|
||||
|
||||
// built-ins written by vertex shader
|
||||
EvqPosition,
|
||||
EvqPointSize,
|
||||
EvqClipVertex,
|
||||
|
||||
// built-ins read by fragment shader
|
||||
EvqFace,
|
||||
EvqFragCoord,
|
||||
EvqPointCoord,
|
||||
|
||||
// built-ins written by fragment shader
|
||||
EvqFragColor,
|
||||
EvqFragDepth,
|
||||
EvqFragStencil,
|
||||
|
||||
// end of list
|
||||
EvqLast
|
||||
};
|
||||
|
||||
//
|
||||
// Subcategories of the TStorageQualifier, simply to give a direct mapping
|
||||
// between built-in variable names and an numerical value (the enum).
|
||||
//
|
||||
// For backward compatibility, there is some redundancy between the
|
||||
// TStorageQualifier and these. Existing members should both be maintained accurately.
|
||||
// However, any new built-in variable (and any existing non-redundant one)
|
||||
// must follow the pattern that the specific built-in is here, and only its
|
||||
// general qualifier is in TStorageQualifier.
|
||||
//
|
||||
// Something like gl_Position, which is sometimes 'in' and sometimes 'out'
|
||||
// shows up as two different built-in variables in a single stage, but
|
||||
// only has a single enum in TBuiltInVariable, so both the
|
||||
// TStorageQualifier and the TBuitinVariable are needed to distinguish
|
||||
// between them.
|
||||
//
|
||||
enum TBuiltInVariable {
|
||||
EbvNone,
|
||||
EbvNumWorkGroups,
|
||||
EbvWorkGroupSize,
|
||||
EbvWorkGroupId,
|
||||
EbvLocalInvocationId,
|
||||
EbvGlobalInvocationId,
|
||||
EbvLocalInvocationIndex,
|
||||
EbvNumSubgroups,
|
||||
EbvSubgroupID,
|
||||
EbvSubGroupSize,
|
||||
EbvSubGroupInvocation,
|
||||
EbvSubGroupEqMask,
|
||||
EbvSubGroupGeMask,
|
||||
EbvSubGroupGtMask,
|
||||
EbvSubGroupLeMask,
|
||||
EbvSubGroupLtMask,
|
||||
EbvSubgroupSize2,
|
||||
EbvSubgroupInvocation2,
|
||||
EbvSubgroupEqMask2,
|
||||
EbvSubgroupGeMask2,
|
||||
EbvSubgroupGtMask2,
|
||||
EbvSubgroupLeMask2,
|
||||
EbvSubgroupLtMask2,
|
||||
EbvVertexId,
|
||||
EbvInstanceId,
|
||||
EbvVertexIndex,
|
||||
EbvInstanceIndex,
|
||||
EbvBaseVertex,
|
||||
EbvBaseInstance,
|
||||
EbvDrawId,
|
||||
EbvPosition,
|
||||
EbvPointSize,
|
||||
EbvClipVertex,
|
||||
EbvClipDistance,
|
||||
EbvCullDistance,
|
||||
EbvNormal,
|
||||
EbvVertex,
|
||||
EbvMultiTexCoord0,
|
||||
EbvMultiTexCoord1,
|
||||
EbvMultiTexCoord2,
|
||||
EbvMultiTexCoord3,
|
||||
EbvMultiTexCoord4,
|
||||
EbvMultiTexCoord5,
|
||||
EbvMultiTexCoord6,
|
||||
EbvMultiTexCoord7,
|
||||
EbvFrontColor,
|
||||
EbvBackColor,
|
||||
EbvFrontSecondaryColor,
|
||||
EbvBackSecondaryColor,
|
||||
EbvTexCoord,
|
||||
EbvFogFragCoord,
|
||||
EbvInvocationId,
|
||||
EbvPrimitiveId,
|
||||
EbvLayer,
|
||||
EbvViewportIndex,
|
||||
EbvPatchVertices,
|
||||
EbvTessLevelOuter,
|
||||
EbvTessLevelInner,
|
||||
EbvBoundingBox,
|
||||
EbvTessCoord,
|
||||
EbvColor,
|
||||
EbvSecondaryColor,
|
||||
EbvFace,
|
||||
EbvFragCoord,
|
||||
EbvPointCoord,
|
||||
EbvFragColor,
|
||||
EbvFragData,
|
||||
EbvFragDepth,
|
||||
EbvFragStencilRef,
|
||||
EbvSampleId,
|
||||
EbvSamplePosition,
|
||||
EbvSampleMask,
|
||||
EbvHelperInvocation,
|
||||
|
||||
EbvBaryCoordNoPersp,
|
||||
EbvBaryCoordNoPerspCentroid,
|
||||
EbvBaryCoordNoPerspSample,
|
||||
EbvBaryCoordSmooth,
|
||||
EbvBaryCoordSmoothCentroid,
|
||||
EbvBaryCoordSmoothSample,
|
||||
EbvBaryCoordPullModel,
|
||||
|
||||
EbvViewIndex,
|
||||
EbvDeviceIndex,
|
||||
|
||||
EbvShadingRateKHR,
|
||||
EbvPrimitiveShadingRateKHR,
|
||||
|
||||
EbvFragSizeEXT,
|
||||
EbvFragInvocationCountEXT,
|
||||
|
||||
EbvSecondaryFragDataEXT,
|
||||
EbvSecondaryFragColorEXT,
|
||||
|
||||
EbvViewportMaskNV,
|
||||
EbvSecondaryPositionNV,
|
||||
EbvSecondaryViewportMaskNV,
|
||||
EbvPositionPerViewNV,
|
||||
EbvViewportMaskPerViewNV,
|
||||
EbvFragFullyCoveredNV,
|
||||
EbvFragmentSizeNV,
|
||||
EbvInvocationsPerPixelNV,
|
||||
// ray tracing
|
||||
EbvLaunchId,
|
||||
EbvLaunchSize,
|
||||
EbvInstanceCustomIndex,
|
||||
EbvGeometryIndex,
|
||||
EbvWorldRayOrigin,
|
||||
EbvWorldRayDirection,
|
||||
EbvObjectRayOrigin,
|
||||
EbvObjectRayDirection,
|
||||
EbvRayTmin,
|
||||
EbvRayTmax,
|
||||
EbvCullMask,
|
||||
EbvHitT,
|
||||
EbvHitKind,
|
||||
EbvObjectToWorld,
|
||||
EbvObjectToWorld3x4,
|
||||
EbvWorldToObject,
|
||||
EbvWorldToObject3x4,
|
||||
EbvIncomingRayFlags,
|
||||
EbvCurrentRayTimeNV,
|
||||
// barycentrics
|
||||
EbvBaryCoordNV,
|
||||
EbvBaryCoordNoPerspNV,
|
||||
EbvBaryCoordEXT,
|
||||
EbvBaryCoordNoPerspEXT,
|
||||
// mesh shaders
|
||||
EbvTaskCountNV,
|
||||
EbvPrimitiveCountNV,
|
||||
EbvPrimitiveIndicesNV,
|
||||
EbvClipDistancePerViewNV,
|
||||
EbvCullDistancePerViewNV,
|
||||
EbvLayerPerViewNV,
|
||||
EbvMeshViewCountNV,
|
||||
EbvMeshViewIndicesNV,
|
||||
//GL_EXT_mesh_shader
|
||||
EbvPrimitivePointIndicesEXT,
|
||||
EbvPrimitiveLineIndicesEXT,
|
||||
EbvPrimitiveTriangleIndicesEXT,
|
||||
EbvCullPrimitiveEXT,
|
||||
|
||||
// sm builtins
|
||||
EbvWarpsPerSM,
|
||||
EbvSMCount,
|
||||
EbvWarpID,
|
||||
EbvSMID,
|
||||
|
||||
// HLSL built-ins that live only temporarily, until they get remapped
|
||||
// to one of the above.
|
||||
EbvFragDepthGreater,
|
||||
EbvFragDepthLesser,
|
||||
EbvGsOutputStream,
|
||||
EbvOutputPatch,
|
||||
EbvInputPatch,
|
||||
|
||||
// structbuffer types
|
||||
EbvAppendConsume, // no need to differentiate append and consume
|
||||
EbvRWStructuredBuffer,
|
||||
EbvStructuredBuffer,
|
||||
EbvByteAddressBuffer,
|
||||
EbvRWByteAddressBuffer,
|
||||
|
||||
EbvLast
|
||||
};
|
||||
|
||||
// In this enum, order matters; users can assume higher precision is a bigger value
|
||||
// and EpqNone is 0.
|
||||
enum TPrecisionQualifier {
|
||||
EpqNone = 0,
|
||||
EpqLow,
|
||||
EpqMedium,
|
||||
EpqHigh
|
||||
};
|
||||
|
||||
#ifdef GLSLANG_WEB
|
||||
__inline const char* GetStorageQualifierString(TStorageQualifier q) { return ""; }
|
||||
__inline const char* GetPrecisionQualifierString(TPrecisionQualifier p) { return ""; }
|
||||
#else
|
||||
// These will show up in error messages
|
||||
__inline const char* GetStorageQualifierString(TStorageQualifier q)
|
||||
{
|
||||
switch (q) {
|
||||
case EvqTemporary: return "temp"; break;
|
||||
case EvqGlobal: return "global"; break;
|
||||
case EvqConst: return "const"; break;
|
||||
case EvqConstReadOnly: return "const (read only)"; break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EvqSpirvStorageClass: return "spirv_storage_class"; break;
|
||||
#endif
|
||||
case EvqVaryingIn: return "in"; break;
|
||||
case EvqVaryingOut: return "out"; break;
|
||||
case EvqUniform: return "uniform"; break;
|
||||
case EvqBuffer: return "buffer"; break;
|
||||
case EvqShared: return "shared"; break;
|
||||
case EvqIn: return "in"; break;
|
||||
case EvqOut: return "out"; break;
|
||||
case EvqInOut: return "inout"; break;
|
||||
case EvqVertexId: return "gl_VertexId"; break;
|
||||
case EvqInstanceId: return "gl_InstanceId"; break;
|
||||
case EvqPosition: return "gl_Position"; break;
|
||||
case EvqPointSize: return "gl_PointSize"; break;
|
||||
case EvqClipVertex: return "gl_ClipVertex"; break;
|
||||
case EvqFace: return "gl_FrontFacing"; break;
|
||||
case EvqFragCoord: return "gl_FragCoord"; break;
|
||||
case EvqPointCoord: return "gl_PointCoord"; break;
|
||||
case EvqFragColor: return "fragColor"; break;
|
||||
case EvqFragDepth: return "gl_FragDepth"; break;
|
||||
case EvqFragStencil: return "gl_FragStencilRefARB"; break;
|
||||
case EvqPayload: return "rayPayloadNV"; break;
|
||||
case EvqPayloadIn: return "rayPayloadInNV"; break;
|
||||
case EvqHitAttr: return "hitAttributeNV"; break;
|
||||
case EvqCallableData: return "callableDataNV"; break;
|
||||
case EvqCallableDataIn: return "callableDataInNV"; break;
|
||||
case EvqtaskPayloadSharedEXT: return "taskPayloadSharedEXT"; break;
|
||||
default: return "unknown qualifier";
|
||||
}
|
||||
}
|
||||
|
||||
__inline const char* GetBuiltInVariableString(TBuiltInVariable v)
|
||||
{
|
||||
switch (v) {
|
||||
case EbvNone: return "";
|
||||
case EbvNumWorkGroups: return "NumWorkGroups";
|
||||
case EbvWorkGroupSize: return "WorkGroupSize";
|
||||
case EbvWorkGroupId: return "WorkGroupID";
|
||||
case EbvLocalInvocationId: return "LocalInvocationID";
|
||||
case EbvGlobalInvocationId: return "GlobalInvocationID";
|
||||
case EbvLocalInvocationIndex: return "LocalInvocationIndex";
|
||||
case EbvNumSubgroups: return "NumSubgroups";
|
||||
case EbvSubgroupID: return "SubgroupID";
|
||||
case EbvSubGroupSize: return "SubGroupSize";
|
||||
case EbvSubGroupInvocation: return "SubGroupInvocation";
|
||||
case EbvSubGroupEqMask: return "SubGroupEqMask";
|
||||
case EbvSubGroupGeMask: return "SubGroupGeMask";
|
||||
case EbvSubGroupGtMask: return "SubGroupGtMask";
|
||||
case EbvSubGroupLeMask: return "SubGroupLeMask";
|
||||
case EbvSubGroupLtMask: return "SubGroupLtMask";
|
||||
case EbvSubgroupSize2: return "SubgroupSize";
|
||||
case EbvSubgroupInvocation2: return "SubgroupInvocationID";
|
||||
case EbvSubgroupEqMask2: return "SubgroupEqMask";
|
||||
case EbvSubgroupGeMask2: return "SubgroupGeMask";
|
||||
case EbvSubgroupGtMask2: return "SubgroupGtMask";
|
||||
case EbvSubgroupLeMask2: return "SubgroupLeMask";
|
||||
case EbvSubgroupLtMask2: return "SubgroupLtMask";
|
||||
case EbvVertexId: return "VertexId";
|
||||
case EbvInstanceId: return "InstanceId";
|
||||
case EbvVertexIndex: return "VertexIndex";
|
||||
case EbvInstanceIndex: return "InstanceIndex";
|
||||
case EbvBaseVertex: return "BaseVertex";
|
||||
case EbvBaseInstance: return "BaseInstance";
|
||||
case EbvDrawId: return "DrawId";
|
||||
case EbvPosition: return "Position";
|
||||
case EbvPointSize: return "PointSize";
|
||||
case EbvClipVertex: return "ClipVertex";
|
||||
case EbvClipDistance: return "ClipDistance";
|
||||
case EbvCullDistance: return "CullDistance";
|
||||
case EbvNormal: return "Normal";
|
||||
case EbvVertex: return "Vertex";
|
||||
case EbvMultiTexCoord0: return "MultiTexCoord0";
|
||||
case EbvMultiTexCoord1: return "MultiTexCoord1";
|
||||
case EbvMultiTexCoord2: return "MultiTexCoord2";
|
||||
case EbvMultiTexCoord3: return "MultiTexCoord3";
|
||||
case EbvMultiTexCoord4: return "MultiTexCoord4";
|
||||
case EbvMultiTexCoord5: return "MultiTexCoord5";
|
||||
case EbvMultiTexCoord6: return "MultiTexCoord6";
|
||||
case EbvMultiTexCoord7: return "MultiTexCoord7";
|
||||
case EbvFrontColor: return "FrontColor";
|
||||
case EbvBackColor: return "BackColor";
|
||||
case EbvFrontSecondaryColor: return "FrontSecondaryColor";
|
||||
case EbvBackSecondaryColor: return "BackSecondaryColor";
|
||||
case EbvTexCoord: return "TexCoord";
|
||||
case EbvFogFragCoord: return "FogFragCoord";
|
||||
case EbvInvocationId: return "InvocationID";
|
||||
case EbvPrimitiveId: return "PrimitiveID";
|
||||
case EbvLayer: return "Layer";
|
||||
case EbvViewportIndex: return "ViewportIndex";
|
||||
case EbvPatchVertices: return "PatchVertices";
|
||||
case EbvTessLevelOuter: return "TessLevelOuter";
|
||||
case EbvTessLevelInner: return "TessLevelInner";
|
||||
case EbvBoundingBox: return "BoundingBox";
|
||||
case EbvTessCoord: return "TessCoord";
|
||||
case EbvColor: return "Color";
|
||||
case EbvSecondaryColor: return "SecondaryColor";
|
||||
case EbvFace: return "Face";
|
||||
case EbvFragCoord: return "FragCoord";
|
||||
case EbvPointCoord: return "PointCoord";
|
||||
case EbvFragColor: return "FragColor";
|
||||
case EbvFragData: return "FragData";
|
||||
case EbvFragDepth: return "FragDepth";
|
||||
case EbvFragStencilRef: return "FragStencilRef";
|
||||
case EbvSampleId: return "SampleId";
|
||||
case EbvSamplePosition: return "SamplePosition";
|
||||
case EbvSampleMask: return "SampleMaskIn";
|
||||
case EbvHelperInvocation: return "HelperInvocation";
|
||||
|
||||
case EbvBaryCoordNoPersp: return "BaryCoordNoPersp";
|
||||
case EbvBaryCoordNoPerspCentroid: return "BaryCoordNoPerspCentroid";
|
||||
case EbvBaryCoordNoPerspSample: return "BaryCoordNoPerspSample";
|
||||
case EbvBaryCoordSmooth: return "BaryCoordSmooth";
|
||||
case EbvBaryCoordSmoothCentroid: return "BaryCoordSmoothCentroid";
|
||||
case EbvBaryCoordSmoothSample: return "BaryCoordSmoothSample";
|
||||
case EbvBaryCoordPullModel: return "BaryCoordPullModel";
|
||||
|
||||
case EbvViewIndex: return "ViewIndex";
|
||||
case EbvDeviceIndex: return "DeviceIndex";
|
||||
|
||||
case EbvFragSizeEXT: return "FragSizeEXT";
|
||||
case EbvFragInvocationCountEXT: return "FragInvocationCountEXT";
|
||||
|
||||
case EbvSecondaryFragDataEXT: return "SecondaryFragDataEXT";
|
||||
case EbvSecondaryFragColorEXT: return "SecondaryFragColorEXT";
|
||||
|
||||
case EbvViewportMaskNV: return "ViewportMaskNV";
|
||||
case EbvSecondaryPositionNV: return "SecondaryPositionNV";
|
||||
case EbvSecondaryViewportMaskNV: return "SecondaryViewportMaskNV";
|
||||
case EbvPositionPerViewNV: return "PositionPerViewNV";
|
||||
case EbvViewportMaskPerViewNV: return "ViewportMaskPerViewNV";
|
||||
case EbvFragFullyCoveredNV: return "FragFullyCoveredNV";
|
||||
case EbvFragmentSizeNV: return "FragmentSizeNV";
|
||||
case EbvInvocationsPerPixelNV: return "InvocationsPerPixelNV";
|
||||
case EbvLaunchId: return "LaunchIdNV";
|
||||
case EbvLaunchSize: return "LaunchSizeNV";
|
||||
case EbvInstanceCustomIndex: return "InstanceCustomIndexNV";
|
||||
case EbvGeometryIndex: return "GeometryIndexEXT";
|
||||
case EbvWorldRayOrigin: return "WorldRayOriginNV";
|
||||
case EbvWorldRayDirection: return "WorldRayDirectionNV";
|
||||
case EbvObjectRayOrigin: return "ObjectRayOriginNV";
|
||||
case EbvObjectRayDirection: return "ObjectRayDirectionNV";
|
||||
case EbvRayTmin: return "ObjectRayTminNV";
|
||||
case EbvRayTmax: return "ObjectRayTmaxNV";
|
||||
case EbvHitT: return "HitTNV";
|
||||
case EbvHitKind: return "HitKindNV";
|
||||
case EbvIncomingRayFlags: return "IncomingRayFlagsNV";
|
||||
case EbvObjectToWorld: return "ObjectToWorldNV";
|
||||
case EbvWorldToObject: return "WorldToObjectNV";
|
||||
case EbvCurrentRayTimeNV: return "CurrentRayTimeNV";
|
||||
|
||||
case EbvBaryCoordEXT:
|
||||
case EbvBaryCoordNV: return "BaryCoordKHR";
|
||||
case EbvBaryCoordNoPerspEXT:
|
||||
case EbvBaryCoordNoPerspNV: return "BaryCoordNoPerspKHR";
|
||||
|
||||
case EbvTaskCountNV: return "TaskCountNV";
|
||||
case EbvPrimitiveCountNV: return "PrimitiveCountNV";
|
||||
case EbvPrimitiveIndicesNV: return "PrimitiveIndicesNV";
|
||||
case EbvClipDistancePerViewNV: return "ClipDistancePerViewNV";
|
||||
case EbvCullDistancePerViewNV: return "CullDistancePerViewNV";
|
||||
case EbvLayerPerViewNV: return "LayerPerViewNV";
|
||||
case EbvMeshViewCountNV: return "MeshViewCountNV";
|
||||
case EbvMeshViewIndicesNV: return "MeshViewIndicesNV";
|
||||
// GL_EXT_mesh_shader
|
||||
case EbvPrimitivePointIndicesEXT: return "PrimitivePointIndicesEXT";
|
||||
case EbvPrimitiveLineIndicesEXT: return "PrimitiveLineIndicesEXT";
|
||||
case EbvPrimitiveTriangleIndicesEXT: return "PrimitiveTriangleIndicesEXT";
|
||||
case EbvCullPrimitiveEXT: return "CullPrimitiveEXT";
|
||||
|
||||
case EbvWarpsPerSM: return "WarpsPerSMNV";
|
||||
case EbvSMCount: return "SMCountNV";
|
||||
case EbvWarpID: return "WarpIDNV";
|
||||
case EbvSMID: return "SMIDNV";
|
||||
|
||||
case EbvShadingRateKHR: return "ShadingRateKHR";
|
||||
case EbvPrimitiveShadingRateKHR: return "PrimitiveShadingRateKHR";
|
||||
|
||||
default: return "unknown built-in variable";
|
||||
}
|
||||
}
|
||||
|
||||
__inline const char* GetPrecisionQualifierString(TPrecisionQualifier p)
|
||||
{
|
||||
switch (p) {
|
||||
case EpqNone: return ""; break;
|
||||
case EpqLow: return "lowp"; break;
|
||||
case EpqMedium: return "mediump"; break;
|
||||
case EpqHigh: return "highp"; break;
|
||||
default: return "unknown precision qualifier";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
__inline bool isTypeSignedInt(TBasicType type)
|
||||
{
|
||||
switch (type) {
|
||||
case EbtInt8:
|
||||
case EbtInt16:
|
||||
case EbtInt:
|
||||
case EbtInt64:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
__inline bool isTypeUnsignedInt(TBasicType type)
|
||||
{
|
||||
switch (type) {
|
||||
case EbtUint8:
|
||||
case EbtUint16:
|
||||
case EbtUint:
|
||||
case EbtUint64:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
__inline bool isTypeInt(TBasicType type)
|
||||
{
|
||||
return isTypeSignedInt(type) || isTypeUnsignedInt(type);
|
||||
}
|
||||
|
||||
__inline bool isTypeFloat(TBasicType type)
|
||||
{
|
||||
switch (type) {
|
||||
case EbtFloat:
|
||||
case EbtDouble:
|
||||
case EbtFloat16:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
__inline int getTypeRank(TBasicType type)
|
||||
{
|
||||
int res = -1;
|
||||
switch(type) {
|
||||
case EbtInt8:
|
||||
case EbtUint8:
|
||||
res = 0;
|
||||
break;
|
||||
case EbtInt16:
|
||||
case EbtUint16:
|
||||
res = 1;
|
||||
break;
|
||||
case EbtInt:
|
||||
case EbtUint:
|
||||
res = 2;
|
||||
break;
|
||||
case EbtInt64:
|
||||
case EbtUint64:
|
||||
res = 3;
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _BASICTYPES_INCLUDED_
|
||||
340
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/Include/Common.h
vendored
Normal file
340
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/Include/Common.h
vendored
Normal file
@ -0,0 +1,340 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2012-2013 LunarG, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef _COMMON_INCLUDED_
|
||||
#define _COMMON_INCLUDED_
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#ifdef _MSC_VER
|
||||
#include <cfloat>
|
||||
#else
|
||||
#include <cmath>
|
||||
#endif
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#if defined(__ANDROID__) || (defined(_MSC_VER) && _MSC_VER < 1700)
|
||||
#include <sstream>
|
||||
namespace std {
|
||||
template<typename T>
|
||||
std::string to_string(const T& val) {
|
||||
std::ostringstream os;
|
||||
os << val;
|
||||
return os.str();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (defined(_MSC_VER) && _MSC_VER < 1900 /*vs2015*/) || (defined(MINGW_HAS_SECURE_API) && MINGW_HAS_SECURE_API)
|
||||
#include <basetsd.h>
|
||||
#ifndef snprintf
|
||||
#define snprintf sprintf_s
|
||||
#endif
|
||||
#define safe_vsprintf(buf,max,format,args) vsnprintf_s((buf), (max), (max), (format), (args))
|
||||
#elif defined (solaris)
|
||||
#define safe_vsprintf(buf,max,format,args) vsnprintf((buf), (max), (format), (args))
|
||||
#include <sys/int_types.h>
|
||||
#define UINT_PTR uintptr_t
|
||||
#else
|
||||
#define safe_vsprintf(buf,max,format,args) vsnprintf((buf), (max), (format), (args))
|
||||
#include <stdint.h>
|
||||
#define UINT_PTR uintptr_t
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1800
|
||||
#include <stdlib.h>
|
||||
inline long long int strtoll (const char* str, char** endptr, int base)
|
||||
{
|
||||
return _strtoi64(str, endptr, base);
|
||||
}
|
||||
inline unsigned long long int strtoull (const char* str, char** endptr, int base)
|
||||
{
|
||||
return _strtoui64(str, endptr, base);
|
||||
}
|
||||
inline long long int atoll (const char* str)
|
||||
{
|
||||
return strtoll(str, NULL, 10);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define strdup _strdup
|
||||
#endif
|
||||
|
||||
/* windows only pragma */
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4786) // Don't warn about too long identifiers
|
||||
#pragma warning(disable : 4514) // unused inline method
|
||||
#pragma warning(disable : 4201) // nameless union
|
||||
#endif
|
||||
|
||||
#include "PoolAlloc.h"
|
||||
|
||||
//
|
||||
// Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme.
|
||||
//
|
||||
#define POOL_ALLOCATOR_NEW_DELETE(A) \
|
||||
void* operator new(size_t s) { return (A).allocate(s); } \
|
||||
void* operator new(size_t, void *_Where) { return (_Where); } \
|
||||
void operator delete(void*) { } \
|
||||
void operator delete(void *, void *) { } \
|
||||
void* operator new[](size_t s) { return (A).allocate(s); } \
|
||||
void* operator new[](size_t, void *_Where) { return (_Where); } \
|
||||
void operator delete[](void*) { } \
|
||||
void operator delete[](void *, void *) { }
|
||||
|
||||
namespace glslang {
|
||||
|
||||
//
|
||||
// Pool version of string.
|
||||
//
|
||||
typedef pool_allocator<char> TStringAllocator;
|
||||
typedef std::basic_string <char, std::char_traits<char>, TStringAllocator> TString;
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
// Repackage the std::hash for use by unordered map/set with a TString key.
|
||||
namespace std {
|
||||
|
||||
template<> struct hash<glslang::TString> {
|
||||
std::size_t operator()(const glslang::TString& s) const
|
||||
{
|
||||
const unsigned _FNV_offset_basis = 2166136261U;
|
||||
const unsigned _FNV_prime = 16777619U;
|
||||
unsigned _Val = _FNV_offset_basis;
|
||||
size_t _Count = s.size();
|
||||
const char* _First = s.c_str();
|
||||
for (size_t _Next = 0; _Next < _Count; ++_Next)
|
||||
{
|
||||
_Val ^= (unsigned)_First[_Next];
|
||||
_Val *= _FNV_prime;
|
||||
}
|
||||
|
||||
return _Val;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace glslang {
|
||||
|
||||
inline TString* NewPoolTString(const char* s)
|
||||
{
|
||||
void* memory = GetThreadPoolAllocator().allocate(sizeof(TString));
|
||||
return new(memory) TString(s);
|
||||
}
|
||||
|
||||
template<class T> inline T* NewPoolObject(T*)
|
||||
{
|
||||
return new(GetThreadPoolAllocator().allocate(sizeof(T))) T;
|
||||
}
|
||||
|
||||
template<class T> inline T* NewPoolObject(T, int instances)
|
||||
{
|
||||
return new(GetThreadPoolAllocator().allocate(instances * sizeof(T))) T[instances];
|
||||
}
|
||||
|
||||
//
|
||||
// Pool allocator versions of vectors, lists, and maps
|
||||
//
|
||||
template <class T> class TVector : public std::vector<T, pool_allocator<T> > {
|
||||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
|
||||
typedef typename std::vector<T, pool_allocator<T> >::size_type size_type;
|
||||
TVector() : std::vector<T, pool_allocator<T> >() {}
|
||||
TVector(const pool_allocator<T>& a) : std::vector<T, pool_allocator<T> >(a) {}
|
||||
TVector(size_type i) : std::vector<T, pool_allocator<T> >(i) {}
|
||||
TVector(size_type i, const T& val) : std::vector<T, pool_allocator<T> >(i, val) {}
|
||||
};
|
||||
|
||||
template <class T> class TList : public std::list<T, pool_allocator<T> > {
|
||||
};
|
||||
|
||||
template <class K, class D, class CMP = std::less<K> >
|
||||
class TMap : public std::map<K, D, CMP, pool_allocator<std::pair<K const, D> > > {
|
||||
};
|
||||
|
||||
template <class K, class D, class HASH = std::hash<K>, class PRED = std::equal_to<K> >
|
||||
class TUnorderedMap : public std::unordered_map<K, D, HASH, PRED, pool_allocator<std::pair<K const, D> > > {
|
||||
};
|
||||
|
||||
template <class K, class CMP = std::less<K> >
|
||||
class TSet : public std::set<K, CMP, pool_allocator<K> > {
|
||||
};
|
||||
|
||||
//
|
||||
// Persistent string memory. Should only be used for strings that survive
|
||||
// across compiles/links.
|
||||
//
|
||||
typedef std::basic_string<char> TPersistString;
|
||||
|
||||
//
|
||||
// templatized min and max functions.
|
||||
//
|
||||
template <class T> T Min(const T a, const T b) { return a < b ? a : b; }
|
||||
template <class T> T Max(const T a, const T b) { return a > b ? a : b; }
|
||||
|
||||
//
|
||||
// Create a TString object from an integer.
|
||||
//
|
||||
#if defined(_MSC_VER) || (defined(MINGW_HAS_SECURE_API) && MINGW_HAS_SECURE_API)
|
||||
inline const TString String(const int i, const int base = 10)
|
||||
{
|
||||
char text[16]; // 32 bit ints are at most 10 digits in base 10
|
||||
_itoa_s(i, text, sizeof(text), base);
|
||||
return text;
|
||||
}
|
||||
#else
|
||||
inline const TString String(const int i, const int /*base*/ = 10)
|
||||
{
|
||||
char text[16]; // 32 bit ints are at most 10 digits in base 10
|
||||
|
||||
// we assume base 10 for all cases
|
||||
snprintf(text, sizeof(text), "%d", i);
|
||||
|
||||
return text;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct TSourceLoc {
|
||||
void init()
|
||||
{
|
||||
name = nullptr; string = 0; line = 0; column = 0;
|
||||
}
|
||||
void init(int stringNum) { init(); string = stringNum; }
|
||||
// Returns the name if it exists. Otherwise, returns the string number.
|
||||
std::string getStringNameOrNum(bool quoteStringName = true) const
|
||||
{
|
||||
if (name != nullptr) {
|
||||
TString qstr = quoteStringName ? ("\"" + *name + "\"") : *name;
|
||||
std::string ret_str(qstr.c_str());
|
||||
return ret_str;
|
||||
}
|
||||
return std::to_string((long long)string);
|
||||
}
|
||||
const char* getFilename() const
|
||||
{
|
||||
if (name == nullptr)
|
||||
return nullptr;
|
||||
return name->c_str();
|
||||
}
|
||||
const char* getFilenameStr() const { return name == nullptr ? "" : name->c_str(); }
|
||||
TString* name; // descriptive name for this string, when a textual name is available, otherwise nullptr
|
||||
int string;
|
||||
int line;
|
||||
int column;
|
||||
};
|
||||
|
||||
class TPragmaTable : public TMap<TString, TString> {
|
||||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
};
|
||||
|
||||
const int MaxTokenLength = 1024;
|
||||
|
||||
template <class T> bool IsPow2(T powerOf2)
|
||||
{
|
||||
if (powerOf2 <= 0)
|
||||
return false;
|
||||
|
||||
return (powerOf2 & (powerOf2 - 1)) == 0;
|
||||
}
|
||||
|
||||
// Round number up to a multiple of the given powerOf2, which is not
|
||||
// a power, just a number that must be a power of 2.
|
||||
template <class T> void RoundToPow2(T& number, int powerOf2)
|
||||
{
|
||||
assert(IsPow2(powerOf2));
|
||||
number = (number + powerOf2 - 1) & ~(powerOf2 - 1);
|
||||
}
|
||||
|
||||
template <class T> bool IsMultipleOfPow2(T number, int powerOf2)
|
||||
{
|
||||
assert(IsPow2(powerOf2));
|
||||
return ! (number & (powerOf2 - 1));
|
||||
}
|
||||
|
||||
// Returns log2 of an integer power of 2.
|
||||
// T should be integral.
|
||||
template <class T> int IntLog2(T n)
|
||||
{
|
||||
assert(IsPow2(n));
|
||||
int result = 0;
|
||||
while ((T(1) << result) != n) {
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline bool IsInfinity(double x) {
|
||||
#ifdef _MSC_VER
|
||||
switch (_fpclass(x)) {
|
||||
case _FPCLASS_NINF:
|
||||
case _FPCLASS_PINF:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
return std::isinf(x);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool IsNan(double x) {
|
||||
#ifdef _MSC_VER
|
||||
switch (_fpclass(x)) {
|
||||
case _FPCLASS_SNAN:
|
||||
case _FPCLASS_QNAN:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
return std::isnan(x);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _COMMON_INCLUDED_
|
||||
@ -0,0 +1,974 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2013 LunarG, Inc.
|
||||
// Copyright (C) 2017 ARM Limited.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef _CONSTANT_UNION_INCLUDED_
|
||||
#define _CONSTANT_UNION_INCLUDED_
|
||||
|
||||
#include "../Include/Common.h"
|
||||
#include "../Include/BaseTypes.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
class TConstUnion {
|
||||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
|
||||
TConstUnion() : iConst(0), type(EbtInt) { }
|
||||
|
||||
void setI8Const(signed char i)
|
||||
{
|
||||
i8Const = i;
|
||||
type = EbtInt8;
|
||||
}
|
||||
|
||||
void setU8Const(unsigned char u)
|
||||
{
|
||||
u8Const = u;
|
||||
type = EbtUint8;
|
||||
}
|
||||
|
||||
void setI16Const(signed short i)
|
||||
{
|
||||
i16Const = i;
|
||||
type = EbtInt16;
|
||||
}
|
||||
|
||||
void setU16Const(unsigned short u)
|
||||
{
|
||||
u16Const = u;
|
||||
type = EbtUint16;
|
||||
}
|
||||
|
||||
void setIConst(int i)
|
||||
{
|
||||
iConst = i;
|
||||
type = EbtInt;
|
||||
}
|
||||
|
||||
void setUConst(unsigned int u)
|
||||
{
|
||||
uConst = u;
|
||||
type = EbtUint;
|
||||
}
|
||||
|
||||
void setI64Const(long long i64)
|
||||
{
|
||||
i64Const = i64;
|
||||
type = EbtInt64;
|
||||
}
|
||||
|
||||
void setU64Const(unsigned long long u64)
|
||||
{
|
||||
u64Const = u64;
|
||||
type = EbtUint64;
|
||||
}
|
||||
|
||||
void setDConst(double d)
|
||||
{
|
||||
dConst = d;
|
||||
type = EbtDouble;
|
||||
}
|
||||
|
||||
void setBConst(bool b)
|
||||
{
|
||||
bConst = b;
|
||||
type = EbtBool;
|
||||
}
|
||||
|
||||
void setSConst(const TString* s)
|
||||
{
|
||||
sConst = s;
|
||||
type = EbtString;
|
||||
}
|
||||
|
||||
signed char getI8Const() const { return i8Const; }
|
||||
unsigned char getU8Const() const { return u8Const; }
|
||||
signed short getI16Const() const { return i16Const; }
|
||||
unsigned short getU16Const() const { return u16Const; }
|
||||
int getIConst() const { return iConst; }
|
||||
unsigned int getUConst() const { return uConst; }
|
||||
long long getI64Const() const { return i64Const; }
|
||||
unsigned long long getU64Const() const { return u64Const; }
|
||||
double getDConst() const { return dConst; }
|
||||
bool getBConst() const { return bConst; }
|
||||
const TString* getSConst() const { return sConst; }
|
||||
|
||||
bool operator==(const signed char i) const
|
||||
{
|
||||
if (i == i8Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const unsigned char u) const
|
||||
{
|
||||
if (u == u8Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const signed short i) const
|
||||
{
|
||||
if (i == i16Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const unsigned short u) const
|
||||
{
|
||||
if (u == u16Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const int i) const
|
||||
{
|
||||
if (i == iConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const unsigned int u) const
|
||||
{
|
||||
if (u == uConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const long long i64) const
|
||||
{
|
||||
if (i64 == i64Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const unsigned long long u64) const
|
||||
{
|
||||
if (u64 == u64Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const double d) const
|
||||
{
|
||||
if (d == dConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const bool b) const
|
||||
{
|
||||
if (b == bConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const TConstUnion& constant) const
|
||||
{
|
||||
if (constant.type != type)
|
||||
return false;
|
||||
|
||||
switch (type) {
|
||||
case EbtInt:
|
||||
if (constant.iConst == iConst)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtUint:
|
||||
if (constant.uConst == uConst)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtBool:
|
||||
if (constant.bConst == bConst)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtDouble:
|
||||
if (constant.dConst == dConst)
|
||||
return true;
|
||||
|
||||
break;
|
||||
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt16:
|
||||
if (constant.i16Const == i16Const)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtUint16:
|
||||
if (constant.u16Const == u16Const)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtInt8:
|
||||
if (constant.i8Const == i8Const)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtUint8:
|
||||
if (constant.u8Const == u8Const)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtInt64:
|
||||
if (constant.i64Const == i64Const)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtUint64:
|
||||
if (constant.u64Const == u64Const)
|
||||
return true;
|
||||
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator!=(const signed char i) const
|
||||
{
|
||||
return !operator==(i);
|
||||
}
|
||||
|
||||
bool operator!=(const unsigned char u) const
|
||||
{
|
||||
return !operator==(u);
|
||||
}
|
||||
|
||||
bool operator!=(const signed short i) const
|
||||
{
|
||||
return !operator==(i);
|
||||
}
|
||||
|
||||
bool operator!=(const unsigned short u) const
|
||||
{
|
||||
return !operator==(u);
|
||||
}
|
||||
|
||||
bool operator!=(const int i) const
|
||||
{
|
||||
return !operator==(i);
|
||||
}
|
||||
|
||||
bool operator!=(const unsigned int u) const
|
||||
{
|
||||
return !operator==(u);
|
||||
}
|
||||
|
||||
bool operator!=(const long long i) const
|
||||
{
|
||||
return !operator==(i);
|
||||
}
|
||||
|
||||
bool operator!=(const unsigned long long u) const
|
||||
{
|
||||
return !operator==(u);
|
||||
}
|
||||
|
||||
bool operator!=(const float f) const
|
||||
{
|
||||
return !operator==(f);
|
||||
}
|
||||
|
||||
bool operator!=(const bool b) const
|
||||
{
|
||||
return !operator==(b);
|
||||
}
|
||||
|
||||
bool operator!=(const TConstUnion& constant) const
|
||||
{
|
||||
return !operator==(constant);
|
||||
}
|
||||
|
||||
bool operator>(const TConstUnion& constant) const
|
||||
{
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt:
|
||||
if (iConst > constant.iConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtUint:
|
||||
if (uConst > constant.uConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtDouble:
|
||||
if (dConst > constant.dConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8:
|
||||
if (i8Const > constant.i8Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtUint8:
|
||||
if (u8Const > constant.u8Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtInt16:
|
||||
if (i16Const > constant.i16Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtUint16:
|
||||
if (u16Const > constant.u16Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtInt64:
|
||||
if (i64Const > constant.i64Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtUint64:
|
||||
if (u64Const > constant.u64Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
#endif
|
||||
default:
|
||||
assert(false && "Default missing");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator<(const TConstUnion& constant) const
|
||||
{
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8:
|
||||
if (i8Const < constant.i8Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtUint8:
|
||||
if (u8Const < constant.u8Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtInt16:
|
||||
if (i16Const < constant.i16Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtUint16:
|
||||
if (u16Const < constant.u16Const)
|
||||
return true;
|
||||
return false;
|
||||
case EbtInt64:
|
||||
if (i64Const < constant.i64Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtUint64:
|
||||
if (u64Const < constant.u64Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
#endif
|
||||
case EbtDouble:
|
||||
if (dConst < constant.dConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtInt:
|
||||
if (iConst < constant.iConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtUint:
|
||||
if (uConst < constant.uConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
default:
|
||||
assert(false && "Default missing");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
TConstUnion operator+(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst + constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst + constant.uConst); break;
|
||||
case EbtDouble: returnValue.setDConst(dConst + constant.dConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setI8Const(i8Const + constant.i8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(i16Const + constant.i16Const); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const + constant.i64Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const + constant.u8Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const + constant.u16Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const + constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator-(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst - constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst - constant.uConst); break;
|
||||
case EbtDouble: returnValue.setDConst(dConst - constant.dConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setI8Const(i8Const - constant.i8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(i16Const - constant.i16Const); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const - constant.i64Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const - constant.u8Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const - constant.u16Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const - constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator*(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst * constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst * constant.uConst); break;
|
||||
case EbtDouble: returnValue.setDConst(dConst * constant.dConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setI8Const(i8Const * constant.i8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(i16Const * constant.i16Const); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const * constant.i64Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const * constant.u8Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const * constant.u16Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const * constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator%(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst % constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst % constant.uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setI8Const(i8Const % constant.i8Const); break;
|
||||
case EbtInt16: returnValue.setI8Const(i8Const % constant.i16Const); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const % constant.i64Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const % constant.u8Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const % constant.u16Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const % constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator>>(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
switch (type) {
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setI8Const(i8Const >> constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setI8Const(i8Const >> constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI8Const(i8Const >> constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setI8Const(i8Const >> constant.u16Const); break;
|
||||
case EbtInt: returnValue.setI8Const(i8Const >> constant.iConst); break;
|
||||
case EbtUint: returnValue.setI8Const(i8Const >> constant.uConst); break;
|
||||
case EbtInt64: returnValue.setI8Const(i8Const >> constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setI8Const(i8Const >> constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtUint8:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setU8Const(u8Const >> constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const >> constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setU8Const(u8Const >> constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU8Const(u8Const >> constant.u16Const); break;
|
||||
case EbtInt: returnValue.setU8Const(u8Const >> constant.iConst); break;
|
||||
case EbtUint: returnValue.setU8Const(u8Const >> constant.uConst); break;
|
||||
case EbtInt64: returnValue.setU8Const(u8Const >> constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU8Const(u8Const >> constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtInt16:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setI16Const(i16Const >> constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setI16Const(i16Const >> constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(i16Const >> constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setI16Const(i16Const >> constant.u16Const); break;
|
||||
case EbtInt: returnValue.setI16Const(i16Const >> constant.iConst); break;
|
||||
case EbtUint: returnValue.setI16Const(i16Const >> constant.uConst); break;
|
||||
case EbtInt64: returnValue.setI16Const(i16Const >> constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setI16Const(i16Const >> constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtUint16:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setU16Const(u16Const >> constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU16Const(u16Const >> constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setU16Const(u16Const >> constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const >> constant.u16Const); break;
|
||||
case EbtInt: returnValue.setU16Const(u16Const >> constant.iConst); break;
|
||||
case EbtUint: returnValue.setU16Const(u16Const >> constant.uConst); break;
|
||||
case EbtInt64: returnValue.setU16Const(u16Const >> constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU16Const(u16Const >> constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case EbtInt:
|
||||
switch (constant.type) {
|
||||
case EbtInt: returnValue.setIConst(iConst >> constant.iConst); break;
|
||||
case EbtUint: returnValue.setIConst(iConst >> constant.uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setIConst(iConst >> constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setIConst(iConst >> constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setIConst(iConst >> constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setIConst(iConst >> constant.u16Const); break;
|
||||
case EbtInt64: returnValue.setIConst(iConst >> constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setIConst(iConst >> constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtUint:
|
||||
switch (constant.type) {
|
||||
case EbtInt: returnValue.setUConst(uConst >> constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst >> constant.uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setUConst(uConst >> constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setUConst(uConst >> constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setUConst(uConst >> constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setUConst(uConst >> constant.u16Const); break;
|
||||
case EbtInt64: returnValue.setUConst(uConst >> constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setUConst(uConst >> constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt64:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setI64Const(i64Const >> constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setI64Const(i64Const >> constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI64Const(i64Const >> constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setI64Const(i64Const >> constant.u16Const); break;
|
||||
case EbtInt: returnValue.setI64Const(i64Const >> constant.iConst); break;
|
||||
case EbtUint: returnValue.setI64Const(i64Const >> constant.uConst); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const >> constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setI64Const(i64Const >> constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtUint64:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setU64Const(u64Const >> constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU64Const(u64Const >> constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setU64Const(u64Const >> constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU64Const(u64Const >> constant.u16Const); break;
|
||||
case EbtInt: returnValue.setU64Const(u64Const >> constant.iConst); break;
|
||||
case EbtUint: returnValue.setU64Const(u64Const >> constant.uConst); break;
|
||||
case EbtInt64: returnValue.setU64Const(u64Const >> constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const >> constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator<<(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
switch (type) {
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setI8Const(i8Const << constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setI8Const(i8Const << constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI8Const(i8Const << constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setI8Const(i8Const << constant.u16Const); break;
|
||||
case EbtInt: returnValue.setI8Const(i8Const << constant.iConst); break;
|
||||
case EbtUint: returnValue.setI8Const(i8Const << constant.uConst); break;
|
||||
case EbtInt64: returnValue.setI8Const(i8Const << constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setI8Const(i8Const << constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtUint8:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setU8Const(u8Const << constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const << constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setU8Const(u8Const << constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU8Const(u8Const << constant.u16Const); break;
|
||||
case EbtInt: returnValue.setU8Const(u8Const << constant.iConst); break;
|
||||
case EbtUint: returnValue.setU8Const(u8Const << constant.uConst); break;
|
||||
case EbtInt64: returnValue.setU8Const(u8Const << constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU8Const(u8Const << constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtInt16:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setI16Const(i16Const << constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setI16Const(i16Const << constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(i16Const << constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setI16Const(i16Const << constant.u16Const); break;
|
||||
case EbtInt: returnValue.setI16Const(i16Const << constant.iConst); break;
|
||||
case EbtUint: returnValue.setI16Const(i16Const << constant.uConst); break;
|
||||
case EbtInt64: returnValue.setI16Const(i16Const << constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setI16Const(i16Const << constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtUint16:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setU16Const(u16Const << constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU16Const(u16Const << constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setU16Const(u16Const << constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const << constant.u16Const); break;
|
||||
case EbtInt: returnValue.setU16Const(u16Const << constant.iConst); break;
|
||||
case EbtUint: returnValue.setU16Const(u16Const << constant.uConst); break;
|
||||
case EbtInt64: returnValue.setU16Const(u16Const << constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU16Const(u16Const << constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtInt64:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setI64Const(i64Const << constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setI64Const(i64Const << constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI64Const(i64Const << constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setI64Const(i64Const << constant.u16Const); break;
|
||||
case EbtInt: returnValue.setI64Const(i64Const << constant.iConst); break;
|
||||
case EbtUint: returnValue.setI64Const(i64Const << constant.uConst); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const << constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setI64Const(i64Const << constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtUint64:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setU64Const(u64Const << constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU64Const(u64Const << constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setU64Const(u64Const << constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU64Const(u64Const << constant.u16Const); break;
|
||||
case EbtInt: returnValue.setU64Const(u64Const << constant.iConst); break;
|
||||
case EbtUint: returnValue.setU64Const(u64Const << constant.uConst); break;
|
||||
case EbtInt64: returnValue.setU64Const(u64Const << constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const << constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case EbtInt:
|
||||
switch (constant.type) {
|
||||
case EbtInt: returnValue.setIConst(iConst << constant.iConst); break;
|
||||
case EbtUint: returnValue.setIConst(iConst << constant.uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setIConst(iConst << constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setIConst(iConst << constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setIConst(iConst << constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setIConst(iConst << constant.u16Const); break;
|
||||
case EbtInt64: returnValue.setIConst(iConst << constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setIConst(iConst << constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtUint:
|
||||
switch (constant.type) {
|
||||
case EbtInt: returnValue.setUConst(uConst << constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst << constant.uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setUConst(uConst << constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setUConst(uConst << constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setUConst(uConst << constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setUConst(uConst << constant.u16Const); break;
|
||||
case EbtInt64: returnValue.setUConst(uConst << constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setUConst(uConst << constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator&(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst & constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst & constant.uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setI8Const(i8Const & constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const & constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(i16Const & constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const & constant.u16Const); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const & constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const & constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator|(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst | constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst | constant.uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setI8Const(i8Const | constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const | constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(i16Const | constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const | constant.u16Const); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const | constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const | constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator^(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst ^ constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst ^ constant.uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setI8Const(i8Const ^ constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const ^ constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(i16Const ^ constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const ^ constant.u16Const); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const ^ constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const ^ constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator~() const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(~iConst); break;
|
||||
case EbtUint: returnValue.setUConst(~uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setI8Const(~i8Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(~u8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(~i16Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(~u16Const); break;
|
||||
case EbtInt64: returnValue.setI64Const(~i64Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(~u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator&&(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtBool: returnValue.setBConst(bConst && constant.bConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator||(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtBool: returnValue.setBConst(bConst || constant.bConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TBasicType getType() const { return type; }
|
||||
|
||||
private:
|
||||
union {
|
||||
signed char i8Const; // used for i8vec, scalar int8s
|
||||
unsigned char u8Const; // used for u8vec, scalar uint8s
|
||||
signed short i16Const; // used for i16vec, scalar int16s
|
||||
unsigned short u16Const; // used for u16vec, scalar uint16s
|
||||
int iConst; // used for ivec, scalar ints
|
||||
unsigned int uConst; // used for uvec, scalar uints
|
||||
long long i64Const; // used for i64vec, scalar int64s
|
||||
unsigned long long u64Const; // used for u64vec, scalar uint64s
|
||||
bool bConst; // used for bvec, scalar bools
|
||||
double dConst; // used for vec, dvec, mat, dmat, scalar floats and doubles
|
||||
const TString* sConst; // string constant
|
||||
};
|
||||
|
||||
TBasicType type;
|
||||
};
|
||||
|
||||
// Encapsulate having a pointer to an array of TConstUnion,
|
||||
// which only needs to be allocated if its size is going to be
|
||||
// bigger than 0.
|
||||
//
|
||||
// One convenience is being able to use [] to go inside the array, instead
|
||||
// of C++ assuming it as an array of pointers to vectors.
|
||||
//
|
||||
// General usage is that the size is known up front, and it is
|
||||
// created once with the proper size.
|
||||
//
|
||||
class TConstUnionArray {
|
||||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
|
||||
TConstUnionArray() : unionArray(nullptr) { }
|
||||
virtual ~TConstUnionArray() { }
|
||||
|
||||
explicit TConstUnionArray(int size)
|
||||
{
|
||||
if (size == 0)
|
||||
unionArray = nullptr;
|
||||
else
|
||||
unionArray = new TConstUnionVector(size);
|
||||
}
|
||||
TConstUnionArray(const TConstUnionArray& a) = default;
|
||||
TConstUnionArray(const TConstUnionArray& a, int start, int size)
|
||||
{
|
||||
unionArray = new TConstUnionVector(size);
|
||||
for (int i = 0; i < size; ++i)
|
||||
(*unionArray)[i] = a[start + i];
|
||||
}
|
||||
|
||||
// Use this constructor for a smear operation
|
||||
TConstUnionArray(int size, const TConstUnion& val)
|
||||
{
|
||||
unionArray = new TConstUnionVector(size, val);
|
||||
}
|
||||
|
||||
int size() const { return unionArray ? (int)unionArray->size() : 0; }
|
||||
TConstUnion& operator[](size_t index) { return (*unionArray)[index]; }
|
||||
const TConstUnion& operator[](size_t index) const { return (*unionArray)[index]; }
|
||||
bool operator==(const TConstUnionArray& rhs) const
|
||||
{
|
||||
// this includes the case that both are unallocated
|
||||
if (unionArray == rhs.unionArray)
|
||||
return true;
|
||||
|
||||
if (! unionArray || ! rhs.unionArray)
|
||||
return false;
|
||||
|
||||
return *unionArray == *rhs.unionArray;
|
||||
}
|
||||
bool operator!=(const TConstUnionArray& rhs) const { return ! operator==(rhs); }
|
||||
|
||||
double dot(const TConstUnionArray& rhs)
|
||||
{
|
||||
assert(rhs.unionArray->size() == unionArray->size());
|
||||
double sum = 0.0;
|
||||
|
||||
for (size_t comp = 0; comp < unionArray->size(); ++comp)
|
||||
sum += (*this)[comp].getDConst() * rhs[comp].getDConst();
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
bool empty() const { return unionArray == nullptr; }
|
||||
|
||||
protected:
|
||||
typedef TVector<TConstUnion> TConstUnionVector;
|
||||
TConstUnionVector* unionArray;
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _CONSTANT_UNION_INCLUDED_
|
||||
144
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/Include/InfoSink.h
vendored
Normal file
144
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/Include/InfoSink.h
vendored
Normal file
@ -0,0 +1,144 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef _INFOSINK_INCLUDED_
|
||||
#define _INFOSINK_INCLUDED_
|
||||
|
||||
#include "../Include/Common.h"
|
||||
#include <cmath>
|
||||
|
||||
namespace glslang {
|
||||
|
||||
//
|
||||
// TPrefixType is used to centralize how info log messages start.
|
||||
// See below.
|
||||
//
|
||||
enum TPrefixType {
|
||||
EPrefixNone,
|
||||
EPrefixWarning,
|
||||
EPrefixError,
|
||||
EPrefixInternalError,
|
||||
EPrefixUnimplemented,
|
||||
EPrefixNote
|
||||
};
|
||||
|
||||
enum TOutputStream {
|
||||
ENull = 0,
|
||||
EDebugger = 0x01,
|
||||
EStdOut = 0x02,
|
||||
EString = 0x04,
|
||||
};
|
||||
//
|
||||
// Encapsulate info logs for all objects that have them.
|
||||
//
|
||||
// The methods are a general set of tools for getting a variety of
|
||||
// messages and types inserted into the log.
|
||||
//
|
||||
class TInfoSinkBase {
|
||||
public:
|
||||
TInfoSinkBase() : outputStream(4) {}
|
||||
void erase() { sink.erase(); }
|
||||
TInfoSinkBase& operator<<(const TPersistString& t) { append(t); return *this; }
|
||||
TInfoSinkBase& operator<<(char c) { append(1, c); return *this; }
|
||||
TInfoSinkBase& operator<<(const char* s) { append(s); return *this; }
|
||||
TInfoSinkBase& operator<<(int n) { append(String(n)); return *this; }
|
||||
TInfoSinkBase& operator<<(unsigned int n) { append(String(n)); return *this; }
|
||||
TInfoSinkBase& operator<<(float n) { const int size = 40; char buf[size];
|
||||
snprintf(buf, size, (fabs(n) > 1e-8 && fabs(n) < 1e8) || n == 0.0f ? "%f" : "%g", n);
|
||||
append(buf);
|
||||
return *this; }
|
||||
TInfoSinkBase& operator+(const TPersistString& t) { append(t); return *this; }
|
||||
TInfoSinkBase& operator+(const TString& t) { append(t); return *this; }
|
||||
TInfoSinkBase& operator<<(const TString& t) { append(t); return *this; }
|
||||
TInfoSinkBase& operator+(const char* s) { append(s); return *this; }
|
||||
const char* c_str() const { return sink.c_str(); }
|
||||
void prefix(TPrefixType message) {
|
||||
switch(message) {
|
||||
case EPrefixNone: break;
|
||||
case EPrefixWarning: append("WARNING: "); break;
|
||||
case EPrefixError: append("ERROR: "); break;
|
||||
case EPrefixInternalError: append("INTERNAL ERROR: "); break;
|
||||
case EPrefixUnimplemented: append("UNIMPLEMENTED: "); break;
|
||||
case EPrefixNote: append("NOTE: "); break;
|
||||
default: append("UNKNOWN ERROR: "); break;
|
||||
}
|
||||
}
|
||||
void location(const TSourceLoc& loc) {
|
||||
const int maxSize = 24;
|
||||
char locText[maxSize];
|
||||
snprintf(locText, maxSize, ":%d", loc.line);
|
||||
append(loc.getStringNameOrNum(false).c_str());
|
||||
append(locText);
|
||||
append(": ");
|
||||
}
|
||||
void message(TPrefixType message, const char* s) {
|
||||
prefix(message);
|
||||
append(s);
|
||||
append("\n");
|
||||
}
|
||||
void message(TPrefixType message, const char* s, const TSourceLoc& loc) {
|
||||
prefix(message);
|
||||
location(loc);
|
||||
append(s);
|
||||
append("\n");
|
||||
}
|
||||
|
||||
void setOutputStream(int output = 4)
|
||||
{
|
||||
outputStream = output;
|
||||
}
|
||||
|
||||
protected:
|
||||
void append(const char* s);
|
||||
|
||||
void append(int count, char c);
|
||||
void append(const TPersistString& t);
|
||||
void append(const TString& t);
|
||||
|
||||
void checkMem(size_t growth) { if (sink.capacity() < sink.size() + growth + 2)
|
||||
sink.reserve(sink.capacity() + sink.capacity() / 2); }
|
||||
void appendToStream(const char* s);
|
||||
TPersistString sink;
|
||||
int outputStream;
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
class TInfoSink {
|
||||
public:
|
||||
glslang::TInfoSinkBase info;
|
||||
glslang::TInfoSinkBase debug;
|
||||
};
|
||||
|
||||
#endif // _INFOSINK_INCLUDED_
|
||||
@ -0,0 +1,44 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef __INITIALIZE_GLOBALS_INCLUDED_
|
||||
#define __INITIALIZE_GLOBALS_INCLUDED_
|
||||
|
||||
namespace glslang {
|
||||
|
||||
bool InitializePoolIndex();
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // __INITIALIZE_GLOBALS_INCLUDED_
|
||||
318
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/Include/PoolAlloc.h
vendored
Normal file
318
Android/android-ndk-r27d/sources/third_party/shaderc/third_party/glslang/glslang/Include/PoolAlloc.h
vendored
Normal file
@ -0,0 +1,318 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2012-2013 LunarG, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef _POOLALLOC_INCLUDED_
|
||||
#define _POOLALLOC_INCLUDED_
|
||||
|
||||
#ifdef _DEBUG
|
||||
# define GUARD_BLOCKS // define to enable guard block sanity checking
|
||||
#endif
|
||||
|
||||
//
|
||||
// This header defines an allocator that can be used to efficiently
|
||||
// allocate a large number of small requests for heap memory, with the
|
||||
// intention that they are not individually deallocated, but rather
|
||||
// collectively deallocated at one time.
|
||||
//
|
||||
// This simultaneously
|
||||
//
|
||||
// * Makes each individual allocation much more efficient; the
|
||||
// typical allocation is trivial.
|
||||
// * Completely avoids the cost of doing individual deallocation.
|
||||
// * Saves the trouble of tracking down and plugging a large class of leaks.
|
||||
//
|
||||
// Individual classes can use this allocator by supplying their own
|
||||
// new and delete methods.
|
||||
//
|
||||
// STL containers can use this allocator by using the pool_allocator
|
||||
// class as the allocator (second) template argument.
|
||||
//
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
namespace glslang {
|
||||
|
||||
// If we are using guard blocks, we must track each individual
|
||||
// allocation. If we aren't using guard blocks, these
|
||||
// never get instantiated, so won't have any impact.
|
||||
//
|
||||
|
||||
class TAllocation {
|
||||
public:
|
||||
TAllocation(size_t size, unsigned char* mem, TAllocation* prev = 0) :
|
||||
size(size), mem(mem), prevAlloc(prev) {
|
||||
// Allocations are bracketed:
|
||||
// [allocationHeader][initialGuardBlock][userData][finalGuardBlock]
|
||||
// This would be cleaner with if (guardBlockSize)..., but that
|
||||
// makes the compiler print warnings about 0 length memsets,
|
||||
// even with the if() protecting them.
|
||||
# ifdef GUARD_BLOCKS
|
||||
memset(preGuard(), guardBlockBeginVal, guardBlockSize);
|
||||
memset(data(), userDataFill, size);
|
||||
memset(postGuard(), guardBlockEndVal, guardBlockSize);
|
||||
# endif
|
||||
}
|
||||
|
||||
void check() const {
|
||||
checkGuardBlock(preGuard(), guardBlockBeginVal, "before");
|
||||
checkGuardBlock(postGuard(), guardBlockEndVal, "after");
|
||||
}
|
||||
|
||||
void checkAllocList() const;
|
||||
|
||||
// Return total size needed to accommodate user buffer of 'size',
|
||||
// plus our tracking data.
|
||||
inline static size_t allocationSize(size_t size) {
|
||||
return size + 2 * guardBlockSize + headerSize();
|
||||
}
|
||||
|
||||
// Offset from surrounding buffer to get to user data buffer.
|
||||
inline static unsigned char* offsetAllocation(unsigned char* m) {
|
||||
return m + guardBlockSize + headerSize();
|
||||
}
|
||||
|
||||
private:
|
||||
void checkGuardBlock(unsigned char* blockMem, unsigned char val, const char* locText) const;
|
||||
|
||||
// Find offsets to pre and post guard blocks, and user data buffer
|
||||
unsigned char* preGuard() const { return mem + headerSize(); }
|
||||
unsigned char* data() const { return preGuard() + guardBlockSize; }
|
||||
unsigned char* postGuard() const { return data() + size; }
|
||||
|
||||
size_t size; // size of the user data area
|
||||
unsigned char* mem; // beginning of our allocation (pts to header)
|
||||
TAllocation* prevAlloc; // prior allocation in the chain
|
||||
|
||||
const static unsigned char guardBlockBeginVal;
|
||||
const static unsigned char guardBlockEndVal;
|
||||
const static unsigned char userDataFill;
|
||||
|
||||
const static size_t guardBlockSize;
|
||||
# ifdef GUARD_BLOCKS
|
||||
inline static size_t headerSize() { return sizeof(TAllocation); }
|
||||
# else
|
||||
inline static size_t headerSize() { return 0; }
|
||||
# endif
|
||||
};
|
||||
|
||||
//
|
||||
// There are several stacks. One is to track the pushing and popping
|
||||
// of the user, and not yet implemented. The others are simply a
|
||||
// repositories of free pages or used pages.
|
||||
//
|
||||
// Page stacks are linked together with a simple header at the beginning
|
||||
// of each allocation obtained from the underlying OS. Multi-page allocations
|
||||
// are returned to the OS. Individual page allocations are kept for future
|
||||
// re-use.
|
||||
//
|
||||
// The "page size" used is not, nor must it match, the underlying OS
|
||||
// page size. But, having it be about that size or equal to a set of
|
||||
// pages is likely most optimal.
|
||||
//
|
||||
class TPoolAllocator {
|
||||
public:
|
||||
TPoolAllocator(int growthIncrement = 8*1024, int allocationAlignment = 16);
|
||||
|
||||
//
|
||||
// Don't call the destructor just to free up the memory, call pop()
|
||||
//
|
||||
~TPoolAllocator();
|
||||
|
||||
//
|
||||
// Call push() to establish a new place to pop memory too. Does not
|
||||
// have to be called to get things started.
|
||||
//
|
||||
void push();
|
||||
|
||||
//
|
||||
// Call pop() to free all memory allocated since the last call to push(),
|
||||
// or if no last call to push, frees all memory since first allocation.
|
||||
//
|
||||
void pop();
|
||||
|
||||
//
|
||||
// Call popAll() to free all memory allocated.
|
||||
//
|
||||
void popAll();
|
||||
|
||||
//
|
||||
// Call allocate() to actually acquire memory. Returns 0 if no memory
|
||||
// available, otherwise a properly aligned pointer to 'numBytes' of memory.
|
||||
//
|
||||
void* allocate(size_t numBytes);
|
||||
|
||||
//
|
||||
// There is no deallocate. The point of this class is that
|
||||
// deallocation can be skipped by the user of it, as the model
|
||||
// of use is to simultaneously deallocate everything at once
|
||||
// by calling pop(), and to not have to solve memory leak problems.
|
||||
//
|
||||
|
||||
protected:
|
||||
friend struct tHeader;
|
||||
|
||||
struct tHeader {
|
||||
tHeader(tHeader* nextPage, size_t pageCount) :
|
||||
#ifdef GUARD_BLOCKS
|
||||
lastAllocation(0),
|
||||
#endif
|
||||
nextPage(nextPage), pageCount(pageCount) { }
|
||||
|
||||
~tHeader() {
|
||||
#ifdef GUARD_BLOCKS
|
||||
if (lastAllocation)
|
||||
lastAllocation->checkAllocList();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef GUARD_BLOCKS
|
||||
TAllocation* lastAllocation;
|
||||
#endif
|
||||
tHeader* nextPage;
|
||||
size_t pageCount;
|
||||
};
|
||||
|
||||
struct tAllocState {
|
||||
size_t offset;
|
||||
tHeader* page;
|
||||
};
|
||||
typedef std::vector<tAllocState> tAllocStack;
|
||||
|
||||
// Track allocations if and only if we're using guard blocks
|
||||
#ifndef GUARD_BLOCKS
|
||||
void* initializeAllocation(tHeader*, unsigned char* memory, size_t) {
|
||||
#else
|
||||
void* initializeAllocation(tHeader* block, unsigned char* memory, size_t numBytes) {
|
||||
new(memory) TAllocation(numBytes, memory, block->lastAllocation);
|
||||
block->lastAllocation = reinterpret_cast<TAllocation*>(memory);
|
||||
#endif
|
||||
|
||||
// This is optimized entirely away if GUARD_BLOCKS is not defined.
|
||||
return TAllocation::offsetAllocation(memory);
|
||||
}
|
||||
|
||||
size_t pageSize; // granularity of allocation from the OS
|
||||
size_t alignment; // all returned allocations will be aligned at
|
||||
// this granularity, which will be a power of 2
|
||||
size_t alignmentMask;
|
||||
size_t headerSkip; // amount of memory to skip to make room for the
|
||||
// header (basically, size of header, rounded
|
||||
// up to make it aligned
|
||||
size_t currentPageOffset; // next offset in top of inUseList to allocate from
|
||||
tHeader* freeList; // list of popped memory
|
||||
tHeader* inUseList; // list of all memory currently being used
|
||||
tAllocStack stack; // stack of where to allocate from, to partition pool
|
||||
|
||||
int numCalls; // just an interesting statistic
|
||||
size_t totalBytes; // just an interesting statistic
|
||||
private:
|
||||
TPoolAllocator& operator=(const TPoolAllocator&); // don't allow assignment operator
|
||||
TPoolAllocator(const TPoolAllocator&); // don't allow default copy constructor
|
||||
};
|
||||
|
||||
//
|
||||
// There could potentially be many pools with pops happening at
|
||||
// different times. But a simple use is to have a global pop
|
||||
// with everyone using the same global allocator.
|
||||
//
|
||||
extern TPoolAllocator& GetThreadPoolAllocator();
|
||||
void SetThreadPoolAllocator(TPoolAllocator* poolAllocator);
|
||||
|
||||
//
|
||||
// This STL compatible allocator is intended to be used as the allocator
|
||||
// parameter to templatized STL containers, like vector and map.
|
||||
//
|
||||
// It will use the pools for allocation, and not
|
||||
// do any deallocation, but will still do destruction.
|
||||
//
|
||||
template<class T>
|
||||
class pool_allocator {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef T *pointer;
|
||||
typedef const T *const_pointer;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef T value_type;
|
||||
template<class Other>
|
||||
struct rebind {
|
||||
typedef pool_allocator<Other> other;
|
||||
};
|
||||
pointer address(reference x) const { return &x; }
|
||||
const_pointer address(const_reference x) const { return &x; }
|
||||
|
||||
pool_allocator() : allocator(GetThreadPoolAllocator()) { }
|
||||
pool_allocator(TPoolAllocator& a) : allocator(a) { }
|
||||
pool_allocator(const pool_allocator<T>& p) : allocator(p.allocator) { }
|
||||
|
||||
template<class Other>
|
||||
pool_allocator(const pool_allocator<Other>& p) : allocator(p.getAllocator()) { }
|
||||
|
||||
pointer allocate(size_type n) {
|
||||
return reinterpret_cast<pointer>(getAllocator().allocate(n * sizeof(T))); }
|
||||
pointer allocate(size_type n, const void*) {
|
||||
return reinterpret_cast<pointer>(getAllocator().allocate(n * sizeof(T))); }
|
||||
|
||||
void deallocate(void*, size_type) { }
|
||||
void deallocate(pointer, size_type) { }
|
||||
|
||||
pointer _Charalloc(size_t n) {
|
||||
return reinterpret_cast<pointer>(getAllocator().allocate(n)); }
|
||||
|
||||
void construct(pointer p, const T& val) { new ((void *)p) T(val); }
|
||||
void destroy(pointer p) { p->T::~T(); }
|
||||
|
||||
bool operator==(const pool_allocator& rhs) const { return &getAllocator() == &rhs.getAllocator(); }
|
||||
bool operator!=(const pool_allocator& rhs) const { return &getAllocator() != &rhs.getAllocator(); }
|
||||
|
||||
size_type max_size() const { return static_cast<size_type>(-1) / sizeof(T); }
|
||||
size_type max_size(int size) const { return static_cast<size_type>(-1) / size; }
|
||||
|
||||
TPoolAllocator& getAllocator() const { return allocator; }
|
||||
|
||||
pool_allocator select_on_container_copy_construction() const { return pool_allocator{}; }
|
||||
|
||||
protected:
|
||||
pool_allocator& operator=(const pool_allocator&) { return *this; }
|
||||
TPoolAllocator& allocator;
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _POOLALLOC_INCLUDED_
|
||||
@ -0,0 +1,159 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2013 LunarG, Inc.
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef _RESOURCE_LIMITS_INCLUDED_
|
||||
#define _RESOURCE_LIMITS_INCLUDED_
|
||||
|
||||
struct TLimits {
|
||||
bool nonInductiveForLoops;
|
||||
bool whileLoops;
|
||||
bool doWhileLoops;
|
||||
bool generalUniformIndexing;
|
||||
bool generalAttributeMatrixVectorIndexing;
|
||||
bool generalVaryingIndexing;
|
||||
bool generalSamplerIndexing;
|
||||
bool generalVariableIndexing;
|
||||
bool generalConstantMatrixVectorIndexing;
|
||||
};
|
||||
|
||||
struct TBuiltInResource {
|
||||
int maxLights;
|
||||
int maxClipPlanes;
|
||||
int maxTextureUnits;
|
||||
int maxTextureCoords;
|
||||
int maxVertexAttribs;
|
||||
int maxVertexUniformComponents;
|
||||
int maxVaryingFloats;
|
||||
int maxVertexTextureImageUnits;
|
||||
int maxCombinedTextureImageUnits;
|
||||
int maxTextureImageUnits;
|
||||
int maxFragmentUniformComponents;
|
||||
int maxDrawBuffers;
|
||||
int maxVertexUniformVectors;
|
||||
int maxVaryingVectors;
|
||||
int maxFragmentUniformVectors;
|
||||
int maxVertexOutputVectors;
|
||||
int maxFragmentInputVectors;
|
||||
int minProgramTexelOffset;
|
||||
int maxProgramTexelOffset;
|
||||
int maxClipDistances;
|
||||
int maxComputeWorkGroupCountX;
|
||||
int maxComputeWorkGroupCountY;
|
||||
int maxComputeWorkGroupCountZ;
|
||||
int maxComputeWorkGroupSizeX;
|
||||
int maxComputeWorkGroupSizeY;
|
||||
int maxComputeWorkGroupSizeZ;
|
||||
int maxComputeUniformComponents;
|
||||
int maxComputeTextureImageUnits;
|
||||
int maxComputeImageUniforms;
|
||||
int maxComputeAtomicCounters;
|
||||
int maxComputeAtomicCounterBuffers;
|
||||
int maxVaryingComponents;
|
||||
int maxVertexOutputComponents;
|
||||
int maxGeometryInputComponents;
|
||||
int maxGeometryOutputComponents;
|
||||
int maxFragmentInputComponents;
|
||||
int maxImageUnits;
|
||||
int maxCombinedImageUnitsAndFragmentOutputs;
|
||||
int maxCombinedShaderOutputResources;
|
||||
int maxImageSamples;
|
||||
int maxVertexImageUniforms;
|
||||
int maxTessControlImageUniforms;
|
||||
int maxTessEvaluationImageUniforms;
|
||||
int maxGeometryImageUniforms;
|
||||
int maxFragmentImageUniforms;
|
||||
int maxCombinedImageUniforms;
|
||||
int maxGeometryTextureImageUnits;
|
||||
int maxGeometryOutputVertices;
|
||||
int maxGeometryTotalOutputComponents;
|
||||
int maxGeometryUniformComponents;
|
||||
int maxGeometryVaryingComponents;
|
||||
int maxTessControlInputComponents;
|
||||
int maxTessControlOutputComponents;
|
||||
int maxTessControlTextureImageUnits;
|
||||
int maxTessControlUniformComponents;
|
||||
int maxTessControlTotalOutputComponents;
|
||||
int maxTessEvaluationInputComponents;
|
||||
int maxTessEvaluationOutputComponents;
|
||||
int maxTessEvaluationTextureImageUnits;
|
||||
int maxTessEvaluationUniformComponents;
|
||||
int maxTessPatchComponents;
|
||||
int maxPatchVertices;
|
||||
int maxTessGenLevel;
|
||||
int maxViewports;
|
||||
int maxVertexAtomicCounters;
|
||||
int maxTessControlAtomicCounters;
|
||||
int maxTessEvaluationAtomicCounters;
|
||||
int maxGeometryAtomicCounters;
|
||||
int maxFragmentAtomicCounters;
|
||||
int maxCombinedAtomicCounters;
|
||||
int maxAtomicCounterBindings;
|
||||
int maxVertexAtomicCounterBuffers;
|
||||
int maxTessControlAtomicCounterBuffers;
|
||||
int maxTessEvaluationAtomicCounterBuffers;
|
||||
int maxGeometryAtomicCounterBuffers;
|
||||
int maxFragmentAtomicCounterBuffers;
|
||||
int maxCombinedAtomicCounterBuffers;
|
||||
int maxAtomicCounterBufferSize;
|
||||
int maxTransformFeedbackBuffers;
|
||||
int maxTransformFeedbackInterleavedComponents;
|
||||
int maxCullDistances;
|
||||
int maxCombinedClipAndCullDistances;
|
||||
int maxSamples;
|
||||
int maxMeshOutputVerticesNV;
|
||||
int maxMeshOutputPrimitivesNV;
|
||||
int maxMeshWorkGroupSizeX_NV;
|
||||
int maxMeshWorkGroupSizeY_NV;
|
||||
int maxMeshWorkGroupSizeZ_NV;
|
||||
int maxTaskWorkGroupSizeX_NV;
|
||||
int maxTaskWorkGroupSizeY_NV;
|
||||
int maxTaskWorkGroupSizeZ_NV;
|
||||
int maxMeshViewCountNV;
|
||||
int maxMeshOutputVerticesEXT;
|
||||
int maxMeshOutputPrimitivesEXT;
|
||||
int maxMeshWorkGroupSizeX_EXT;
|
||||
int maxMeshWorkGroupSizeY_EXT;
|
||||
int maxMeshWorkGroupSizeZ_EXT;
|
||||
int maxTaskWorkGroupSizeX_EXT;
|
||||
int maxTaskWorkGroupSizeY_EXT;
|
||||
int maxTaskWorkGroupSizeZ_EXT;
|
||||
int maxMeshViewCountEXT;
|
||||
int maxDualSourceDrawBuffersEXT;
|
||||
|
||||
TLimits limits;
|
||||
};
|
||||
|
||||
#endif // _RESOURCE_LIMITS_INCLUDED_
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user