1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/include/GLSLANG/ShaderLang.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,446 @@ 1.4 +// 1.5 +// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. 1.6 +// Use of this source code is governed by a BSD-style license that can be 1.7 +// found in the LICENSE file. 1.8 +// 1.9 +#ifndef _COMPILER_INTERFACE_INCLUDED_ 1.10 +#define _COMPILER_INTERFACE_INCLUDED_ 1.11 + 1.12 +#if defined(COMPONENT_BUILD) 1.13 +#if defined(_WIN32) || defined(_WIN64) 1.14 + 1.15 +#if defined(COMPILER_IMPLEMENTATION) 1.16 +#define COMPILER_EXPORT __declspec(dllexport) 1.17 +#else 1.18 +#define COMPILER_EXPORT __declspec(dllimport) 1.19 +#endif // defined(COMPILER_IMPLEMENTATION) 1.20 + 1.21 +#else // defined(WIN32) 1.22 +#define COMPILER_EXPORT __attribute__((visibility("default"))) 1.23 +#endif 1.24 + 1.25 +#else // defined(COMPONENT_BUILD) 1.26 +#define COMPILER_EXPORT 1.27 +#endif 1.28 + 1.29 +#include "khrplatform.h" 1.30 +#include <stddef.h> 1.31 + 1.32 +// 1.33 +// This is the platform independent interface between an OGL driver 1.34 +// and the shading language compiler. 1.35 +// 1.36 + 1.37 +#ifdef __cplusplus 1.38 +extern "C" { 1.39 +#endif 1.40 + 1.41 +// Version number for shader translation API. 1.42 +// It is incremented everytime the API changes. 1.43 +#define ANGLE_SH_VERSION 110 1.44 + 1.45 +// 1.46 +// The names of the following enums have been derived by replacing GL prefix 1.47 +// with SH. For example, SH_INFO_LOG_LENGTH is equivalent to GL_INFO_LOG_LENGTH. 1.48 +// The enum values are also equal to the values of their GL counterpart. This 1.49 +// is done to make it easier for applications to use the shader library. 1.50 +// 1.51 +typedef enum { 1.52 + SH_FRAGMENT_SHADER = 0x8B30, 1.53 + SH_VERTEX_SHADER = 0x8B31 1.54 +} ShShaderType; 1.55 + 1.56 +typedef enum { 1.57 + SH_GLES2_SPEC = 0x8B40, 1.58 + SH_WEBGL_SPEC = 0x8B41, 1.59 + 1.60 + // The CSS Shaders spec is a subset of the WebGL spec. 1.61 + // 1.62 + // In both CSS vertex and fragment shaders, ANGLE: 1.63 + // (1) Reserves the "css_" prefix. 1.64 + // (2) Renames the main function to css_main. 1.65 + // (3) Disables the gl_MaxDrawBuffers built-in. 1.66 + // 1.67 + // In CSS fragment shaders, ANGLE: 1.68 + // (1) Disables the gl_FragColor built-in. 1.69 + // (2) Disables the gl_FragData built-in. 1.70 + // (3) Enables the css_MixColor built-in. 1.71 + // (4) Enables the css_ColorMatrix built-in. 1.72 + // 1.73 + // After passing a CSS shader through ANGLE, the browser is expected to append 1.74 + // a new main function to it. 1.75 + // This new main function will call the css_main function. 1.76 + // It may also perform additional operations like varying assignment, texture 1.77 + // access, and gl_FragColor assignment in order to implement the CSS Shaders 1.78 + // blend modes. 1.79 + // 1.80 + SH_CSS_SHADERS_SPEC = 0x8B42 1.81 +} ShShaderSpec; 1.82 + 1.83 +typedef enum { 1.84 + SH_ESSL_OUTPUT = 0x8B45, 1.85 + SH_GLSL_OUTPUT = 0x8B46, 1.86 + SH_HLSL_OUTPUT = 0x8B47, 1.87 + SH_HLSL9_OUTPUT = 0x8B47, 1.88 + SH_HLSL11_OUTPUT = 0x8B48 1.89 +} ShShaderOutput; 1.90 + 1.91 +typedef enum { 1.92 + SH_NONE = 0, 1.93 + SH_INT = 0x1404, 1.94 + SH_FLOAT = 0x1406, 1.95 + SH_FLOAT_VEC2 = 0x8B50, 1.96 + SH_FLOAT_VEC3 = 0x8B51, 1.97 + SH_FLOAT_VEC4 = 0x8B52, 1.98 + SH_INT_VEC2 = 0x8B53, 1.99 + SH_INT_VEC3 = 0x8B54, 1.100 + SH_INT_VEC4 = 0x8B55, 1.101 + SH_BOOL = 0x8B56, 1.102 + SH_BOOL_VEC2 = 0x8B57, 1.103 + SH_BOOL_VEC3 = 0x8B58, 1.104 + SH_BOOL_VEC4 = 0x8B59, 1.105 + SH_FLOAT_MAT2 = 0x8B5A, 1.106 + SH_FLOAT_MAT3 = 0x8B5B, 1.107 + SH_FLOAT_MAT4 = 0x8B5C, 1.108 + SH_SAMPLER_2D = 0x8B5E, 1.109 + SH_SAMPLER_CUBE = 0x8B60, 1.110 + SH_SAMPLER_2D_RECT_ARB = 0x8B63, 1.111 + SH_SAMPLER_EXTERNAL_OES = 0x8D66 1.112 +} ShDataType; 1.113 + 1.114 +typedef enum { 1.115 + SH_INFO_LOG_LENGTH = 0x8B84, 1.116 + SH_OBJECT_CODE_LENGTH = 0x8B88, // GL_SHADER_SOURCE_LENGTH 1.117 + SH_ACTIVE_UNIFORMS = 0x8B86, 1.118 + SH_ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87, 1.119 + SH_ACTIVE_ATTRIBUTES = 0x8B89, 1.120 + SH_ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A, 1.121 + SH_MAPPED_NAME_MAX_LENGTH = 0x6000, 1.122 + SH_NAME_MAX_LENGTH = 0x6001, 1.123 + SH_HASHED_NAME_MAX_LENGTH = 0x6002, 1.124 + SH_HASHED_NAMES_COUNT = 0x6003, 1.125 + SH_ACTIVE_UNIFORMS_ARRAY = 0x6004 1.126 +} ShShaderInfo; 1.127 + 1.128 +// Compile options. 1.129 +typedef enum { 1.130 + SH_VALIDATE = 0, 1.131 + SH_VALIDATE_LOOP_INDEXING = 0x0001, 1.132 + SH_INTERMEDIATE_TREE = 0x0002, 1.133 + SH_OBJECT_CODE = 0x0004, 1.134 + SH_ATTRIBUTES_UNIFORMS = 0x0008, 1.135 + SH_LINE_DIRECTIVES = 0x0010, 1.136 + SH_SOURCE_PATH = 0x0020, 1.137 + SH_MAP_LONG_VARIABLE_NAMES = 0x0040, 1.138 + SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX = 0x0080, 1.139 + 1.140 + // This is needed only as a workaround for certain OpenGL driver bugs. 1.141 + SH_EMULATE_BUILT_IN_FUNCTIONS = 0x0100, 1.142 + 1.143 + // This is an experimental flag to enforce restrictions that aim to prevent 1.144 + // timing attacks. 1.145 + // It generates compilation errors for shaders that could expose sensitive 1.146 + // texture information via the timing channel. 1.147 + // To use this flag, you must compile the shader under the WebGL spec 1.148 + // (using the SH_WEBGL_SPEC flag). 1.149 + SH_TIMING_RESTRICTIONS = 0x0200, 1.150 + 1.151 + // This flag prints the dependency graph that is used to enforce timing 1.152 + // restrictions on fragment shaders. 1.153 + // This flag only has an effect if all of the following are true: 1.154 + // - The shader spec is SH_WEBGL_SPEC. 1.155 + // - The compile options contain the SH_TIMING_RESTRICTIONS flag. 1.156 + // - The shader type is SH_FRAGMENT_SHADER. 1.157 + SH_DEPENDENCY_GRAPH = 0x0400, 1.158 + 1.159 + // Enforce the GLSL 1.017 Appendix A section 7 packing restrictions. 1.160 + SH_ENFORCE_PACKING_RESTRICTIONS = 0x0800, 1.161 + 1.162 + // This flag ensures all indirect (expression-based) array indexing 1.163 + // is clamped to the bounds of the array. This ensures, for example, 1.164 + // that you cannot read off the end of a uniform, whether an array 1.165 + // vec234, or mat234 type. The ShArrayIndexClampingStrategy enum, 1.166 + // specified in the ShBuiltInResources when constructing the 1.167 + // compiler, selects the strategy for the clamping implementation. 1.168 + SH_CLAMP_INDIRECT_ARRAY_BOUNDS = 0x1000, 1.169 + 1.170 + // This flag limits the complexity of an expression. 1.171 + SH_LIMIT_EXPRESSION_COMPLEXITY = 0x2000, 1.172 + 1.173 + // This flag limits the depth of the call stack. 1.174 + SH_LIMIT_CALL_STACK_DEPTH = 0x4000, 1.175 +} ShCompileOptions; 1.176 + 1.177 +// Defines alternate strategies for implementing array index clamping. 1.178 +typedef enum { 1.179 + // Use the clamp intrinsic for array index clamping. 1.180 + SH_CLAMP_WITH_CLAMP_INTRINSIC = 1, 1.181 + 1.182 + // Use a user-defined function for array index clamping. 1.183 + SH_CLAMP_WITH_USER_DEFINED_INT_CLAMP_FUNCTION 1.184 +} ShArrayIndexClampingStrategy; 1.185 + 1.186 +// 1.187 +// Driver must call this first, once, before doing any other 1.188 +// compiler operations. 1.189 +// If the function succeeds, the return value is nonzero, else zero. 1.190 +// 1.191 +COMPILER_EXPORT int ShInitialize(); 1.192 +// 1.193 +// Driver should call this at shutdown. 1.194 +// If the function succeeds, the return value is nonzero, else zero. 1.195 +// 1.196 +COMPILER_EXPORT int ShFinalize(); 1.197 + 1.198 +// The 64 bits hash function. The first parameter is the input string; the 1.199 +// second parameter is the string length. 1.200 +typedef khronos_uint64_t (*ShHashFunction64)(const char*, size_t); 1.201 + 1.202 +// 1.203 +// Implementation dependent built-in resources (constants and extensions). 1.204 +// The names for these resources has been obtained by stripping gl_/GL_. 1.205 +// 1.206 +typedef struct 1.207 +{ 1.208 + // Constants. 1.209 + int MaxVertexAttribs; 1.210 + int MaxVertexUniformVectors; 1.211 + int MaxVaryingVectors; 1.212 + int MaxVertexTextureImageUnits; 1.213 + int MaxCombinedTextureImageUnits; 1.214 + int MaxTextureImageUnits; 1.215 + int MaxFragmentUniformVectors; 1.216 + int MaxDrawBuffers; 1.217 + 1.218 + // Extensions. 1.219 + // Set to 1 to enable the extension, else 0. 1.220 + int OES_standard_derivatives; 1.221 + int OES_EGL_image_external; 1.222 + int ARB_texture_rectangle; 1.223 + int EXT_draw_buffers; 1.224 + int EXT_frag_depth; 1.225 + 1.226 + // Set to 1 if highp precision is supported in the fragment language. 1.227 + // Default is 0. 1.228 + int FragmentPrecisionHigh; 1.229 + 1.230 + // Name Hashing. 1.231 + // Set a 64 bit hash function to enable user-defined name hashing. 1.232 + // Default is NULL. 1.233 + ShHashFunction64 HashFunction; 1.234 + 1.235 + // Selects a strategy to use when implementing array index clamping. 1.236 + // Default is SH_CLAMP_WITH_CLAMP_INTRINSIC. 1.237 + ShArrayIndexClampingStrategy ArrayIndexClampingStrategy; 1.238 + 1.239 + // The maximum complexity an expression can be. 1.240 + int MaxExpressionComplexity; 1.241 + 1.242 + // The maximum depth a call stack can be. 1.243 + int MaxCallStackDepth; 1.244 +} ShBuiltInResources; 1.245 + 1.246 +// 1.247 +// Initialize built-in resources with minimum expected values. 1.248 +// 1.249 +COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources* resources); 1.250 + 1.251 +// 1.252 +// ShHandle held by but opaque to the driver. It is allocated, 1.253 +// managed, and de-allocated by the compiler. It's contents 1.254 +// are defined by and used by the compiler. 1.255 +// 1.256 +// If handle creation fails, 0 will be returned. 1.257 +// 1.258 +typedef void* ShHandle; 1.259 + 1.260 +// 1.261 +// Driver calls these to create and destroy compiler objects. 1.262 +// 1.263 +// Returns the handle of constructed compiler, null if the requested compiler is 1.264 +// not supported. 1.265 +// Parameters: 1.266 +// type: Specifies the type of shader - SH_FRAGMENT_SHADER or SH_VERTEX_SHADER. 1.267 +// spec: Specifies the language spec the compiler must conform to - 1.268 +// SH_GLES2_SPEC or SH_WEBGL_SPEC. 1.269 +// output: Specifies the output code type - SH_ESSL_OUTPUT, SH_GLSL_OUTPUT, 1.270 +// SH_HLSL9_OUTPUT or SH_HLSL11_OUTPUT. 1.271 +// resources: Specifies the built-in resources. 1.272 +COMPILER_EXPORT ShHandle ShConstructCompiler( 1.273 + ShShaderType type, 1.274 + ShShaderSpec spec, 1.275 + ShShaderOutput output, 1.276 + const ShBuiltInResources* resources); 1.277 +COMPILER_EXPORT void ShDestruct(ShHandle handle); 1.278 + 1.279 +// 1.280 +// Compiles the given shader source. 1.281 +// If the function succeeds, the return value is nonzero, else zero. 1.282 +// Parameters: 1.283 +// handle: Specifies the handle of compiler to be used. 1.284 +// shaderStrings: Specifies an array of pointers to null-terminated strings 1.285 +// containing the shader source code. 1.286 +// numStrings: Specifies the number of elements in shaderStrings array. 1.287 +// compileOptions: A mask containing the following parameters: 1.288 +// SH_VALIDATE: Validates shader to ensure that it conforms to the spec 1.289 +// specified during compiler construction. 1.290 +// SH_VALIDATE_LOOP_INDEXING: Validates loop and indexing in the shader to 1.291 +// ensure that they do not exceed the minimum 1.292 +// functionality mandated in GLSL 1.0 spec, 1.293 +// Appendix A, Section 4 and 5. 1.294 +// There is no need to specify this parameter when 1.295 +// compiling for WebGL - it is implied. 1.296 +// SH_INTERMEDIATE_TREE: Writes intermediate tree to info log. 1.297 +// Can be queried by calling ShGetInfoLog(). 1.298 +// SH_OBJECT_CODE: Translates intermediate tree to glsl or hlsl shader. 1.299 +// Can be queried by calling ShGetObjectCode(). 1.300 +// SH_ATTRIBUTES_UNIFORMS: Extracts attributes and uniforms. 1.301 +// Can be queried by calling ShGetActiveAttrib() and 1.302 +// ShGetActiveUniform(). 1.303 +// 1.304 +COMPILER_EXPORT int ShCompile( 1.305 + const ShHandle handle, 1.306 + const char* const shaderStrings[], 1.307 + size_t numStrings, 1.308 + int compileOptions 1.309 + ); 1.310 + 1.311 +// Returns a parameter from a compiled shader. 1.312 +// Parameters: 1.313 +// handle: Specifies the compiler 1.314 +// pname: Specifies the parameter to query. 1.315 +// The following parameters are defined: 1.316 +// SH_INFO_LOG_LENGTH: the number of characters in the information log 1.317 +// including the null termination character. 1.318 +// SH_OBJECT_CODE_LENGTH: the number of characters in the object code 1.319 +// including the null termination character. 1.320 +// SH_ACTIVE_ATTRIBUTES: the number of active attribute variables. 1.321 +// SH_ACTIVE_ATTRIBUTE_MAX_LENGTH: the length of the longest active attribute 1.322 +// variable name including the null 1.323 +// termination character. 1.324 +// SH_ACTIVE_UNIFORMS: the number of active uniform variables. 1.325 +// SH_ACTIVE_UNIFORM_MAX_LENGTH: the length of the longest active uniform 1.326 +// variable name including the null 1.327 +// termination character. 1.328 +// SH_MAPPED_NAME_MAX_LENGTH: the length of the mapped variable name including 1.329 +// the null termination character. 1.330 +// SH_NAME_MAX_LENGTH: the max length of a user-defined name including the 1.331 +// null termination character. 1.332 +// SH_HASHED_NAME_MAX_LENGTH: the max length of a hashed name including the 1.333 +// null termination character. 1.334 +// SH_HASHED_NAMES_COUNT: the number of hashed names from the latest compile. 1.335 +// 1.336 +// params: Requested parameter 1.337 +COMPILER_EXPORT void ShGetInfo(const ShHandle handle, 1.338 + ShShaderInfo pname, 1.339 + size_t* params); 1.340 + 1.341 +// Returns nul-terminated information log for a compiled shader. 1.342 +// Parameters: 1.343 +// handle: Specifies the compiler 1.344 +// infoLog: Specifies an array of characters that is used to return 1.345 +// the information log. It is assumed that infoLog has enough memory 1.346 +// to accomodate the information log. The size of the buffer required 1.347 +// to store the returned information log can be obtained by calling 1.348 +// ShGetInfo with SH_INFO_LOG_LENGTH. 1.349 +COMPILER_EXPORT void ShGetInfoLog(const ShHandle handle, char* infoLog); 1.350 + 1.351 +// Returns null-terminated object code for a compiled shader. 1.352 +// Parameters: 1.353 +// handle: Specifies the compiler 1.354 +// infoLog: Specifies an array of characters that is used to return 1.355 +// the object code. It is assumed that infoLog has enough memory to 1.356 +// accomodate the object code. The size of the buffer required to 1.357 +// store the returned object code can be obtained by calling 1.358 +// ShGetInfo with SH_OBJECT_CODE_LENGTH. 1.359 +COMPILER_EXPORT void ShGetObjectCode(const ShHandle handle, char* objCode); 1.360 + 1.361 +// Returns information about an active attribute variable. 1.362 +// Parameters: 1.363 +// handle: Specifies the compiler 1.364 +// index: Specifies the index of the attribute variable to be queried. 1.365 +// length: Returns the number of characters actually written in the string 1.366 +// indicated by name (excluding the null terminator) if a value other 1.367 +// than NULL is passed. 1.368 +// size: Returns the size of the attribute variable. 1.369 +// type: Returns the data type of the attribute variable. 1.370 +// name: Returns a null terminated string containing the name of the 1.371 +// attribute variable. It is assumed that name has enough memory to 1.372 +// accomodate the attribute variable name. The size of the buffer 1.373 +// required to store the attribute variable name can be obtained by 1.374 +// calling ShGetInfo with SH_ACTIVE_ATTRIBUTE_MAX_LENGTH. 1.375 +// mappedName: Returns a null terminated string containing the mapped name of 1.376 +// the attribute variable, It is assumed that mappedName has enough 1.377 +// memory (SH_MAPPED_NAME_MAX_LENGTH), or NULL if don't care 1.378 +// about the mapped name. If the name is not mapped, then name and 1.379 +// mappedName are the same. 1.380 +COMPILER_EXPORT void ShGetActiveAttrib(const ShHandle handle, 1.381 + int index, 1.382 + size_t* length, 1.383 + int* size, 1.384 + ShDataType* type, 1.385 + char* name, 1.386 + char* mappedName); 1.387 + 1.388 +// Returns information about an active uniform variable. 1.389 +// Parameters: 1.390 +// handle: Specifies the compiler 1.391 +// index: Specifies the index of the uniform variable to be queried. 1.392 +// length: Returns the number of characters actually written in the string 1.393 +// indicated by name (excluding the null terminator) if a value 1.394 +// other than NULL is passed. 1.395 +// size: Returns the size of the uniform variable. 1.396 +// type: Returns the data type of the uniform variable. 1.397 +// name: Returns a null terminated string containing the name of the 1.398 +// uniform variable. It is assumed that name has enough memory to 1.399 +// accomodate the uniform variable name. The size of the buffer required 1.400 +// to store the uniform variable name can be obtained by calling 1.401 +// ShGetInfo with SH_ACTIVE_UNIFORMS_MAX_LENGTH. 1.402 +// mappedName: Returns a null terminated string containing the mapped name of 1.403 +// the uniform variable, It is assumed that mappedName has enough 1.404 +// memory (SH_MAPPED_NAME_MAX_LENGTH), or NULL if don't care 1.405 +// about the mapped name. If the name is not mapped, then name and 1.406 +// mappedName are the same. 1.407 +COMPILER_EXPORT void ShGetActiveUniform(const ShHandle handle, 1.408 + int index, 1.409 + size_t* length, 1.410 + int* size, 1.411 + ShDataType* type, 1.412 + char* name, 1.413 + char* mappedName); 1.414 + 1.415 +// Returns information about a name hashing entry from the latest compile. 1.416 +// Parameters: 1.417 +// handle: Specifies the compiler 1.418 +// index: Specifies the index of the name hashing entry to be queried. 1.419 +// name: Returns a null terminated string containing the user defined name. 1.420 +// It is assumed that name has enough memory to accomodate the name. 1.421 +// The size of the buffer required to store the user defined name can 1.422 +// be obtained by calling ShGetInfo with SH_NAME_MAX_LENGTH. 1.423 +// hashedName: Returns a null terminated string containing the hashed name of 1.424 +// the uniform variable, It is assumed that hashedName has enough 1.425 +// memory to accomodate the name. The size of the buffer required 1.426 +// to store the name can be obtained by calling ShGetInfo with 1.427 +// SH_HASHED_NAME_MAX_LENGTH. 1.428 +COMPILER_EXPORT void ShGetNameHashingEntry(const ShHandle handle, 1.429 + int index, 1.430 + char* name, 1.431 + char* hashedName); 1.432 + 1.433 +// Returns a parameter from a compiled shader. 1.434 +// Parameters: 1.435 +// handle: Specifies the compiler 1.436 +// pname: Specifies the parameter to query. 1.437 +// The following parameters are defined: 1.438 +// SH_ACTIVE_UNIFORMS_ARRAY: an STL vector of active uniforms. Valid only for 1.439 +// HLSL output. 1.440 +// params: Requested parameter 1.441 +COMPILER_EXPORT void ShGetInfoPointer(const ShHandle handle, 1.442 + ShShaderInfo pname, 1.443 + void** params); 1.444 + 1.445 +#ifdef __cplusplus 1.446 +} 1.447 +#endif 1.448 + 1.449 +#endif // _COMPILER_INTERFACE_INCLUDED_