built iOS glslang and spirv-cross (#123)
This commit is contained in:
parent
87b0cd29d1
commit
f9ea45e081
|
|
@ -94,6 +94,42 @@ if(USE_SE_JSC)
|
|||
set(se_libs_name ${JAVASCRIPT_CORE_LIBRARY})
|
||||
endif()
|
||||
|
||||
add_library(glslang STATIC IMPORTED GLOBAL)
|
||||
set_target_properties(glslang PROPERTIES
|
||||
IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/libs/glslang/libglslang.a
|
||||
)
|
||||
add_library(OGLCompiler STATIC IMPORTED GLOBAL)
|
||||
set_target_properties(OGLCompiler PROPERTIES
|
||||
IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/libs/glslang/libOGLCompiler.a
|
||||
)
|
||||
add_library(OSDependent STATIC IMPORTED GLOBAL)
|
||||
set_target_properties(OSDependent PROPERTIES
|
||||
IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/libs/glslang/libOSDependent.a
|
||||
)
|
||||
add_library(SPIRV STATIC IMPORTED GLOBAL)
|
||||
set_target_properties(SPIRV PROPERTIES
|
||||
IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/libs/glslang/libSPIRV.a
|
||||
)
|
||||
add_library(glslang-default-resource-limits STATIC IMPORTED GLOBAL)
|
||||
set_target_properties(glslang-default-resource-limits PROPERTIES
|
||||
IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/libs/glslang/libglslang-default-resource-limits.a
|
||||
)
|
||||
set(glslang_libs_name glslang OGLCompiler OSDependent SPIRV glslang-default-resource-limits)
|
||||
|
||||
add_library(spirv-cross-core STATIC IMPORTED GLOBAL)
|
||||
set_target_properties(spirv-cross-core PROPERTIES
|
||||
IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/libs/spirv-cross/libspirv-cross-core.a
|
||||
)
|
||||
add_library(spirv-cross-msl STATIC IMPORTED GLOBAL)
|
||||
set_target_properties(spirv-cross-msl PROPERTIES
|
||||
IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/libs/spirv-cross/libspirv-cross-msl.a
|
||||
)
|
||||
add_library(spirv-cross-glsl STATIC IMPORTED GLOBAL)
|
||||
set_target_properties(spirv-cross-glsl PROPERTIES
|
||||
IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/libs/spirv-cross/libspirv-cross-glsl.a
|
||||
)
|
||||
set(spirv-cross_libs_name spirv-cross-core spirv-cross-glsl spirv-cross-msl)
|
||||
|
||||
list(APPEND CC_EXTERNAL_INCLUDES
|
||||
${CMAKE_CURRENT_LIST_DIR}/include
|
||||
)
|
||||
|
|
@ -106,4 +142,6 @@ list(APPEND CC_EXTERNAL_LIBS
|
|||
${se_libs_name}
|
||||
crypto
|
||||
ssl
|
||||
${glslang_libs_name}
|
||||
${spirv-cross_libs_name}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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_
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2020, Travis Fort
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef _STAND_ALONE_RESOURCE_LIMITS_C_INCLUDED_
|
||||
#define _STAND_ALONE_RESOURCE_LIMITS_C_INCLUDED_
|
||||
|
||||
#include "../glslang/Include/glslang_c_interface.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// 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.
|
||||
const glslang_resource_t* glslang_default_resource(void);
|
||||
|
||||
// Returns the DefaultTBuiltInResource as a human-readable string.
|
||||
// NOTE: User is responsible for freeing this string.
|
||||
const char* glslang_default_resource_string();
|
||||
|
||||
// Decodes the resource limits from |config| to |resources|.
|
||||
void glslang_decode_resource_limits(glslang_resource_t* resources, char* config);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _STAND_ALONE_RESOURCE_LIMITS_C_INCLUDED_
|
||||
|
|
@ -0,0 +1,571 @@
|
|||
//
|
||||
// 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,
|
||||
|
||||
// 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
|
||||
|
||||
EvqPayload,
|
||||
EvqPayloadIn,
|
||||
EvqHitAttr,
|
||||
EvqCallableData,
|
||||
EvqCallableDataIn,
|
||||
|
||||
// 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,
|
||||
|
||||
// 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,
|
||||
|
||||
EbvFragSizeEXT,
|
||||
EbvFragInvocationCountEXT,
|
||||
|
||||
EbvSecondaryFragDataEXT,
|
||||
EbvSecondaryFragColorEXT,
|
||||
|
||||
EbvViewportMaskNV,
|
||||
EbvSecondaryPositionNV,
|
||||
EbvSecondaryViewportMaskNV,
|
||||
EbvPositionPerViewNV,
|
||||
EbvViewportMaskPerViewNV,
|
||||
EbvFragFullyCoveredNV,
|
||||
EbvFragmentSizeNV,
|
||||
EbvInvocationsPerPixelNV,
|
||||
// ray tracing
|
||||
EbvLaunchId,
|
||||
EbvLaunchSize,
|
||||
EbvInstanceCustomIndex,
|
||||
EbvGeometryIndex,
|
||||
EbvWorldRayOrigin,
|
||||
EbvWorldRayDirection,
|
||||
EbvObjectRayOrigin,
|
||||
EbvObjectRayDirection,
|
||||
EbvRayTmin,
|
||||
EbvRayTmax,
|
||||
EbvHitT,
|
||||
EbvHitKind,
|
||||
EbvObjectToWorld,
|
||||
EbvObjectToWorld3x4,
|
||||
EbvWorldToObject,
|
||||
EbvWorldToObject3x4,
|
||||
EbvIncomingRayFlags,
|
||||
// barycentrics
|
||||
EbvBaryCoordNV,
|
||||
EbvBaryCoordNoPerspNV,
|
||||
// mesh shaders
|
||||
EbvTaskCountNV,
|
||||
EbvPrimitiveCountNV,
|
||||
EbvPrimitiveIndicesNV,
|
||||
EbvClipDistancePerViewNV,
|
||||
EbvCullDistancePerViewNV,
|
||||
EbvLayerPerViewNV,
|
||||
EbvMeshViewCountNV,
|
||||
EbvMeshViewIndicesNV,
|
||||
|
||||
// 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;
|
||||
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 EvqPayload: return "rayPayloadNV"; break;
|
||||
case EvqPayloadIn: return "rayPayloadInNV"; break;
|
||||
case EvqHitAttr: return "hitAttributeNV"; break;
|
||||
case EvqCallableData: return "callableDataNV"; break;
|
||||
case EvqCallableDataIn: return "callableDataInNV"; 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 EbvBaryCoordNV: return "BaryCoordNV";
|
||||
case EbvBaryCoordNoPerspNV: return "BaryCoordNoPerspNV";
|
||||
|
||||
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";
|
||||
|
||||
case EbvWarpsPerSM: return "WarpsPerSMNV";
|
||||
case EbvSMCount: return "SMCountNV";
|
||||
case EbvWarpID: return "WarpIDNV";
|
||||
case EbvSMID: return "SMIDNV";
|
||||
|
||||
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_
|
||||
|
|
@ -0,0 +1,292 @@
|
|||
//
|
||||
// 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_
|
||||
|
||||
|
||||
#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
|
||||
#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 <set>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#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> > > {
|
||||
};
|
||||
|
||||
//
|
||||
// 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
|
||||
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));
|
||||
}
|
||||
|
||||
} // 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_
|
||||
|
|
@ -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_
|
||||
|
|
@ -0,0 +1,316 @@
|
|||
//
|
||||
// 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; }
|
||||
|
||||
protected:
|
||||
pool_allocator& operator=(const pool_allocator&) { return *this; }
|
||||
TPoolAllocator& allocator;
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _POOLALLOC_INCLUDED_
|
||||
|
|
@ -0,0 +1,150 @@
|
|||
//
|
||||
// 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 maxDualSourceDrawBuffersEXT;
|
||||
|
||||
TLimits limits;
|
||||
};
|
||||
|
||||
#endif // _RESOURCE_LIMITS_INCLUDED_
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
//
|
||||
// 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 _SHHANDLE_INCLUDED_
|
||||
#define _SHHANDLE_INCLUDED_
|
||||
|
||||
//
|
||||
// Machine independent part of the compiler private objects
|
||||
// sent as ShHandle to the driver.
|
||||
//
|
||||
// This should not be included by driver code.
|
||||
//
|
||||
|
||||
#define SH_EXPORTING
|
||||
#include "../Public/ShaderLang.h"
|
||||
#include "../MachineIndependent/Versions.h"
|
||||
#include "InfoSink.h"
|
||||
|
||||
class TCompiler;
|
||||
class TLinker;
|
||||
class TUniformMap;
|
||||
|
||||
//
|
||||
// The base class used to back handles returned to the driver.
|
||||
//
|
||||
class TShHandleBase {
|
||||
public:
|
||||
TShHandleBase() { pool = new glslang::TPoolAllocator; }
|
||||
virtual ~TShHandleBase() { delete pool; }
|
||||
virtual TCompiler* getAsCompiler() { return 0; }
|
||||
virtual TLinker* getAsLinker() { return 0; }
|
||||
virtual TUniformMap* getAsUniformMap() { return 0; }
|
||||
virtual glslang::TPoolAllocator* getPool() const { return pool; }
|
||||
private:
|
||||
glslang::TPoolAllocator* pool;
|
||||
};
|
||||
|
||||
//
|
||||
// The base class for the machine dependent linker to derive from
|
||||
// for managing where uniforms live.
|
||||
//
|
||||
class TUniformMap : public TShHandleBase {
|
||||
public:
|
||||
TUniformMap() { }
|
||||
virtual ~TUniformMap() { }
|
||||
virtual TUniformMap* getAsUniformMap() { return this; }
|
||||
virtual int getLocation(const char* name) = 0;
|
||||
virtual TInfoSink& getInfoSink() { return infoSink; }
|
||||
TInfoSink infoSink;
|
||||
};
|
||||
|
||||
class TIntermNode;
|
||||
|
||||
//
|
||||
// The base class for the machine dependent compiler to derive from
|
||||
// for managing object code from the compile.
|
||||
//
|
||||
class TCompiler : public TShHandleBase {
|
||||
public:
|
||||
TCompiler(EShLanguage l, TInfoSink& sink) : infoSink(sink) , language(l), haveValidObjectCode(false) { }
|
||||
virtual ~TCompiler() { }
|
||||
EShLanguage getLanguage() { return language; }
|
||||
virtual TInfoSink& getInfoSink() { return infoSink; }
|
||||
|
||||
virtual bool compile(TIntermNode* root, int version = 0, EProfile profile = ENoProfile) = 0;
|
||||
|
||||
virtual TCompiler* getAsCompiler() { return this; }
|
||||
virtual bool linkable() { return haveValidObjectCode; }
|
||||
|
||||
TInfoSink& infoSink;
|
||||
protected:
|
||||
TCompiler& operator=(TCompiler&);
|
||||
|
||||
EShLanguage language;
|
||||
bool haveValidObjectCode;
|
||||
};
|
||||
|
||||
//
|
||||
// Link operations are based on a list of compile results...
|
||||
//
|
||||
typedef glslang::TVector<TCompiler*> TCompilerList;
|
||||
typedef glslang::TVector<TShHandleBase*> THandleList;
|
||||
|
||||
//
|
||||
// The base class for the machine dependent linker to derive from
|
||||
// to manage the resulting executable.
|
||||
//
|
||||
|
||||
class TLinker : public TShHandleBase {
|
||||
public:
|
||||
TLinker(EShExecutable e, TInfoSink& iSink) :
|
||||
infoSink(iSink),
|
||||
executable(e),
|
||||
haveReturnableObjectCode(false),
|
||||
appAttributeBindings(0),
|
||||
fixedAttributeBindings(0),
|
||||
excludedAttributes(0),
|
||||
excludedCount(0),
|
||||
uniformBindings(0) { }
|
||||
virtual TLinker* getAsLinker() { return this; }
|
||||
virtual ~TLinker() { }
|
||||
virtual bool link(TCompilerList&, TUniformMap*) = 0;
|
||||
virtual bool link(THandleList&) { return false; }
|
||||
virtual void setAppAttributeBindings(const ShBindingTable* t) { appAttributeBindings = t; }
|
||||
virtual void setFixedAttributeBindings(const ShBindingTable* t) { fixedAttributeBindings = t; }
|
||||
virtual void getAttributeBindings(ShBindingTable const **t) const = 0;
|
||||
virtual void setExcludedAttributes(const int* attributes, int count) { excludedAttributes = attributes; excludedCount = count; }
|
||||
virtual ShBindingTable* getUniformBindings() const { return uniformBindings; }
|
||||
virtual const void* getObjectCode() const { return 0; } // a real compiler would be returning object code here
|
||||
virtual TInfoSink& getInfoSink() { return infoSink; }
|
||||
TInfoSink& infoSink;
|
||||
protected:
|
||||
TLinker& operator=(TLinker&);
|
||||
EShExecutable executable;
|
||||
bool haveReturnableObjectCode; // true when objectCode is acceptable to send to driver
|
||||
|
||||
const ShBindingTable* appAttributeBindings;
|
||||
const ShBindingTable* fixedAttributeBindings;
|
||||
const int* excludedAttributes;
|
||||
int excludedCount;
|
||||
ShBindingTable* uniformBindings; // created by the linker
|
||||
};
|
||||
|
||||
//
|
||||
// This is the interface between the machine independent code
|
||||
// and the machine dependent code.
|
||||
//
|
||||
// The machine dependent code should derive from the classes
|
||||
// above. Then Construct*() and Delete*() will create and
|
||||
// destroy the machine dependent objects, which contain the
|
||||
// above machine independent information.
|
||||
//
|
||||
TCompiler* ConstructCompiler(EShLanguage, int);
|
||||
|
||||
TShHandleBase* ConstructLinker(EShExecutable, int);
|
||||
TShHandleBase* ConstructBindings();
|
||||
void DeleteLinker(TShHandleBase*);
|
||||
void DeleteBindingList(TShHandleBase* bindingList);
|
||||
|
||||
TUniformMap* ConstructUniformMap();
|
||||
void DeleteCompiler(TCompiler*);
|
||||
|
||||
void DeleteUniformMap(TUniformMap*);
|
||||
|
||||
#endif // _SHHANDLE_INCLUDED_
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,341 @@
|
|||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
//
|
||||
// Implement types for tracking GLSL arrays, arrays of arrays, etc.
|
||||
//
|
||||
|
||||
#ifndef _ARRAYS_INCLUDED
|
||||
#define _ARRAYS_INCLUDED
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace glslang {
|
||||
|
||||
// This is used to mean there is no size yet (unsized), it is waiting to get a size from somewhere else.
|
||||
const int UnsizedArraySize = 0;
|
||||
|
||||
class TIntermTyped;
|
||||
extern bool SameSpecializationConstants(TIntermTyped*, TIntermTyped*);
|
||||
|
||||
// Specialization constants need both a nominal size and a node that defines
|
||||
// the specialization constant being used. Array types are the same when their
|
||||
// size and specialization constant nodes are the same.
|
||||
struct TArraySize {
|
||||
unsigned int size;
|
||||
TIntermTyped* node; // nullptr means no specialization constant node
|
||||
bool operator==(const TArraySize& rhs) const
|
||||
{
|
||||
if (size != rhs.size)
|
||||
return false;
|
||||
if (node == nullptr || rhs.node == nullptr)
|
||||
return node == rhs.node;
|
||||
|
||||
return SameSpecializationConstants(node, rhs.node);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// TSmallArrayVector is used as the container for the set of sizes in TArraySizes.
|
||||
// It has generic-container semantics, while TArraySizes has array-of-array semantics.
|
||||
// That is, TSmallArrayVector should be more focused on mechanism and TArraySizes on policy.
|
||||
//
|
||||
struct TSmallArrayVector {
|
||||
//
|
||||
// TODO: memory: TSmallArrayVector is intended to be smaller.
|
||||
// Almost all arrays could be handled by two sizes each fitting
|
||||
// in 16 bits, needing a real vector only in the cases where there
|
||||
// are more than 3 sizes or a size needing more than 16 bits.
|
||||
//
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
|
||||
TSmallArrayVector() : sizes(nullptr) { }
|
||||
virtual ~TSmallArrayVector() { dealloc(); }
|
||||
|
||||
// For breaking into two non-shared copies, independently modifiable.
|
||||
TSmallArrayVector& operator=(const TSmallArrayVector& from)
|
||||
{
|
||||
if (from.sizes == nullptr)
|
||||
sizes = nullptr;
|
||||
else {
|
||||
alloc();
|
||||
*sizes = *from.sizes;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
int size() const
|
||||
{
|
||||
if (sizes == nullptr)
|
||||
return 0;
|
||||
return (int)sizes->size();
|
||||
}
|
||||
|
||||
unsigned int frontSize() const
|
||||
{
|
||||
assert(sizes != nullptr && sizes->size() > 0);
|
||||
return sizes->front().size;
|
||||
}
|
||||
|
||||
TIntermTyped* frontNode() const
|
||||
{
|
||||
assert(sizes != nullptr && sizes->size() > 0);
|
||||
return sizes->front().node;
|
||||
}
|
||||
|
||||
void changeFront(unsigned int s)
|
||||
{
|
||||
assert(sizes != nullptr);
|
||||
// this should only happen for implicitly sized arrays, not specialization constants
|
||||
assert(sizes->front().node == nullptr);
|
||||
sizes->front().size = s;
|
||||
}
|
||||
|
||||
void push_back(unsigned int e, TIntermTyped* n)
|
||||
{
|
||||
alloc();
|
||||
TArraySize pair = { e, n };
|
||||
sizes->push_back(pair);
|
||||
}
|
||||
|
||||
void push_back(const TSmallArrayVector& newDims)
|
||||
{
|
||||
alloc();
|
||||
sizes->insert(sizes->end(), newDims.sizes->begin(), newDims.sizes->end());
|
||||
}
|
||||
|
||||
void pop_front()
|
||||
{
|
||||
assert(sizes != nullptr && sizes->size() > 0);
|
||||
if (sizes->size() == 1)
|
||||
dealloc();
|
||||
else
|
||||
sizes->erase(sizes->begin());
|
||||
}
|
||||
|
||||
// 'this' should currently not be holding anything, and copyNonFront
|
||||
// will make it hold a copy of all but the first element of rhs.
|
||||
// (This would be useful for making a type that is dereferenced by
|
||||
// one dimension.)
|
||||
void copyNonFront(const TSmallArrayVector& rhs)
|
||||
{
|
||||
assert(sizes == nullptr);
|
||||
if (rhs.size() > 1) {
|
||||
alloc();
|
||||
sizes->insert(sizes->begin(), rhs.sizes->begin() + 1, rhs.sizes->end());
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int getDimSize(int i) const
|
||||
{
|
||||
assert(sizes != nullptr && (int)sizes->size() > i);
|
||||
return (*sizes)[i].size;
|
||||
}
|
||||
|
||||
void setDimSize(int i, unsigned int size) const
|
||||
{
|
||||
assert(sizes != nullptr && (int)sizes->size() > i);
|
||||
assert((*sizes)[i].node == nullptr);
|
||||
(*sizes)[i].size = size;
|
||||
}
|
||||
|
||||
TIntermTyped* getDimNode(int i) const
|
||||
{
|
||||
assert(sizes != nullptr && (int)sizes->size() > i);
|
||||
return (*sizes)[i].node;
|
||||
}
|
||||
|
||||
bool operator==(const TSmallArrayVector& rhs) const
|
||||
{
|
||||
if (sizes == nullptr && rhs.sizes == nullptr)
|
||||
return true;
|
||||
if (sizes == nullptr || rhs.sizes == nullptr)
|
||||
return false;
|
||||
return *sizes == *rhs.sizes;
|
||||
}
|
||||
bool operator!=(const TSmallArrayVector& rhs) const { return ! operator==(rhs); }
|
||||
|
||||
protected:
|
||||
TSmallArrayVector(const TSmallArrayVector&);
|
||||
|
||||
void alloc()
|
||||
{
|
||||
if (sizes == nullptr)
|
||||
sizes = new TVector<TArraySize>;
|
||||
}
|
||||
void dealloc()
|
||||
{
|
||||
delete sizes;
|
||||
sizes = nullptr;
|
||||
}
|
||||
|
||||
TVector<TArraySize>* sizes; // will either hold such a pointer, or in the future, hold the two array sizes
|
||||
};
|
||||
|
||||
//
|
||||
// Represent an array, or array of arrays, to arbitrary depth. This is not
|
||||
// done through a hierarchy of types in a type tree, rather all contiguous arrayness
|
||||
// in the type hierarchy is localized into this single cumulative object.
|
||||
//
|
||||
// The arrayness in TTtype is a pointer, so that it can be non-allocated and zero
|
||||
// for the vast majority of types that are non-array types.
|
||||
//
|
||||
// Order Policy: these are all identical:
|
||||
// - left to right order within a contiguous set of ...[..][..][..]... in the source language
|
||||
// - index order 0, 1, 2, ... within the 'sizes' member below
|
||||
// - outer-most to inner-most
|
||||
//
|
||||
struct TArraySizes {
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
|
||||
TArraySizes() : implicitArraySize(1), variablyIndexed(false) { }
|
||||
|
||||
// For breaking into two non-shared copies, independently modifiable.
|
||||
TArraySizes& operator=(const TArraySizes& from)
|
||||
{
|
||||
implicitArraySize = from.implicitArraySize;
|
||||
variablyIndexed = from.variablyIndexed;
|
||||
sizes = from.sizes;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// translate from array-of-array semantics to container semantics
|
||||
int getNumDims() const { return sizes.size(); }
|
||||
int getDimSize(int dim) const { return sizes.getDimSize(dim); }
|
||||
TIntermTyped* getDimNode(int dim) const { return sizes.getDimNode(dim); }
|
||||
void setDimSize(int dim, int size) { sizes.setDimSize(dim, size); }
|
||||
int getOuterSize() const { return sizes.frontSize(); }
|
||||
TIntermTyped* getOuterNode() const { return sizes.frontNode(); }
|
||||
int getCumulativeSize() const
|
||||
{
|
||||
int size = 1;
|
||||
for (int d = 0; d < sizes.size(); ++d) {
|
||||
// this only makes sense in paths that have a known array size
|
||||
assert(sizes.getDimSize(d) != UnsizedArraySize);
|
||||
size *= sizes.getDimSize(d);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
void addInnerSize() { addInnerSize((unsigned)UnsizedArraySize); }
|
||||
void addInnerSize(int s) { addInnerSize((unsigned)s, nullptr); }
|
||||
void addInnerSize(int s, TIntermTyped* n) { sizes.push_back((unsigned)s, n); }
|
||||
void addInnerSize(TArraySize pair) {
|
||||
sizes.push_back(pair.size, pair.node);
|
||||
}
|
||||
void addInnerSizes(const TArraySizes& s) { sizes.push_back(s.sizes); }
|
||||
void changeOuterSize(int s) { sizes.changeFront((unsigned)s); }
|
||||
int getImplicitSize() const { return implicitArraySize; }
|
||||
void updateImplicitSize(int s) { implicitArraySize = std::max(implicitArraySize, s); }
|
||||
bool isInnerUnsized() const
|
||||
{
|
||||
for (int d = 1; d < sizes.size(); ++d) {
|
||||
if (sizes.getDimSize(d) == (unsigned)UnsizedArraySize)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool clearInnerUnsized()
|
||||
{
|
||||
for (int d = 1; d < sizes.size(); ++d) {
|
||||
if (sizes.getDimSize(d) == (unsigned)UnsizedArraySize)
|
||||
setDimSize(d, 1);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool isInnerSpecialization() const
|
||||
{
|
||||
for (int d = 1; d < sizes.size(); ++d) {
|
||||
if (sizes.getDimNode(d) != nullptr)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool isOuterSpecialization()
|
||||
{
|
||||
return sizes.getDimNode(0) != nullptr;
|
||||
}
|
||||
|
||||
bool hasUnsized() const { return getOuterSize() == UnsizedArraySize || isInnerUnsized(); }
|
||||
bool isSized() const { return getOuterSize() != UnsizedArraySize; }
|
||||
void dereference() { sizes.pop_front(); }
|
||||
void copyDereferenced(const TArraySizes& rhs)
|
||||
{
|
||||
assert(sizes.size() == 0);
|
||||
if (rhs.sizes.size() > 1)
|
||||
sizes.copyNonFront(rhs.sizes);
|
||||
}
|
||||
|
||||
bool sameInnerArrayness(const TArraySizes& rhs) const
|
||||
{
|
||||
if (sizes.size() != rhs.sizes.size())
|
||||
return false;
|
||||
|
||||
for (int d = 1; d < sizes.size(); ++d) {
|
||||
if (sizes.getDimSize(d) != rhs.sizes.getDimSize(d) ||
|
||||
sizes.getDimNode(d) != rhs.sizes.getDimNode(d))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void setVariablyIndexed() { variablyIndexed = true; }
|
||||
bool isVariablyIndexed() const { return variablyIndexed; }
|
||||
|
||||
bool operator==(const TArraySizes& rhs) const { return sizes == rhs.sizes; }
|
||||
bool operator!=(const TArraySizes& rhs) const { return sizes != rhs.sizes; }
|
||||
|
||||
protected:
|
||||
TSmallArrayVector sizes;
|
||||
|
||||
TArraySizes(const TArraySizes&);
|
||||
|
||||
// For tracking maximum referenced compile-time constant index.
|
||||
// Applies only to the outer-most dimension. Potentially becomes
|
||||
// the implicit size of the array, if not variably indexed and
|
||||
// otherwise legal.
|
||||
int implicitArraySize;
|
||||
bool variablyIndexed; // true if array is indexed with a non compile-time constant
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _ARRAYS_INCLUDED_
|
||||
|
|
@ -0,0 +1,233 @@
|
|||
/**
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef GLSLANG_C_IFACE_H_INCLUDED
|
||||
#define GLSLANG_C_IFACE_H_INCLUDED
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "glslang_c_shader_types.h"
|
||||
|
||||
typedef struct glslang_shader_s glslang_shader_t;
|
||||
typedef struct glslang_program_s glslang_program_t;
|
||||
|
||||
/* TLimits counterpart */
|
||||
typedef struct glslang_limits_s {
|
||||
bool non_inductive_for_loops;
|
||||
bool while_loops;
|
||||
bool do_while_loops;
|
||||
bool general_uniform_indexing;
|
||||
bool general_attribute_matrix_vector_indexing;
|
||||
bool general_varying_indexing;
|
||||
bool general_sampler_indexing;
|
||||
bool general_variable_indexing;
|
||||
bool general_constant_matrix_vector_indexing;
|
||||
} glslang_limits_t;
|
||||
|
||||
/* TBuiltInResource counterpart */
|
||||
typedef struct glslang_resource_s {
|
||||
int max_lights;
|
||||
int max_clip_planes;
|
||||
int max_texture_units;
|
||||
int max_texture_coords;
|
||||
int max_vertex_attribs;
|
||||
int max_vertex_uniform_components;
|
||||
int max_varying_floats;
|
||||
int max_vertex_texture_image_units;
|
||||
int max_combined_texture_image_units;
|
||||
int max_texture_image_units;
|
||||
int max_fragment_uniform_components;
|
||||
int max_draw_buffers;
|
||||
int max_vertex_uniform_vectors;
|
||||
int max_varying_vectors;
|
||||
int max_fragment_uniform_vectors;
|
||||
int max_vertex_output_vectors;
|
||||
int max_fragment_input_vectors;
|
||||
int min_program_texel_offset;
|
||||
int max_program_texel_offset;
|
||||
int max_clip_distances;
|
||||
int max_compute_work_group_count_x;
|
||||
int max_compute_work_group_count_y;
|
||||
int max_compute_work_group_count_z;
|
||||
int max_compute_work_group_size_x;
|
||||
int max_compute_work_group_size_y;
|
||||
int max_compute_work_group_size_z;
|
||||
int max_compute_uniform_components;
|
||||
int max_compute_texture_image_units;
|
||||
int max_compute_image_uniforms;
|
||||
int max_compute_atomic_counters;
|
||||
int max_compute_atomic_counter_buffers;
|
||||
int max_varying_components;
|
||||
int max_vertex_output_components;
|
||||
int max_geometry_input_components;
|
||||
int max_geometry_output_components;
|
||||
int max_fragment_input_components;
|
||||
int max_image_units;
|
||||
int max_combined_image_units_and_fragment_outputs;
|
||||
int max_combined_shader_output_resources;
|
||||
int max_image_samples;
|
||||
int max_vertex_image_uniforms;
|
||||
int max_tess_control_image_uniforms;
|
||||
int max_tess_evaluation_image_uniforms;
|
||||
int max_geometry_image_uniforms;
|
||||
int max_fragment_image_uniforms;
|
||||
int max_combined_image_uniforms;
|
||||
int max_geometry_texture_image_units;
|
||||
int max_geometry_output_vertices;
|
||||
int max_geometry_total_output_components;
|
||||
int max_geometry_uniform_components;
|
||||
int max_geometry_varying_components;
|
||||
int max_tess_control_input_components;
|
||||
int max_tess_control_output_components;
|
||||
int max_tess_control_texture_image_units;
|
||||
int max_tess_control_uniform_components;
|
||||
int max_tess_control_total_output_components;
|
||||
int max_tess_evaluation_input_components;
|
||||
int max_tess_evaluation_output_components;
|
||||
int max_tess_evaluation_texture_image_units;
|
||||
int max_tess_evaluation_uniform_components;
|
||||
int max_tess_patch_components;
|
||||
int max_patch_vertices;
|
||||
int max_tess_gen_level;
|
||||
int max_viewports;
|
||||
int max_vertex_atomic_counters;
|
||||
int max_tess_control_atomic_counters;
|
||||
int max_tess_evaluation_atomic_counters;
|
||||
int max_geometry_atomic_counters;
|
||||
int max_fragment_atomic_counters;
|
||||
int max_combined_atomic_counters;
|
||||
int max_atomic_counter_bindings;
|
||||
int max_vertex_atomic_counter_buffers;
|
||||
int max_tess_control_atomic_counter_buffers;
|
||||
int max_tess_evaluation_atomic_counter_buffers;
|
||||
int max_geometry_atomic_counter_buffers;
|
||||
int max_fragment_atomic_counter_buffers;
|
||||
int max_combined_atomic_counter_buffers;
|
||||
int max_atomic_counter_buffer_size;
|
||||
int max_transform_feedback_buffers;
|
||||
int max_transform_feedback_interleaved_components;
|
||||
int max_cull_distances;
|
||||
int max_combined_clip_and_cull_distances;
|
||||
int max_samples;
|
||||
int max_mesh_output_vertices_nv;
|
||||
int max_mesh_output_primitives_nv;
|
||||
int max_mesh_work_group_size_x_nv;
|
||||
int max_mesh_work_group_size_y_nv;
|
||||
int max_mesh_work_group_size_z_nv;
|
||||
int max_task_work_group_size_x_nv;
|
||||
int max_task_work_group_size_y_nv;
|
||||
int max_task_work_group_size_z_nv;
|
||||
int max_mesh_view_count_nv;
|
||||
int maxDualSourceDrawBuffersEXT;
|
||||
|
||||
glslang_limits_t limits;
|
||||
} glslang_resource_t;
|
||||
|
||||
typedef struct glslang_input_s {
|
||||
glslang_source_t language;
|
||||
glslang_stage_t stage;
|
||||
glslang_client_t client;
|
||||
glslang_target_client_version_t client_version;
|
||||
glslang_target_language_t target_language;
|
||||
glslang_target_language_version_t target_language_version;
|
||||
/** Shader source code */
|
||||
const char* code;
|
||||
int default_version;
|
||||
glslang_profile_t default_profile;
|
||||
int force_default_version_and_profile;
|
||||
int forward_compatible;
|
||||
glslang_messages_t messages;
|
||||
const glslang_resource_t* resource;
|
||||
} glslang_input_t;
|
||||
|
||||
/* Inclusion result structure allocated by C include_local/include_system callbacks */
|
||||
typedef struct glsl_include_result_s {
|
||||
/* Header file name or NULL if inclusion failed */
|
||||
const char* header_name;
|
||||
|
||||
/* Header contents or NULL */
|
||||
const char* header_data;
|
||||
size_t header_length;
|
||||
|
||||
} glsl_include_result_t;
|
||||
|
||||
/* Callback for local file inclusion */
|
||||
typedef glsl_include_result_t* (*glsl_include_local_func)(void* ctx, const char* header_name, const char* includer_name,
|
||||
size_t include_depth);
|
||||
|
||||
/* Callback for system file inclusion */
|
||||
typedef glsl_include_result_t* (*glsl_include_system_func)(void* ctx, const char* header_name,
|
||||
const char* includer_name, size_t include_depth);
|
||||
|
||||
/* Callback for include result destruction */
|
||||
typedef int (*glsl_free_include_result_func)(void* ctx, glsl_include_result_t* result);
|
||||
|
||||
/* Collection of callbacks for GLSL preprocessor */
|
||||
typedef struct glsl_include_callbacks_s {
|
||||
glsl_include_system_func include_system;
|
||||
glsl_include_local_func include_local;
|
||||
glsl_free_include_result_func free_include_result;
|
||||
} glsl_include_callbacks_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int glslang_initialize_process();
|
||||
void glslang_finalize_process();
|
||||
|
||||
glslang_shader_t* glslang_shader_create(const glslang_input_t* input);
|
||||
void glslang_shader_delete(glslang_shader_t* shader);
|
||||
int glslang_shader_preprocess(glslang_shader_t* shader, const glslang_input_t* input);
|
||||
int glslang_shader_parse(glslang_shader_t* shader, const glslang_input_t* input);
|
||||
const char* glslang_shader_get_preprocessed_code(glslang_shader_t* shader);
|
||||
const char* glslang_shader_get_info_log(glslang_shader_t* shader);
|
||||
const char* glslang_shader_get_info_debug_log(glslang_shader_t* shader);
|
||||
|
||||
glslang_program_t* glslang_program_create();
|
||||
void glslang_program_delete(glslang_program_t* program);
|
||||
void glslang_program_add_shader(glslang_program_t* program, glslang_shader_t* shader);
|
||||
int glslang_program_link(glslang_program_t* program, int messages); // glslang_messages_t
|
||||
void glslang_program_SPIRV_generate(glslang_program_t* program, glslang_stage_t stage);
|
||||
size_t glslang_program_SPIRV_get_size(glslang_program_t* program);
|
||||
void glslang_program_SPIRV_get(glslang_program_t* program, unsigned int*);
|
||||
unsigned int* glslang_program_SPIRV_get_ptr(glslang_program_t* program);
|
||||
const char* glslang_program_SPIRV_get_messages(glslang_program_t* program);
|
||||
const char* glslang_program_get_info_log(glslang_program_t* program);
|
||||
const char* glslang_program_get_info_debug_log(glslang_program_t* program);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* #ifdef GLSLANG_C_IFACE_INCLUDED */
|
||||
|
|
@ -0,0 +1,185 @@
|
|||
/**
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef C_SHADER_TYPES_H_INCLUDED
|
||||
#define C_SHADER_TYPES_H_INCLUDED
|
||||
|
||||
#define LAST_ELEMENT_MARKER(x) x
|
||||
|
||||
/* EShLanguage counterpart */
|
||||
typedef enum {
|
||||
GLSLANG_STAGE_VERTEX,
|
||||
GLSLANG_STAGE_TESSCONTROL,
|
||||
GLSLANG_STAGE_TESSEVALUATION,
|
||||
GLSLANG_STAGE_GEOMETRY,
|
||||
GLSLANG_STAGE_FRAGMENT,
|
||||
GLSLANG_STAGE_COMPUTE,
|
||||
GLSLANG_STAGE_RAYGEN_NV,
|
||||
GLSLANG_STAGE_INTERSECT_NV,
|
||||
GLSLANG_STAGE_ANYHIT_NV,
|
||||
GLSLANG_STAGE_CLOSESTHIT_NV,
|
||||
GLSLANG_STAGE_MISS_NV,
|
||||
GLSLANG_STAGE_CALLABLE_NV,
|
||||
GLSLANG_STAGE_TASK_NV,
|
||||
GLSLANG_STAGE_MESH_NV,
|
||||
LAST_ELEMENT_MARKER(GLSLANG_STAGE_COUNT),
|
||||
} glslang_stage_t; // would be better as stage, but this is ancient now
|
||||
|
||||
/* EShLanguageMask counterpart */
|
||||
typedef enum {
|
||||
GLSLANG_STAGE_VERTEX_MASK = (1 << GLSLANG_STAGE_VERTEX),
|
||||
GLSLANG_STAGE_TESSCONTROL_MASK = (1 << GLSLANG_STAGE_TESSCONTROL),
|
||||
GLSLANG_STAGE_TESSEVALUATION_MASK = (1 << GLSLANG_STAGE_TESSEVALUATION),
|
||||
GLSLANG_STAGE_GEOMETRY_MASK = (1 << GLSLANG_STAGE_GEOMETRY),
|
||||
GLSLANG_STAGE_FRAGMENT_MASK = (1 << GLSLANG_STAGE_FRAGMENT),
|
||||
GLSLANG_STAGE_COMPUTE_MASK = (1 << GLSLANG_STAGE_COMPUTE),
|
||||
GLSLANG_STAGE_RAYGEN_NV_MASK = (1 << GLSLANG_STAGE_RAYGEN_NV),
|
||||
GLSLANG_STAGE_INTERSECT_NV_MASK = (1 << GLSLANG_STAGE_INTERSECT_NV),
|
||||
GLSLANG_STAGE_ANYHIT_NV_MASK = (1 << GLSLANG_STAGE_ANYHIT_NV),
|
||||
GLSLANG_STAGE_CLOSESTHIT_NV_MASK = (1 << GLSLANG_STAGE_CLOSESTHIT_NV),
|
||||
GLSLANG_STAGE_MISS_NV_MASK = (1 << GLSLANG_STAGE_MISS_NV),
|
||||
GLSLANG_STAGE_CALLABLE_NV_MASK = (1 << GLSLANG_STAGE_CALLABLE_NV),
|
||||
GLSLANG_STAGE_TASK_NV_MASK = (1 << GLSLANG_STAGE_TASK_NV),
|
||||
GLSLANG_STAGE_MESH_NV_MASK = (1 << GLSLANG_STAGE_MESH_NV),
|
||||
LAST_ELEMENT_MARKER(GLSLANG_STAGE_MASK_COUNT),
|
||||
} glslang_stage_mask_t;
|
||||
|
||||
/* EShSource counterpart */
|
||||
typedef enum {
|
||||
GLSLANG_SOURCE_NONE,
|
||||
GLSLANG_SOURCE_GLSL,
|
||||
GLSLANG_SOURCE_HLSL,
|
||||
LAST_ELEMENT_MARKER(GLSLANG_SOURCE_COUNT),
|
||||
} glslang_source_t;
|
||||
|
||||
/* EShClient counterpart */
|
||||
typedef enum {
|
||||
GLSLANG_CLIENT_NONE,
|
||||
GLSLANG_CLIENT_VULKAN,
|
||||
GLSLANG_CLIENT_OPENGL,
|
||||
LAST_ELEMENT_MARKER(GLSLANG_CLIENT_COUNT),
|
||||
} glslang_client_t;
|
||||
|
||||
/* EShTargetLanguage counterpart */
|
||||
typedef enum {
|
||||
GLSLANG_TARGET_NONE,
|
||||
GLSLANG_TARGET_SPV,
|
||||
LAST_ELEMENT_MARKER(GLSLANG_TARGET_COUNT),
|
||||
} glslang_target_language_t;
|
||||
|
||||
/* SH_TARGET_ClientVersion counterpart */
|
||||
typedef enum {
|
||||
GLSLANG_TARGET_VULKAN_1_0 = (1 << 22),
|
||||
GLSLANG_TARGET_VULKAN_1_1 = (1 << 22) | (1 << 12),
|
||||
GLSLANG_TARGET_OPENGL_450 = 450,
|
||||
LAST_ELEMENT_MARKER(GLSLANG_TARGET_CLIENT_VERSION_COUNT),
|
||||
} glslang_target_client_version_t;
|
||||
|
||||
/* SH_TARGET_LanguageVersion counterpart */
|
||||
typedef enum {
|
||||
GLSLANG_TARGET_SPV_1_0 = (1 << 16),
|
||||
GLSLANG_TARGET_SPV_1_1 = (1 << 16) | (1 << 8),
|
||||
GLSLANG_TARGET_SPV_1_2 = (1 << 16) | (2 << 8),
|
||||
GLSLANG_TARGET_SPV_1_3 = (1 << 16) | (3 << 8),
|
||||
GLSLANG_TARGET_SPV_1_4 = (1 << 16) | (4 << 8),
|
||||
GLSLANG_TARGET_SPV_1_5 = (1 << 16) | (5 << 8),
|
||||
LAST_ELEMENT_MARKER(GLSLANG_TARGET_LANGUAGE_VERSION_COUNT),
|
||||
} glslang_target_language_version_t;
|
||||
|
||||
/* EShExecutable counterpart */
|
||||
typedef enum { GLSLANG_EX_VERTEX_FRAGMENT, GLSLANG_EX_FRAGMENT } glslang_executable_t;
|
||||
|
||||
/* EShOptimizationLevel counterpart */
|
||||
typedef enum {
|
||||
GLSLANG_OPT_NO_GENERATION,
|
||||
GLSLANG_OPT_NONE,
|
||||
GLSLANG_OPT_SIMPLE,
|
||||
GLSLANG_OPT_FULL,
|
||||
LAST_ELEMENT_MARKER(GLSLANG_OPT_LEVEL_COUNT),
|
||||
} glslang_optimization_level_t;
|
||||
|
||||
/* EShTextureSamplerTransformMode counterpart */
|
||||
typedef enum {
|
||||
GLSLANG_TEX_SAMP_TRANS_KEEP,
|
||||
GLSLANG_TEX_SAMP_TRANS_UPGRADE_TEXTURE_REMOVE_SAMPLER,
|
||||
LAST_ELEMENT_MARKER(GLSLANG_TEX_SAMP_TRANS_COUNT),
|
||||
} glslang_texture_sampler_transform_mode_t;
|
||||
|
||||
/* EShMessages counterpart */
|
||||
typedef enum {
|
||||
GLSLANG_MSG_DEFAULT_BIT = 0,
|
||||
GLSLANG_MSG_RELAXED_ERRORS_BIT = (1 << 0),
|
||||
GLSLANG_MSG_SUPPRESS_WARNINGS_BIT = (1 << 1),
|
||||
GLSLANG_MSG_AST_BIT = (1 << 2),
|
||||
GLSLANG_MSG_SPV_RULES_BIT = (1 << 3),
|
||||
GLSLANG_MSG_VULKAN_RULES_BIT = (1 << 4),
|
||||
GLSLANG_MSG_ONLY_PREPROCESSOR_BIT = (1 << 5),
|
||||
GLSLANG_MSG_READ_HLSL_BIT = (1 << 6),
|
||||
GLSLANG_MSG_CASCADING_ERRORS_BIT = (1 << 7),
|
||||
GLSLANG_MSG_KEEP_UNCALLED_BIT = (1 << 8),
|
||||
GLSLANG_MSG_HLSL_OFFSETS_BIT = (1 << 9),
|
||||
GLSLANG_MSG_DEBUG_INFO_BIT = (1 << 10),
|
||||
GLSLANG_MSG_HLSL_ENABLE_16BIT_TYPES_BIT = (1 << 11),
|
||||
GLSLANG_MSG_HLSL_LEGALIZATION_BIT = (1 << 12),
|
||||
GLSLANG_MSG_HLSL_DX9_COMPATIBLE_BIT = (1 << 13),
|
||||
GLSLANG_MSG_BUILTIN_SYMBOL_TABLE_BIT = (1 << 14),
|
||||
LAST_ELEMENT_MARKER(GLSLANG_MSG_COUNT),
|
||||
} glslang_messages_t;
|
||||
|
||||
/* EShReflectionOptions counterpart */
|
||||
typedef enum {
|
||||
GLSLANG_REFLECTION_DEFAULT_BIT = 0,
|
||||
GLSLANG_REFLECTION_STRICT_ARRAY_SUFFIX_BIT = (1 << 0),
|
||||
GLSLANG_REFLECTION_BASIC_ARRAY_SUFFIX_BIT = (1 << 1),
|
||||
GLSLANG_REFLECTION_INTERMEDIATE_IOO_BIT = (1 << 2),
|
||||
GLSLANG_REFLECTION_SEPARATE_BUFFERS_BIT = (1 << 3),
|
||||
GLSLANG_REFLECTION_ALL_BLOCK_VARIABLES_BIT = (1 << 4),
|
||||
GLSLANG_REFLECTION_UNWRAP_IO_BLOCKS_BIT = (1 << 5),
|
||||
GLSLANG_REFLECTION_ALL_IO_VARIABLES_BIT = (1 << 6),
|
||||
GLSLANG_REFLECTION_SHARED_STD140_SSBO_BIT = (1 << 7),
|
||||
GLSLANG_REFLECTION_SHARED_STD140_UBO_BIT = (1 << 8),
|
||||
LAST_ELEMENT_MARKER(GLSLANG_REFLECTION_COUNT),
|
||||
} glslang_reflection_options_t;
|
||||
|
||||
/* EProfile counterpart (from Versions.h) */
|
||||
typedef enum {
|
||||
GLSLANG_BAD_PROFILE = 0,
|
||||
GLSLANG_NO_PROFILE = (1 << 0),
|
||||
GLSLANG_CORE_PROFILE = (1 << 1),
|
||||
GLSLANG_COMPATIBILITY_PROFILE = (1 << 2),
|
||||
GLSLANG_ES_PROFILE = (1 << 3),
|
||||
LAST_ELEMENT_MARKER(GLSLANG_PROFILE_COUNT),
|
||||
} glslang_profile_t;
|
||||
|
||||
#undef LAST_ELEMENT_MARKER
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,3 @@
|
|||
// This header is generated by the make-revision script.
|
||||
|
||||
#define GLSLANG_PATCH_LEVEL 3795
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2013-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 _INITIALIZE_INCLUDED_
|
||||
#define _INITIALIZE_INCLUDED_
|
||||
|
||||
#include "../Include/ResourceLimits.h"
|
||||
#include "../Include/Common.h"
|
||||
#include "../Include/ShHandle.h"
|
||||
#include "SymbolTable.h"
|
||||
#include "Versions.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
//
|
||||
// This is made to hold parseable strings for almost all the built-in
|
||||
// functions and variables for one specific combination of version
|
||||
// and profile. (Some still need to be added programmatically.)
|
||||
// This is a base class for language-specific derivations, which
|
||||
// can be used for language independent builtins.
|
||||
//
|
||||
// The strings are organized by
|
||||
// commonBuiltins: intersection of all stages' built-ins, processed just once
|
||||
// stageBuiltins[]: anything a stage needs that's not in commonBuiltins
|
||||
//
|
||||
class TBuiltInParseables {
|
||||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
TBuiltInParseables();
|
||||
virtual ~TBuiltInParseables();
|
||||
virtual void initialize(int version, EProfile, const SpvVersion& spvVersion) = 0;
|
||||
virtual void initialize(const TBuiltInResource& resources, int version, EProfile, const SpvVersion& spvVersion, EShLanguage) = 0;
|
||||
virtual const TString& getCommonString() const { return commonBuiltins; }
|
||||
virtual const TString& getStageString(EShLanguage language) const { return stageBuiltins[language]; }
|
||||
|
||||
virtual void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable) = 0;
|
||||
virtual void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources) = 0;
|
||||
|
||||
protected:
|
||||
TString commonBuiltins;
|
||||
TString stageBuiltins[EShLangCount];
|
||||
};
|
||||
|
||||
//
|
||||
// This is a GLSL specific derivation of TBuiltInParseables. To present a stable
|
||||
// interface and match other similar code, it is called TBuiltIns, rather
|
||||
// than TBuiltInParseablesGlsl.
|
||||
//
|
||||
class TBuiltIns : public TBuiltInParseables {
|
||||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
TBuiltIns();
|
||||
virtual ~TBuiltIns();
|
||||
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);
|
||||
|
||||
protected:
|
||||
void addTabledBuiltins(int version, EProfile profile, const SpvVersion& spvVersion);
|
||||
void relateTabledBuiltins(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage, TSymbolTable&);
|
||||
void add2ndGenerationSamplingImaging(int version, EProfile profile, const SpvVersion& spvVersion);
|
||||
void addSubpassSampling(TSampler, const TString& typeName, int version, EProfile profile);
|
||||
void addQueryFunctions(TSampler, const TString& typeName, int version, EProfile profile);
|
||||
void addImageFunctions(TSampler, const TString& typeName, int version, EProfile profile);
|
||||
void addSamplingFunctions(TSampler, const TString& typeName, int version, EProfile profile);
|
||||
void addGatherFunctions(TSampler, const TString& typeName, int version, EProfile profile);
|
||||
|
||||
// Helpers for making textual representations of the permutations
|
||||
// of texturing/imaging functions.
|
||||
const char* postfixes[5];
|
||||
const char* prefixes[EbtNumTypes];
|
||||
int dimMap[EsdNumDims];
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _INITIALIZE_INCLUDED_
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../Include/Common.h"
|
||||
#include "reflection.h"
|
||||
#include "localintermediate.h"
|
||||
|
||||
#include "gl_types.h"
|
||||
|
||||
#include <list>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace glslang {
|
||||
|
||||
//
|
||||
// The traverser: mostly pass through, except
|
||||
// - processing function-call nodes to push live functions onto the stack of functions to process
|
||||
// - processing selection nodes to trim semantically dead code
|
||||
//
|
||||
// This is in the glslang namespace directly so it can be a friend of TReflection.
|
||||
// This can be derived from to implement reflection database traversers or
|
||||
// binding mappers: anything that wants to traverse the live subset of the tree.
|
||||
//
|
||||
|
||||
class TLiveTraverser : public TIntermTraverser {
|
||||
public:
|
||||
TLiveTraverser(const TIntermediate& i, bool traverseAll = false,
|
||||
bool preVisit = true, bool inVisit = false, bool postVisit = false) :
|
||||
TIntermTraverser(preVisit, inVisit, postVisit),
|
||||
intermediate(i), traverseAll(traverseAll)
|
||||
{ }
|
||||
|
||||
//
|
||||
// Given a function name, find its subroot in the tree, and push it onto the stack of
|
||||
// functions left to process.
|
||||
//
|
||||
void pushFunction(const TString& name)
|
||||
{
|
||||
TIntermSequence& globals = intermediate.getTreeRoot()->getAsAggregate()->getSequence();
|
||||
for (unsigned int f = 0; f < globals.size(); ++f) {
|
||||
TIntermAggregate* candidate = globals[f]->getAsAggregate();
|
||||
if (candidate && candidate->getOp() == EOpFunction && candidate->getName() == name) {
|
||||
functions.push_back(candidate);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typedef std::list<TIntermAggregate*> TFunctionStack;
|
||||
TFunctionStack functions;
|
||||
|
||||
protected:
|
||||
// To catch which function calls are not dead, and hence which functions must be visited.
|
||||
virtual bool visitAggregate(TVisit, TIntermAggregate* node)
|
||||
{
|
||||
if (!traverseAll)
|
||||
if (node->getOp() == EOpFunctionCall)
|
||||
addFunctionCall(node);
|
||||
|
||||
return true; // traverse this subtree
|
||||
}
|
||||
|
||||
// To prune semantically dead paths.
|
||||
virtual bool visitSelection(TVisit /* visit */, TIntermSelection* node)
|
||||
{
|
||||
if (traverseAll)
|
||||
return true; // traverse all code
|
||||
|
||||
TIntermConstantUnion* constant = node->getCondition()->getAsConstantUnion();
|
||||
if (constant) {
|
||||
// cull the path that is dead
|
||||
if (constant->getConstArray()[0].getBConst() == true && node->getTrueBlock())
|
||||
node->getTrueBlock()->traverse(this);
|
||||
if (constant->getConstArray()[0].getBConst() == false && node->getFalseBlock())
|
||||
node->getFalseBlock()->traverse(this);
|
||||
|
||||
return false; // don't traverse any more, we did it all above
|
||||
} else
|
||||
return true; // traverse the whole subtree
|
||||
}
|
||||
|
||||
// Track live functions as well as uniforms, so that we don't visit dead functions
|
||||
// and only visit each function once.
|
||||
void addFunctionCall(TIntermAggregate* call)
|
||||
{
|
||||
// // just use the map to ensure we process each function at most once
|
||||
if (liveFunctions.find(call->getName()) == liveFunctions.end()) {
|
||||
liveFunctions.insert(call->getName());
|
||||
pushFunction(call->getName());
|
||||
}
|
||||
}
|
||||
|
||||
const TIntermediate& intermediate;
|
||||
typedef std::unordered_set<TString> TLiveFunctions;
|
||||
TLiveFunctions liveFunctions;
|
||||
bool traverseAll;
|
||||
|
||||
private:
|
||||
// prevent copy & copy construct
|
||||
TLiveTraverser(TLiveTraverser&);
|
||||
TLiveTraverser& operator=(TLiveTraverser&);
|
||||
};
|
||||
|
||||
} // namespace glslang
|
||||
|
|
@ -0,0 +1,532 @@
|
|||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2012-2013 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.
|
||||
//
|
||||
|
||||
//
|
||||
// This header defines a two-level parse-helper hierarchy, derived from
|
||||
// TParseVersions:
|
||||
// - TParseContextBase: sharable across multiple parsers
|
||||
// - TParseContext: GLSL specific helper
|
||||
//
|
||||
|
||||
#ifndef _PARSER_HELPER_INCLUDED_
|
||||
#define _PARSER_HELPER_INCLUDED_
|
||||
|
||||
#include <cstdarg>
|
||||
#include <functional>
|
||||
|
||||
#include "parseVersions.h"
|
||||
#include "../Include/ShHandle.h"
|
||||
#include "SymbolTable.h"
|
||||
#include "localintermediate.h"
|
||||
#include "Scan.h"
|
||||
#include "attribute.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
struct TPragma {
|
||||
TPragma(bool o, bool d) : optimize(o), debug(d) { }
|
||||
bool optimize;
|
||||
bool debug;
|
||||
TPragmaTable pragmaTable;
|
||||
};
|
||||
|
||||
class TScanContext;
|
||||
class TPpContext;
|
||||
|
||||
typedef std::set<int> TIdSetType;
|
||||
typedef std::map<const TTypeList*, std::map<size_t, const TTypeList*>> TStructRecord;
|
||||
|
||||
//
|
||||
// Sharable code (as well as what's in TParseVersions) across
|
||||
// parse helpers.
|
||||
//
|
||||
class TParseContextBase : public TParseVersions {
|
||||
public:
|
||||
TParseContextBase(TSymbolTable& symbolTable, TIntermediate& interm, bool parsingBuiltins, int version,
|
||||
EProfile profile, const SpvVersion& spvVersion, EShLanguage language,
|
||||
TInfoSink& infoSink, bool forwardCompatible, EShMessages messages,
|
||||
const TString* entryPoint = nullptr)
|
||||
: TParseVersions(interm, version, profile, spvVersion, language, infoSink, forwardCompatible, messages),
|
||||
scopeMangler("::"),
|
||||
symbolTable(symbolTable),
|
||||
statementNestingLevel(0), loopNestingLevel(0), structNestingLevel(0), controlFlowNestingLevel(0),
|
||||
postEntryPointReturn(false),
|
||||
contextPragma(true, false),
|
||||
beginInvocationInterlockCount(0), endInvocationInterlockCount(0),
|
||||
parsingBuiltins(parsingBuiltins), scanContext(nullptr), ppContext(nullptr),
|
||||
limits(resources.limits),
|
||||
globalUniformBlock(nullptr),
|
||||
globalUniformBinding(TQualifier::layoutBindingEnd),
|
||||
globalUniformSet(TQualifier::layoutSetEnd)
|
||||
{
|
||||
if (entryPoint != nullptr)
|
||||
sourceEntryPointName = *entryPoint;
|
||||
}
|
||||
virtual ~TParseContextBase() { }
|
||||
|
||||
#if !defined(GLSLANG_WEB) || defined(GLSLANG_WEB_DEVEL)
|
||||
virtual void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||
const char* szExtraInfoFormat, ...);
|
||||
virtual void C_DECL warn(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||
const char* szExtraInfoFormat, ...);
|
||||
virtual void C_DECL ppError(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||
const char* szExtraInfoFormat, ...);
|
||||
virtual void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||
const char* szExtraInfoFormat, ...);
|
||||
#endif
|
||||
|
||||
virtual void setLimits(const TBuiltInResource&) = 0;
|
||||
|
||||
void checkIndex(const TSourceLoc&, const TType&, int& index);
|
||||
|
||||
EShLanguage getLanguage() const { return language; }
|
||||
void setScanContext(TScanContext* c) { scanContext = c; }
|
||||
TScanContext* getScanContext() const { return scanContext; }
|
||||
void setPpContext(TPpContext* c) { ppContext = c; }
|
||||
TPpContext* getPpContext() const { return ppContext; }
|
||||
|
||||
virtual void setLineCallback(const std::function<void(int, int, bool, int, const char*)>& func) { lineCallback = func; }
|
||||
virtual void setExtensionCallback(const std::function<void(int, const char*, const char*)>& func) { extensionCallback = func; }
|
||||
virtual void setVersionCallback(const std::function<void(int, int, const char*)>& func) { versionCallback = func; }
|
||||
virtual void setPragmaCallback(const std::function<void(int, const TVector<TString>&)>& func) { pragmaCallback = func; }
|
||||
virtual void setErrorCallback(const std::function<void(int, const char*)>& func) { errorCallback = func; }
|
||||
|
||||
virtual void reservedPpErrorCheck(const TSourceLoc&, const char* name, const char* op) = 0;
|
||||
virtual bool lineContinuationCheck(const TSourceLoc&, bool endOfComment) = 0;
|
||||
virtual bool lineDirectiveShouldSetNextLine() const = 0;
|
||||
virtual void handlePragma(const TSourceLoc&, const TVector<TString>&) = 0;
|
||||
|
||||
virtual bool parseShaderStrings(TPpContext&, TInputScanner& input, bool versionWillBeError = false) = 0;
|
||||
|
||||
virtual void notifyVersion(int line, int version, const char* type_string)
|
||||
{
|
||||
if (versionCallback)
|
||||
versionCallback(line, version, type_string);
|
||||
}
|
||||
virtual void notifyErrorDirective(int line, const char* error_message)
|
||||
{
|
||||
if (errorCallback)
|
||||
errorCallback(line, error_message);
|
||||
}
|
||||
virtual void notifyLineDirective(int curLineNo, int newLineNo, bool hasSource, int sourceNum, const char* sourceName)
|
||||
{
|
||||
if (lineCallback)
|
||||
lineCallback(curLineNo, newLineNo, hasSource, sourceNum, sourceName);
|
||||
}
|
||||
virtual void notifyExtensionDirective(int line, const char* extension, const char* behavior)
|
||||
{
|
||||
if (extensionCallback)
|
||||
extensionCallback(line, extension, behavior);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_HLSL
|
||||
// Manage the global uniform block (default uniforms in GLSL, $Global in HLSL)
|
||||
virtual void growGlobalUniformBlock(const TSourceLoc&, TType&, const TString& memberName, TTypeList* typeList = nullptr);
|
||||
#endif
|
||||
|
||||
// Potentially rename shader entry point function
|
||||
void renameShaderFunction(TString*& name) const
|
||||
{
|
||||
// Replace the entry point name given in the shader with the real entry point name,
|
||||
// if there is a substitution.
|
||||
if (name != nullptr && *name == sourceEntryPointName && intermediate.getEntryPointName().size() > 0)
|
||||
name = NewPoolTString(intermediate.getEntryPointName().c_str());
|
||||
}
|
||||
|
||||
virtual bool lValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*);
|
||||
virtual void rValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*);
|
||||
|
||||
const char* const scopeMangler;
|
||||
|
||||
// Basic parsing state, easily accessible to the grammar
|
||||
|
||||
TSymbolTable& symbolTable; // symbol table that goes with the current language, version, and profile
|
||||
int statementNestingLevel; // 0 if outside all flow control or compound statements
|
||||
int loopNestingLevel; // 0 if outside all loops
|
||||
int structNestingLevel; // 0 if outside blocks and structures
|
||||
int controlFlowNestingLevel; // 0 if outside all flow control
|
||||
const TType* currentFunctionType; // the return type of the function that's currently being parsed
|
||||
bool functionReturnsValue; // true if a non-void function has a return
|
||||
// if inside a function, true if the function is the entry point and this is after a return statement
|
||||
bool postEntryPointReturn;
|
||||
// case, node, case, case, node, ...; ensure only one node between cases; stack of them for nesting
|
||||
TList<TIntermSequence*> switchSequenceStack;
|
||||
// the statementNestingLevel the current switch statement is at, which must match the level of its case statements
|
||||
TList<int> switchLevel;
|
||||
struct TPragma contextPragma;
|
||||
int beginInvocationInterlockCount;
|
||||
int endInvocationInterlockCount;
|
||||
|
||||
protected:
|
||||
TParseContextBase(TParseContextBase&);
|
||||
TParseContextBase& operator=(TParseContextBase&);
|
||||
|
||||
const bool parsingBuiltins; // true if parsing built-in symbols/functions
|
||||
TVector<TSymbol*> linkageSymbols; // will be transferred to 'linkage', after all editing is done, order preserving
|
||||
TScanContext* scanContext;
|
||||
TPpContext* ppContext;
|
||||
TBuiltInResource resources;
|
||||
TLimits& limits;
|
||||
TString sourceEntryPointName;
|
||||
|
||||
// These, if set, will be called when a line, pragma ... is preprocessed.
|
||||
// They will be called with any parameters to the original directive.
|
||||
std::function<void(int, int, bool, int, const char*)> lineCallback;
|
||||
std::function<void(int, const TVector<TString>&)> pragmaCallback;
|
||||
std::function<void(int, int, const char*)> versionCallback;
|
||||
std::function<void(int, const char*, const char*)> extensionCallback;
|
||||
std::function<void(int, const char*)> errorCallback;
|
||||
|
||||
// see implementation for detail
|
||||
const TFunction* selectFunction(const TVector<const TFunction*>, const TFunction&,
|
||||
std::function<bool(const TType&, const TType&, TOperator, int arg)>,
|
||||
std::function<bool(const TType&, const TType&, const TType&)>,
|
||||
/* output */ bool& tie);
|
||||
|
||||
virtual void parseSwizzleSelector(const TSourceLoc&, const TString&, int size,
|
||||
TSwizzleSelectors<TVectorSelector>&);
|
||||
|
||||
// Manage the global uniform block (default uniforms in GLSL, $Global in HLSL)
|
||||
TVariable* globalUniformBlock; // the actual block, inserted into the symbol table
|
||||
unsigned int globalUniformBinding; // the block's binding number
|
||||
unsigned int globalUniformSet; // the block's set number
|
||||
int firstNewMember; // the index of the first member not yet inserted into the symbol table
|
||||
// override this to set the language-specific name
|
||||
virtual const char* getGlobalUniformBlockName() const { return ""; }
|
||||
virtual void setUniformBlockDefaults(TType&) const { }
|
||||
virtual void finalizeGlobalUniformBlockLayout(TVariable&) { }
|
||||
virtual void outputMessage(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||
const char* szExtraInfoFormat, TPrefixType prefix,
|
||||
va_list args);
|
||||
virtual void trackLinkage(TSymbol& symbol);
|
||||
virtual void makeEditable(TSymbol*&);
|
||||
virtual TVariable* getEditableVariable(const char* name);
|
||||
virtual void finish();
|
||||
};
|
||||
|
||||
//
|
||||
// Manage the state for when to respect precision qualifiers and when to warn about
|
||||
// the defaults being different than might be expected.
|
||||
//
|
||||
class TPrecisionManager {
|
||||
public:
|
||||
TPrecisionManager() : obey(false), warn(false), explicitIntDefault(false), explicitFloatDefault(false){ }
|
||||
virtual ~TPrecisionManager() {}
|
||||
|
||||
void respectPrecisionQualifiers() { obey = true; }
|
||||
bool respectingPrecisionQualifiers() const { return obey; }
|
||||
bool shouldWarnAboutDefaults() const { return warn; }
|
||||
void defaultWarningGiven() { warn = false; }
|
||||
void warnAboutDefaults() { warn = true; }
|
||||
void explicitIntDefaultSeen()
|
||||
{
|
||||
explicitIntDefault = true;
|
||||
if (explicitFloatDefault)
|
||||
warn = false;
|
||||
}
|
||||
void explicitFloatDefaultSeen()
|
||||
{
|
||||
explicitFloatDefault = true;
|
||||
if (explicitIntDefault)
|
||||
warn = false;
|
||||
}
|
||||
|
||||
protected:
|
||||
bool obey; // respect precision qualifiers
|
||||
bool warn; // need to give a warning about the defaults
|
||||
bool explicitIntDefault; // user set the default for int/uint
|
||||
bool explicitFloatDefault; // user set the default for float
|
||||
};
|
||||
|
||||
//
|
||||
// GLSL-specific parse helper. Should have GLSL in the name, but that's
|
||||
// too big of a change for comparing branches at the moment, and perhaps
|
||||
// impacts downstream consumers as well.
|
||||
//
|
||||
class TParseContext : public TParseContextBase {
|
||||
public:
|
||||
TParseContext(TSymbolTable&, TIntermediate&, bool parsingBuiltins, int version, EProfile, const SpvVersion& spvVersion, EShLanguage, TInfoSink&,
|
||||
bool forwardCompatible = false, EShMessages messages = EShMsgDefault,
|
||||
const TString* entryPoint = nullptr);
|
||||
virtual ~TParseContext();
|
||||
|
||||
bool obeyPrecisionQualifiers() const { return precisionManager.respectingPrecisionQualifiers(); }
|
||||
void setPrecisionDefaults();
|
||||
|
||||
void setLimits(const TBuiltInResource&) override;
|
||||
bool parseShaderStrings(TPpContext&, TInputScanner& input, bool versionWillBeError = false) override;
|
||||
void parserError(const char* s); // for bison's yyerror
|
||||
|
||||
void reservedErrorCheck(const TSourceLoc&, const TString&);
|
||||
void reservedPpErrorCheck(const TSourceLoc&, const char* name, const char* op) override;
|
||||
bool lineContinuationCheck(const TSourceLoc&, bool endOfComment) override;
|
||||
bool lineDirectiveShouldSetNextLine() const override;
|
||||
bool builtInName(const TString&);
|
||||
|
||||
void handlePragma(const TSourceLoc&, const TVector<TString>&) override;
|
||||
TIntermTyped* handleVariable(const TSourceLoc&, TSymbol* symbol, const TString* string);
|
||||
TIntermTyped* handleBracketDereference(const TSourceLoc&, TIntermTyped* base, TIntermTyped* index);
|
||||
void handleIndexLimits(const TSourceLoc&, TIntermTyped* base, TIntermTyped* index);
|
||||
|
||||
#ifndef GLSLANG_WEB
|
||||
void makeEditable(TSymbol*&) override;
|
||||
void ioArrayCheck(const TSourceLoc&, const TType&, const TString& identifier);
|
||||
#endif
|
||||
bool isIoResizeArray(const TType&) const;
|
||||
void fixIoArraySize(const TSourceLoc&, TType&);
|
||||
void handleIoResizeArrayAccess(const TSourceLoc&, TIntermTyped* base);
|
||||
void checkIoArraysConsistency(const TSourceLoc&, bool tailOnly = false);
|
||||
int getIoArrayImplicitSize(const TQualifier&, TString* featureString = nullptr) const;
|
||||
void checkIoArrayConsistency(const TSourceLoc&, int requiredSize, const char* feature, TType&, const TString&);
|
||||
|
||||
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);
|
||||
TIntermTyped* handleDotSwizzle(const TSourceLoc&, TIntermTyped* base, const TString& field);
|
||||
void blockMemberExtensionCheck(const TSourceLoc&, const TIntermTyped* base, int member, const TString& memberName);
|
||||
TFunction* handleFunctionDeclarator(const TSourceLoc&, TFunction& function, bool prototype);
|
||||
TIntermAggregate* handleFunctionDefinition(const TSourceLoc&, TFunction&);
|
||||
TIntermTyped* handleFunctionCall(const TSourceLoc&, TFunction*, TIntermNode*);
|
||||
TIntermTyped* handleBuiltInFunctionCall(TSourceLoc, TIntermNode* arguments, const TFunction& function);
|
||||
void computeBuiltinPrecisions(TIntermTyped&, const TFunction&);
|
||||
TIntermNode* handleReturnValue(const TSourceLoc&, TIntermTyped*);
|
||||
void checkLocation(const TSourceLoc&, TOperator);
|
||||
TIntermTyped* handleLengthMethod(const TSourceLoc&, TFunction*, TIntermNode*);
|
||||
void addInputArgumentConversions(const TFunction&, TIntermNode*&) const;
|
||||
TIntermTyped* addOutputArgumentConversions(const TFunction&, TIntermAggregate&) const;
|
||||
void builtInOpCheck(const TSourceLoc&, const TFunction&, TIntermOperator&);
|
||||
void nonOpBuiltInCheck(const TSourceLoc&, const TFunction&, TIntermAggregate&);
|
||||
void userFunctionCallCheck(const TSourceLoc&, TIntermAggregate&);
|
||||
void samplerConstructorLocationCheck(const TSourceLoc&, const char* token, TIntermNode*);
|
||||
TFunction* handleConstructorCall(const TSourceLoc&, const TPublicType&);
|
||||
void handlePrecisionQualifier(const TSourceLoc&, TQualifier&, TPrecisionQualifier);
|
||||
void checkPrecisionQualifier(const TSourceLoc&, TPrecisionQualifier);
|
||||
void memorySemanticsCheck(const TSourceLoc&, const TFunction&, const TIntermOperator& callNode);
|
||||
|
||||
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);
|
||||
bool lValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*) override;
|
||||
void rValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*) override;
|
||||
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&);
|
||||
bool constructorTextureSamplerError(const TSourceLoc&, const TFunction&);
|
||||
void arraySizeCheck(const TSourceLoc&, TIntermTyped* expr, TArraySize&, const char *sizeType);
|
||||
bool arrayQualifierError(const TSourceLoc&, const TQualifier&);
|
||||
bool arrayError(const TSourceLoc&, const TType&);
|
||||
void arraySizeRequiredCheck(const TSourceLoc&, const TArraySizes&);
|
||||
void structArrayCheck(const TSourceLoc&, const TType& structure);
|
||||
void arraySizesCheck(const TSourceLoc&, const TQualifier&, TArraySizes*, const TIntermTyped* initializer, bool lastMember);
|
||||
void arrayOfArrayVersionCheck(const TSourceLoc&, const TArraySizes*);
|
||||
bool voidErrorCheck(const TSourceLoc&, const TString&, TBasicType);
|
||||
void boolCheck(const TSourceLoc&, const TIntermTyped*);
|
||||
void boolCheck(const TSourceLoc&, const TPublicType&);
|
||||
void samplerCheck(const TSourceLoc&, const TType&, const TString& identifier, TIntermTyped* initializer);
|
||||
void atomicUintCheck(const TSourceLoc&, const TType&, const TString& identifier);
|
||||
void accStructCheck(const TSourceLoc & loc, const TType & type, const TString & identifier);
|
||||
void transparentOpaqueCheck(const TSourceLoc&, const TType&, const TString& identifier);
|
||||
void memberQualifierCheck(glslang::TPublicType&);
|
||||
void globalQualifierFixCheck(const TSourceLoc&, TQualifier&);
|
||||
void globalQualifierTypeCheck(const TSourceLoc&, const TQualifier&, const TPublicType&);
|
||||
bool structQualifierErrorCheck(const TSourceLoc&, const TPublicType& pType);
|
||||
void mergeQualifiers(const TSourceLoc&, TQualifier& dst, const TQualifier& src, bool force);
|
||||
void setDefaultPrecision(const TSourceLoc&, TPublicType&, TPrecisionQualifier);
|
||||
int computeSamplerTypeIndex(TSampler&);
|
||||
TPrecisionQualifier getDefaultPrecision(TPublicType&);
|
||||
void precisionQualifierCheck(const TSourceLoc&, TBasicType, TQualifier&);
|
||||
void parameterTypeCheck(const TSourceLoc&, TStorageQualifier qualifier, const TType& type);
|
||||
bool containsFieldWithBasicType(const TType& type ,TBasicType basicType);
|
||||
TSymbol* redeclareBuiltinVariable(const TSourceLoc&, const TString&, const TQualifier&, const TShaderQualifiers&);
|
||||
void redeclareBuiltinBlock(const TSourceLoc&, TTypeList& typeList, const TString& blockName, const TString* instanceName, TArraySizes* arraySizes);
|
||||
void paramCheckFixStorage(const TSourceLoc&, const TStorageQualifier&, TType& type);
|
||||
void paramCheckFix(const TSourceLoc&, const TQualifier&, TType& type);
|
||||
void nestedBlockCheck(const TSourceLoc&);
|
||||
void nestedStructCheck(const TSourceLoc&);
|
||||
void arrayObjectCheck(const TSourceLoc&, const TType&, const char* op);
|
||||
void opaqueCheck(const TSourceLoc&, const TType&, const char* op);
|
||||
void referenceCheck(const TSourceLoc&, const TType&, const char* op);
|
||||
void storage16BitAssignmentCheck(const TSourceLoc&, const TType&, const char* op);
|
||||
void specializationCheck(const TSourceLoc&, const TType&, const char* op);
|
||||
void structTypeCheck(const TSourceLoc&, TPublicType&);
|
||||
void inductiveLoopCheck(const TSourceLoc&, TIntermNode* init, TIntermLoop* loop);
|
||||
void arrayLimitCheck(const TSourceLoc&, const TString&, int size);
|
||||
void limitCheck(const TSourceLoc&, int value, const char* limit, const char* feature);
|
||||
|
||||
void inductiveLoopBodyCheck(TIntermNode*, int loopIndexId, TSymbolTable&);
|
||||
void constantIndexExpressionCheck(TIntermNode*);
|
||||
|
||||
void setLayoutQualifier(const TSourceLoc&, TPublicType&, TString&);
|
||||
void setLayoutQualifier(const TSourceLoc&, TPublicType&, TString&, const TIntermTyped*);
|
||||
void mergeObjectLayoutQualifiers(TQualifier& dest, const TQualifier& src, bool inheritOnly);
|
||||
void layoutObjectCheck(const TSourceLoc&, const TSymbol&);
|
||||
void layoutMemberLocationArrayCheck(const TSourceLoc&, bool memberWithLocation, TArraySizes* arraySizes);
|
||||
void layoutTypeCheck(const TSourceLoc&, const TType&);
|
||||
void layoutQualifierCheck(const TSourceLoc&, const TQualifier&);
|
||||
void checkNoShaderLayouts(const TSourceLoc&, const TShaderQualifiers&);
|
||||
void fixOffset(const TSourceLoc&, TSymbol&);
|
||||
|
||||
const TFunction* findFunction(const TSourceLoc& loc, const TFunction& call, bool& builtIn);
|
||||
const TFunction* findFunctionExact(const TSourceLoc& loc, const TFunction& call, bool& builtIn);
|
||||
const TFunction* findFunction120(const TSourceLoc& loc, const TFunction& call, bool& builtIn);
|
||||
const TFunction* findFunction400(const TSourceLoc& loc, const TFunction& call, bool& builtIn);
|
||||
const TFunction* findFunctionExplicitTypes(const TSourceLoc& loc, const TFunction& call, bool& builtIn);
|
||||
void declareTypeDefaults(const TSourceLoc&, const TPublicType&);
|
||||
TIntermNode* declareVariable(const TSourceLoc&, TString& identifier, const TPublicType&, TArraySizes* typeArray = 0, TIntermTyped* initializer = 0);
|
||||
TIntermTyped* addConstructor(const TSourceLoc&, TIntermNode*, const TType&);
|
||||
TIntermTyped* constructAggregate(TIntermNode*, const TType&, int, const TSourceLoc&);
|
||||
TIntermTyped* constructBuiltIn(const TType&, TOperator, TIntermTyped*, const TSourceLoc&, bool subset);
|
||||
void inheritMemoryQualifiers(const TQualifier& from, TQualifier& to);
|
||||
void declareBlock(const TSourceLoc&, TTypeList& typeList, const TString* instanceName = 0, TArraySizes* arraySizes = 0);
|
||||
void blockStageIoCheck(const TSourceLoc&, const TQualifier&);
|
||||
void blockQualifierCheck(const TSourceLoc&, const TQualifier&, bool instanceName);
|
||||
void fixBlockLocations(const TSourceLoc&, TQualifier&, TTypeList&, bool memberWithLocation, bool memberWithoutLocation);
|
||||
void fixXfbOffsets(TQualifier&, TTypeList&);
|
||||
void fixBlockUniformOffsets(TQualifier&, TTypeList&);
|
||||
void fixBlockUniformLayoutMatrix(TQualifier&, TTypeList*, TTypeList*);
|
||||
void fixBlockUniformLayoutPacking(TQualifier&, TTypeList*, TTypeList*);
|
||||
void addQualifierToExisting(const TSourceLoc&, TQualifier, const TString& identifier);
|
||||
void addQualifierToExisting(const TSourceLoc&, TQualifier, TIdentifierList&);
|
||||
void invariantCheck(const TSourceLoc&, const TQualifier&);
|
||||
void updateStandaloneQualifierDefaults(const TSourceLoc&, const TPublicType&);
|
||||
void wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode);
|
||||
TIntermNode* addSwitch(const TSourceLoc&, TIntermTyped* expression, TIntermAggregate* body);
|
||||
const TTypeList* recordStructCopy(TStructRecord&, const TType*, const TType*);
|
||||
|
||||
#ifndef GLSLANG_WEB
|
||||
TAttributeType attributeFromName(const TString& name) const;
|
||||
TAttributes* makeAttributes(const TString& identifier) const;
|
||||
TAttributes* makeAttributes(const TString& identifier, TIntermNode* node) const;
|
||||
TAttributes* mergeAttributes(TAttributes*, TAttributes*) const;
|
||||
|
||||
// Determine selection control from attributes
|
||||
void handleSelectionAttributes(const TAttributes& attributes, TIntermNode*);
|
||||
void handleSwitchAttributes(const TAttributes& attributes, TIntermNode*);
|
||||
// Determine loop control from attributes
|
||||
void handleLoopAttributes(const TAttributes& attributes, TIntermNode*);
|
||||
#endif
|
||||
|
||||
void checkAndResizeMeshViewDim(const TSourceLoc&, TType&, bool isBlockMember);
|
||||
|
||||
protected:
|
||||
void nonInitConstCheck(const TSourceLoc&, TString& identifier, TType& type);
|
||||
void inheritGlobalDefaults(TQualifier& dst) const;
|
||||
TVariable* makeInternalVariable(const char* name, const TType&) const;
|
||||
TVariable* declareNonArray(const TSourceLoc&, const TString& identifier, const TType&);
|
||||
void declareArray(const TSourceLoc&, const TString& identifier, const TType&, TSymbol*&);
|
||||
void checkRuntimeSizable(const TSourceLoc&, const TIntermTyped&);
|
||||
bool isRuntimeLength(const TIntermTyped&) const;
|
||||
TIntermNode* executeInitializer(const TSourceLoc&, TIntermTyped* initializer, TVariable* variable);
|
||||
TIntermTyped* convertInitializerList(const TSourceLoc&, const TType&, TIntermTyped* initializer);
|
||||
#ifndef GLSLANG_WEB
|
||||
void finish() override;
|
||||
#endif
|
||||
|
||||
public:
|
||||
//
|
||||
// Generally, bison productions, the scanner, and the PP need read/write access to these; just give them direct access
|
||||
//
|
||||
|
||||
// Current state of parsing
|
||||
bool inMain; // if inside a function, true if the function is main
|
||||
const TString* blockName;
|
||||
TQualifier currentBlockQualifier;
|
||||
TPrecisionQualifier defaultPrecision[EbtNumTypes];
|
||||
TBuiltInResource resources;
|
||||
TLimits& limits;
|
||||
|
||||
protected:
|
||||
TParseContext(TParseContext&);
|
||||
TParseContext& operator=(TParseContext&);
|
||||
|
||||
static const int maxSamplerIndex = EsdNumDims * (EbtNumTypes * (2 * 2 * 2 * 2 * 2)); // see computeSamplerTypeIndex()
|
||||
TPrecisionQualifier defaultSamplerPrecision[maxSamplerIndex];
|
||||
TPrecisionManager precisionManager;
|
||||
TQualifier globalBufferDefaults;
|
||||
TQualifier globalUniformDefaults;
|
||||
TQualifier globalInputDefaults;
|
||||
TQualifier globalOutputDefaults;
|
||||
TString currentCaller; // name of last function body entered (not valid when at global scope)
|
||||
#ifndef GLSLANG_WEB
|
||||
int* atomicUintOffsets; // to become an array of the right size to hold an offset per binding point
|
||||
bool anyIndexLimits;
|
||||
TIdSetType inductiveLoopIds;
|
||||
TVector<TIntermTyped*> needsIndexLimitationChecking;
|
||||
TStructRecord matrixFixRecord;
|
||||
TStructRecord packingFixRecord;
|
||||
|
||||
//
|
||||
// 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;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _PARSER_HELPER_INCLUDED_
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace glslang {
|
||||
|
||||
void RemoveAllTreeNodes(TIntermNode*);
|
||||
|
||||
} // end namespace glslang
|
||||
|
|
@ -0,0 +1,276 @@
|
|||
//
|
||||
// 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 _GLSLANG_SCAN_INCLUDED_
|
||||
#define _GLSLANG_SCAN_INCLUDED_
|
||||
|
||||
#include "Versions.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
// Use a global end-of-input character, so no translation is needed across
|
||||
// layers of encapsulation. Characters are all 8 bit, and positive, so there is
|
||||
// no aliasing of character 255 onto -1, for example.
|
||||
const int EndOfInput = -1;
|
||||
|
||||
//
|
||||
// A character scanner that seamlessly, on read-only strings, reads across an
|
||||
// array of strings without assuming null termination.
|
||||
//
|
||||
class TInputScanner {
|
||||
public:
|
||||
TInputScanner(int n, const char* const s[], size_t L[], const char* const* names = nullptr,
|
||||
int b = 0, int f = 0, bool single = false) :
|
||||
numSources(n),
|
||||
// up to this point, common usage is "char*", but now we need positive 8-bit characters
|
||||
sources(reinterpret_cast<const unsigned char* const *>(s)),
|
||||
lengths(L), currentSource(0), currentChar(0), stringBias(b), finale(f), singleLogical(single),
|
||||
endOfFileReached(false)
|
||||
{
|
||||
loc = new TSourceLoc[numSources];
|
||||
for (int i = 0; i < numSources; ++i) {
|
||||
loc[i].init(i - stringBias);
|
||||
}
|
||||
if (names != nullptr) {
|
||||
for (int i = 0; i < numSources; ++i)
|
||||
loc[i].name = names[i] != nullptr ? NewPoolTString(names[i]) : nullptr;
|
||||
}
|
||||
loc[currentSource].line = 1;
|
||||
logicalSourceLoc.init(1);
|
||||
logicalSourceLoc.name = loc[0].name;
|
||||
}
|
||||
|
||||
virtual ~TInputScanner()
|
||||
{
|
||||
delete [] loc;
|
||||
}
|
||||
|
||||
// retrieve the next character and advance one character
|
||||
int get()
|
||||
{
|
||||
int ret = peek();
|
||||
if (ret == EndOfInput)
|
||||
return ret;
|
||||
++loc[currentSource].column;
|
||||
++logicalSourceLoc.column;
|
||||
if (ret == '\n') {
|
||||
++loc[currentSource].line;
|
||||
++logicalSourceLoc.line;
|
||||
logicalSourceLoc.column = 0;
|
||||
loc[currentSource].column = 0;
|
||||
}
|
||||
advance();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// retrieve the next character, no advance
|
||||
int peek()
|
||||
{
|
||||
if (currentSource >= numSources) {
|
||||
endOfFileReached = true;
|
||||
return EndOfInput;
|
||||
}
|
||||
// Make sure we do not read off the end of a string.
|
||||
// N.B. Sources can have a length of 0.
|
||||
int sourceToRead = currentSource;
|
||||
size_t charToRead = currentChar;
|
||||
while(charToRead >= lengths[sourceToRead]) {
|
||||
charToRead = 0;
|
||||
sourceToRead += 1;
|
||||
if (sourceToRead >= numSources) {
|
||||
return EndOfInput;
|
||||
}
|
||||
}
|
||||
|
||||
// Here, we care about making negative valued characters positive
|
||||
return sources[sourceToRead][charToRead];
|
||||
}
|
||||
|
||||
// go back one character
|
||||
void unget()
|
||||
{
|
||||
// Do not roll back once we've reached the end of the file.
|
||||
if (endOfFileReached)
|
||||
return;
|
||||
|
||||
if (currentChar > 0) {
|
||||
--currentChar;
|
||||
--loc[currentSource].column;
|
||||
--logicalSourceLoc.column;
|
||||
if (loc[currentSource].column < 0) {
|
||||
// We've moved back past a new line. Find the
|
||||
// previous newline (or start of the file) to compute
|
||||
// the column count on the now current line.
|
||||
size_t chIndex = currentChar;
|
||||
while (chIndex > 0) {
|
||||
if (sources[currentSource][chIndex] == '\n') {
|
||||
break;
|
||||
}
|
||||
--chIndex;
|
||||
}
|
||||
logicalSourceLoc.column = (int)(currentChar - chIndex);
|
||||
loc[currentSource].column = (int)(currentChar - chIndex);
|
||||
}
|
||||
} else {
|
||||
do {
|
||||
--currentSource;
|
||||
} while (currentSource > 0 && lengths[currentSource] == 0);
|
||||
if (lengths[currentSource] == 0) {
|
||||
// set to 0 if we've backed up to the start of an empty string
|
||||
currentChar = 0;
|
||||
} else
|
||||
currentChar = lengths[currentSource] - 1;
|
||||
}
|
||||
if (peek() == '\n') {
|
||||
--loc[currentSource].line;
|
||||
--logicalSourceLoc.line;
|
||||
}
|
||||
}
|
||||
|
||||
// for #line override
|
||||
void setLine(int newLine)
|
||||
{
|
||||
logicalSourceLoc.line = newLine;
|
||||
loc[getLastValidSourceIndex()].line = newLine;
|
||||
}
|
||||
|
||||
// for #line override in filename based parsing
|
||||
void setFile(const char* filename)
|
||||
{
|
||||
TString* fn_tstr = NewPoolTString(filename);
|
||||
logicalSourceLoc.name = fn_tstr;
|
||||
loc[getLastValidSourceIndex()].name = fn_tstr;
|
||||
}
|
||||
|
||||
void setFile(const char* filename, int i)
|
||||
{
|
||||
TString* fn_tstr = NewPoolTString(filename);
|
||||
if (i == getLastValidSourceIndex()) {
|
||||
logicalSourceLoc.name = fn_tstr;
|
||||
}
|
||||
loc[i].name = fn_tstr;
|
||||
}
|
||||
|
||||
void setString(int newString)
|
||||
{
|
||||
logicalSourceLoc.string = newString;
|
||||
loc[getLastValidSourceIndex()].string = newString;
|
||||
logicalSourceLoc.name = nullptr;
|
||||
loc[getLastValidSourceIndex()].name = nullptr;
|
||||
}
|
||||
|
||||
// for #include content indentation
|
||||
void setColumn(int col)
|
||||
{
|
||||
logicalSourceLoc.column = col;
|
||||
loc[getLastValidSourceIndex()].column = col;
|
||||
}
|
||||
|
||||
void setEndOfInput()
|
||||
{
|
||||
endOfFileReached = true;
|
||||
currentSource = numSources;
|
||||
}
|
||||
|
||||
bool atEndOfInput() const { return endOfFileReached; }
|
||||
|
||||
const TSourceLoc& getSourceLoc() const
|
||||
{
|
||||
if (singleLogical) {
|
||||
return logicalSourceLoc;
|
||||
} else {
|
||||
return loc[std::max(0, std::min(currentSource, numSources - finale - 1))];
|
||||
}
|
||||
}
|
||||
// Returns the index (starting from 0) of the most recent valid source string we are reading from.
|
||||
int getLastValidSourceIndex() const { return std::min(currentSource, numSources - 1); }
|
||||
|
||||
void consumeWhiteSpace(bool& foundNonSpaceTab);
|
||||
bool consumeComment();
|
||||
void consumeWhitespaceComment(bool& foundNonSpaceTab);
|
||||
bool scanVersion(int& version, EProfile& profile, bool& notFirstToken);
|
||||
|
||||
protected:
|
||||
|
||||
// advance one character
|
||||
void advance()
|
||||
{
|
||||
++currentChar;
|
||||
if (currentChar >= lengths[currentSource]) {
|
||||
++currentSource;
|
||||
if (currentSource < numSources) {
|
||||
loc[currentSource].string = loc[currentSource - 1].string + 1;
|
||||
loc[currentSource].line = 1;
|
||||
loc[currentSource].column = 0;
|
||||
}
|
||||
while (currentSource < numSources && lengths[currentSource] == 0) {
|
||||
++currentSource;
|
||||
if (currentSource < numSources) {
|
||||
loc[currentSource].string = loc[currentSource - 1].string + 1;
|
||||
loc[currentSource].line = 1;
|
||||
loc[currentSource].column = 0;
|
||||
}
|
||||
}
|
||||
currentChar = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int numSources; // number of strings in source
|
||||
const unsigned char* const *sources; // array of strings; must be converted to positive values on use, to avoid aliasing with -1 as EndOfInput
|
||||
const size_t *lengths; // length of each string
|
||||
int currentSource;
|
||||
size_t currentChar;
|
||||
|
||||
// This is for reporting what string/line an error occurred on, and can be overridden by #line.
|
||||
// It remembers the last state of each source string as it is left for the next one, so unget()
|
||||
// can restore that state.
|
||||
TSourceLoc* loc; // an array
|
||||
|
||||
int stringBias; // the first string that is the user's string number 0
|
||||
int finale; // number of internal strings after user's last string
|
||||
|
||||
TSourceLoc logicalSourceLoc;
|
||||
bool singleLogical; // treats the strings as a single logical string.
|
||||
// locations will be reported from the first string.
|
||||
|
||||
// Set to true once peek() returns EndOfFile, so that we won't roll back
|
||||
// once we've reached EndOfFile.
|
||||
bool endOfFileReached;
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _GLSLANG_SCAN_INCLUDED_
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
//
|
||||
// This holds context specific to the GLSL scanner, which
|
||||
// sits between the preprocessor scanner and parser.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ParseHelper.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
class TPpContext;
|
||||
class TPpToken;
|
||||
class TParserToken;
|
||||
|
||||
class TScanContext {
|
||||
public:
|
||||
explicit TScanContext(TParseContextBase& pc) :
|
||||
parseContext(pc),
|
||||
afterType(false), afterStruct(false),
|
||||
field(false), afterBuffer(false) { }
|
||||
virtual ~TScanContext() { }
|
||||
|
||||
static void fillInKeywordMap();
|
||||
static void deleteKeywordMap();
|
||||
|
||||
int tokenize(TPpContext*, TParserToken&);
|
||||
|
||||
protected:
|
||||
TScanContext(TScanContext&);
|
||||
TScanContext& operator=(TScanContext&);
|
||||
|
||||
int tokenizeIdentifier();
|
||||
int identifierOrType();
|
||||
int reservedWord();
|
||||
int identifierOrReserved(bool reserved);
|
||||
int es30ReservedFromGLSL(int version);
|
||||
int nonreservedKeyword(int esVersion, int nonEsVersion);
|
||||
int precisionKeyword();
|
||||
int matNxM();
|
||||
int dMat();
|
||||
int firstGenerationImage(bool inEs310);
|
||||
int secondGenerationImage();
|
||||
|
||||
TParseContextBase& parseContext;
|
||||
bool afterType; // true if we've recognized a type, so can only be looking for an identifier
|
||||
bool afterStruct; // true if we've recognized the STRUCT keyword, so can only be looking for an identifier
|
||||
bool field; // true if we're on a field, right after a '.'
|
||||
bool afterBuffer; // true if we've recognized the BUFFER keyword
|
||||
TSourceLoc loc;
|
||||
TParserToken* parserToken;
|
||||
TPpToken* ppToken;
|
||||
|
||||
const char* tokenText;
|
||||
int keyword;
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
|
@ -0,0 +1,885 @@
|
|||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2013 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.
|
||||
//
|
||||
|
||||
#ifndef _SYMBOL_TABLE_INCLUDED_
|
||||
#define _SYMBOL_TABLE_INCLUDED_
|
||||
|
||||
//
|
||||
// Symbol table for parsing. Has these design characteristics:
|
||||
//
|
||||
// * Same symbol table can be used to compile many shaders, to preserve
|
||||
// effort of creating and loading with the large numbers of built-in
|
||||
// symbols.
|
||||
//
|
||||
// --> This requires a copy mechanism, so initial pools used to create
|
||||
// the shared information can be popped. Done through "clone"
|
||||
// methods.
|
||||
//
|
||||
// * Name mangling will be used to give each function a unique name
|
||||
// so that symbol table lookups are never ambiguous. This allows
|
||||
// a simpler symbol table structure.
|
||||
//
|
||||
// * Pushing and popping of scope, so symbol table will really be a stack
|
||||
// of symbol tables. Searched from the top, with new inserts going into
|
||||
// the top.
|
||||
//
|
||||
// * Constants: Compile time constant symbols will keep their values
|
||||
// in the symbol table. The parser can substitute constants at parse
|
||||
// time, including doing constant folding and constant propagation.
|
||||
//
|
||||
// * No temporaries: Temporaries made from operations (+, --, .xy, etc.)
|
||||
// are tracked in the intermediate representation, not the symbol table.
|
||||
//
|
||||
|
||||
#include "../Include/Common.h"
|
||||
#include "../Include/intermediate.h"
|
||||
#include "../Include/InfoSink.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
//
|
||||
// Symbol base class. (Can build functions or variables out of these...)
|
||||
//
|
||||
|
||||
class TVariable;
|
||||
class TFunction;
|
||||
class TAnonMember;
|
||||
|
||||
typedef TVector<const char*> TExtensionList;
|
||||
|
||||
class TSymbol {
|
||||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
explicit TSymbol(const TString *n) : name(n), extensions(0), writable(true) { }
|
||||
virtual TSymbol* clone() const = 0;
|
||||
virtual ~TSymbol() { } // rely on all symbol owned memory coming from the pool
|
||||
|
||||
virtual const TString& getName() const { return *name; }
|
||||
virtual void changeName(const TString* newName) { name = newName; }
|
||||
virtual void addPrefix(const char* prefix)
|
||||
{
|
||||
TString newName(prefix);
|
||||
newName.append(*name);
|
||||
changeName(NewPoolTString(newName.c_str()));
|
||||
}
|
||||
virtual const TString& getMangledName() const { return getName(); }
|
||||
virtual TFunction* getAsFunction() { return 0; }
|
||||
virtual const TFunction* getAsFunction() const { return 0; }
|
||||
virtual TVariable* getAsVariable() { return 0; }
|
||||
virtual const TVariable* getAsVariable() const { return 0; }
|
||||
virtual const TAnonMember* getAsAnonMember() const { return 0; }
|
||||
virtual const TType& getType() const = 0;
|
||||
virtual TType& getWritableType() = 0;
|
||||
virtual void setUniqueId(int id) { uniqueId = id; }
|
||||
virtual int getUniqueId() const { return uniqueId; }
|
||||
virtual void setExtensions(int numExts, const char* const exts[])
|
||||
{
|
||||
assert(extensions == 0);
|
||||
assert(numExts > 0);
|
||||
extensions = NewPoolObject(extensions);
|
||||
for (int e = 0; e < numExts; ++e)
|
||||
extensions->push_back(exts[e]);
|
||||
}
|
||||
virtual int getNumExtensions() const { return extensions == nullptr ? 0 : (int)extensions->size(); }
|
||||
virtual const char** getExtensions() const { return extensions->data(); }
|
||||
|
||||
#ifndef GLSLANG_WEB
|
||||
virtual void dump(TInfoSink& infoSink, bool complete = false) const = 0;
|
||||
void dumpExtensions(TInfoSink& infoSink) const;
|
||||
#endif
|
||||
|
||||
virtual bool isReadOnly() const { return ! writable; }
|
||||
virtual void makeReadOnly() { writable = false; }
|
||||
|
||||
protected:
|
||||
explicit TSymbol(const TSymbol&);
|
||||
TSymbol& operator=(const TSymbol&);
|
||||
|
||||
const TString *name;
|
||||
unsigned int uniqueId; // For cross-scope comparing during code generation
|
||||
|
||||
// For tracking what extensions must be present
|
||||
// (don't use if correct version/profile is present).
|
||||
TExtensionList* extensions; // an array of pointers to existing constant char strings
|
||||
|
||||
//
|
||||
// N.B.: Non-const functions that will be generally used should assert on this,
|
||||
// to avoid overwriting shared symbol-table information.
|
||||
//
|
||||
bool writable;
|
||||
};
|
||||
|
||||
//
|
||||
// Variable class, meaning a symbol that's not a function.
|
||||
//
|
||||
// There could be a separate class hierarchy for Constant variables;
|
||||
// Only one of int, bool, or float, (or none) is correct for
|
||||
// any particular use, but it's easy to do this way, and doesn't
|
||||
// seem worth having separate classes, and "getConst" can't simply return
|
||||
// different values for different types polymorphically, so this is
|
||||
// just simple and pragmatic.
|
||||
//
|
||||
class TVariable : public TSymbol {
|
||||
public:
|
||||
TVariable(const TString *name, const TType& t, bool uT = false )
|
||||
: TSymbol(name),
|
||||
userType(uT),
|
||||
constSubtree(nullptr),
|
||||
memberExtensions(nullptr),
|
||||
anonId(-1)
|
||||
{ type.shallowCopy(t); }
|
||||
virtual TVariable* clone() const;
|
||||
virtual ~TVariable() { }
|
||||
|
||||
virtual TVariable* getAsVariable() { return this; }
|
||||
virtual const TVariable* getAsVariable() const { return this; }
|
||||
virtual const TType& getType() const { return type; }
|
||||
virtual TType& getWritableType() { assert(writable); return type; }
|
||||
virtual bool isUserType() const { return userType; }
|
||||
virtual const TConstUnionArray& getConstArray() const { return constArray; }
|
||||
virtual TConstUnionArray& getWritableConstArray() { assert(writable); return constArray; }
|
||||
virtual void setConstArray(const TConstUnionArray& array) { constArray = array; }
|
||||
virtual void setConstSubtree(TIntermTyped* subtree) { constSubtree = subtree; }
|
||||
virtual TIntermTyped* getConstSubtree() const { return constSubtree; }
|
||||
virtual void setAnonId(int i) { anonId = i; }
|
||||
virtual int getAnonId() const { return anonId; }
|
||||
|
||||
virtual void setMemberExtensions(int member, int numExts, const char* const exts[])
|
||||
{
|
||||
assert(type.isStruct());
|
||||
assert(numExts > 0);
|
||||
if (memberExtensions == nullptr) {
|
||||
memberExtensions = NewPoolObject(memberExtensions);
|
||||
memberExtensions->resize(type.getStruct()->size());
|
||||
}
|
||||
for (int e = 0; e < numExts; ++e)
|
||||
(*memberExtensions)[member].push_back(exts[e]);
|
||||
}
|
||||
virtual bool hasMemberExtensions() const { return memberExtensions != nullptr; }
|
||||
virtual int getNumMemberExtensions(int member) const
|
||||
{
|
||||
return memberExtensions == nullptr ? 0 : (int)(*memberExtensions)[member].size();
|
||||
}
|
||||
virtual const char** getMemberExtensions(int member) const { return (*memberExtensions)[member].data(); }
|
||||
|
||||
#ifndef GLSLANG_WEB
|
||||
virtual void dump(TInfoSink& infoSink, bool complete = false) const;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
explicit TVariable(const TVariable&);
|
||||
TVariable& operator=(const TVariable&);
|
||||
|
||||
TType type;
|
||||
bool userType;
|
||||
|
||||
// we are assuming that Pool Allocator will free the memory allocated to unionArray
|
||||
// when this object is destroyed
|
||||
|
||||
TConstUnionArray constArray; // for compile-time constant value
|
||||
TIntermTyped* constSubtree; // for specialization constant computation
|
||||
TVector<TExtensionList>* memberExtensions; // per-member extension list, allocated only when needed
|
||||
int anonId; // the ID used for anonymous blocks: TODO: see if uniqueId could serve a dual purpose
|
||||
};
|
||||
|
||||
//
|
||||
// The function sub-class of symbols and the parser will need to
|
||||
// share this definition of a function parameter.
|
||||
//
|
||||
struct TParameter {
|
||||
TString *name;
|
||||
TType* type;
|
||||
TIntermTyped* defaultValue;
|
||||
void copyParam(const TParameter& param)
|
||||
{
|
||||
if (param.name)
|
||||
name = NewPoolTString(param.name->c_str());
|
||||
else
|
||||
name = 0;
|
||||
type = param.type->clone();
|
||||
defaultValue = param.defaultValue;
|
||||
}
|
||||
TBuiltInVariable getDeclaredBuiltIn() const { return type->getQualifier().declaredBuiltIn; }
|
||||
};
|
||||
|
||||
//
|
||||
// The function sub-class of a symbol.
|
||||
//
|
||||
class TFunction : public TSymbol {
|
||||
public:
|
||||
explicit TFunction(TOperator o) :
|
||||
TSymbol(0),
|
||||
op(o),
|
||||
defined(false), prototyped(false), implicitThis(false), illegalImplicitThis(false), defaultParamCount(0) { }
|
||||
TFunction(const TString *name, const TType& retType, TOperator tOp = EOpNull) :
|
||||
TSymbol(name),
|
||||
mangledName(*name + '('),
|
||||
op(tOp),
|
||||
defined(false), prototyped(false), implicitThis(false), illegalImplicitThis(false), defaultParamCount(0)
|
||||
{
|
||||
returnType.shallowCopy(retType);
|
||||
declaredBuiltIn = retType.getQualifier().builtIn;
|
||||
}
|
||||
virtual TFunction* clone() const override;
|
||||
virtual ~TFunction();
|
||||
|
||||
virtual TFunction* getAsFunction() override { return this; }
|
||||
virtual const TFunction* getAsFunction() const override { return this; }
|
||||
|
||||
// Install 'p' as the (non-'this') last parameter.
|
||||
// Non-'this' parameters are reflected in both the list of parameters and the
|
||||
// mangled name.
|
||||
virtual void addParameter(TParameter& p)
|
||||
{
|
||||
assert(writable);
|
||||
parameters.push_back(p);
|
||||
p.type->appendMangledName(mangledName);
|
||||
|
||||
if (p.defaultValue != nullptr)
|
||||
defaultParamCount++;
|
||||
}
|
||||
|
||||
// Install 'this' as the first parameter.
|
||||
// 'this' is reflected in the list of parameters, but not the mangled name.
|
||||
virtual void addThisParameter(TType& type, const char* name)
|
||||
{
|
||||
TParameter p = { NewPoolTString(name), new TType, nullptr };
|
||||
p.type->shallowCopy(type);
|
||||
parameters.insert(parameters.begin(), p);
|
||||
}
|
||||
|
||||
virtual void addPrefix(const char* prefix) override
|
||||
{
|
||||
TSymbol::addPrefix(prefix);
|
||||
mangledName.insert(0, prefix);
|
||||
}
|
||||
|
||||
virtual void removePrefix(const TString& prefix)
|
||||
{
|
||||
assert(mangledName.compare(0, prefix.size(), prefix) == 0);
|
||||
mangledName.erase(0, prefix.size());
|
||||
}
|
||||
|
||||
virtual const TString& getMangledName() const override { return mangledName; }
|
||||
virtual const TType& getType() const override { return returnType; }
|
||||
virtual TBuiltInVariable getDeclaredBuiltInType() const { return declaredBuiltIn; }
|
||||
virtual TType& getWritableType() override { return returnType; }
|
||||
virtual void relateToOperator(TOperator o) { assert(writable); op = o; }
|
||||
virtual TOperator getBuiltInOp() const { return op; }
|
||||
virtual void setDefined() { assert(writable); defined = true; }
|
||||
virtual bool isDefined() const { return defined; }
|
||||
virtual void setPrototyped() { assert(writable); prototyped = true; }
|
||||
virtual bool isPrototyped() const { return prototyped; }
|
||||
virtual void setImplicitThis() { assert(writable); implicitThis = true; }
|
||||
virtual bool hasImplicitThis() const { return implicitThis; }
|
||||
virtual void setIllegalImplicitThis() { assert(writable); illegalImplicitThis = true; }
|
||||
virtual bool hasIllegalImplicitThis() const { return illegalImplicitThis; }
|
||||
|
||||
// Return total number of parameters
|
||||
virtual int getParamCount() const { return static_cast<int>(parameters.size()); }
|
||||
// Return number of parameters with default values.
|
||||
virtual int getDefaultParamCount() const { return defaultParamCount; }
|
||||
// Return number of fixed parameters (without default values)
|
||||
virtual int getFixedParamCount() const { return getParamCount() - getDefaultParamCount(); }
|
||||
|
||||
virtual TParameter& operator[](int i) { assert(writable); return parameters[i]; }
|
||||
virtual const TParameter& operator[](int i) const { return parameters[i]; }
|
||||
|
||||
#ifndef GLSLANG_WEB
|
||||
virtual void dump(TInfoSink& infoSink, bool complete = false) const override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
explicit TFunction(const TFunction&);
|
||||
TFunction& operator=(const TFunction&);
|
||||
|
||||
typedef TVector<TParameter> TParamList;
|
||||
TParamList parameters;
|
||||
TType returnType;
|
||||
TBuiltInVariable declaredBuiltIn;
|
||||
|
||||
TString mangledName;
|
||||
TOperator op;
|
||||
bool defined;
|
||||
bool prototyped;
|
||||
bool implicitThis; // True if this function is allowed to see all members of 'this'
|
||||
bool illegalImplicitThis; // True if this function is not supposed to have access to dynamic members of 'this',
|
||||
// even if it finds member variables in the symbol table.
|
||||
// This is important for a static member function that has member variables in scope,
|
||||
// but is not allowed to use them, or see hidden symbols instead.
|
||||
int defaultParamCount;
|
||||
};
|
||||
|
||||
//
|
||||
// Members of anonymous blocks are a kind of TSymbol. They are not hidden in
|
||||
// the symbol table behind a container; rather they are visible and point to
|
||||
// their anonymous container. (The anonymous container is found through the
|
||||
// member, not the other way around.)
|
||||
//
|
||||
class TAnonMember : public TSymbol {
|
||||
public:
|
||||
TAnonMember(const TString* n, unsigned int m, TVariable& a, int an) : TSymbol(n), anonContainer(a), memberNumber(m), anonId(an) { }
|
||||
virtual TAnonMember* clone() const override;
|
||||
virtual ~TAnonMember() { }
|
||||
|
||||
virtual const TAnonMember* getAsAnonMember() const override { return this; }
|
||||
virtual const TVariable& getAnonContainer() const { return anonContainer; }
|
||||
virtual unsigned int getMemberNumber() const { return memberNumber; }
|
||||
|
||||
virtual const TType& getType() const override
|
||||
{
|
||||
const TTypeList& types = *anonContainer.getType().getStruct();
|
||||
return *types[memberNumber].type;
|
||||
}
|
||||
|
||||
virtual TType& getWritableType() override
|
||||
{
|
||||
assert(writable);
|
||||
const TTypeList& types = *anonContainer.getType().getStruct();
|
||||
return *types[memberNumber].type;
|
||||
}
|
||||
|
||||
virtual void setExtensions(int numExts, const char* const exts[]) override
|
||||
{
|
||||
anonContainer.setMemberExtensions(memberNumber, numExts, exts);
|
||||
}
|
||||
virtual int getNumExtensions() const override { return anonContainer.getNumMemberExtensions(memberNumber); }
|
||||
virtual const char** getExtensions() const override { return anonContainer.getMemberExtensions(memberNumber); }
|
||||
|
||||
virtual int getAnonId() const { return anonId; }
|
||||
#ifndef GLSLANG_WEB
|
||||
virtual void dump(TInfoSink& infoSink, bool complete = false) const override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
explicit TAnonMember(const TAnonMember&);
|
||||
TAnonMember& operator=(const TAnonMember&);
|
||||
|
||||
TVariable& anonContainer;
|
||||
unsigned int memberNumber;
|
||||
int anonId;
|
||||
};
|
||||
|
||||
class TSymbolTableLevel {
|
||||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
TSymbolTableLevel() : defaultPrecision(0), anonId(0), thisLevel(false) { }
|
||||
~TSymbolTableLevel();
|
||||
|
||||
bool insert(TSymbol& symbol, bool separateNameSpaces)
|
||||
{
|
||||
//
|
||||
// returning true means symbol was added to the table with no semantic errors
|
||||
//
|
||||
const TString& name = symbol.getName();
|
||||
if (name == "") {
|
||||
symbol.getAsVariable()->setAnonId(anonId++);
|
||||
// An empty name means an anonymous container, exposing its members to the external scope.
|
||||
// Give it a name and insert its members in the symbol table, pointing to the container.
|
||||
char buf[20];
|
||||
snprintf(buf, 20, "%s%d", AnonymousPrefix, symbol.getAsVariable()->getAnonId());
|
||||
symbol.changeName(NewPoolTString(buf));
|
||||
|
||||
return insertAnonymousMembers(symbol, 0);
|
||||
} else {
|
||||
// Check for redefinition errors:
|
||||
// - STL itself will tell us if there is a direct name collision, with name mangling, at this level
|
||||
// - additionally, check for function-redefining-variable name collisions
|
||||
const TString& insertName = symbol.getMangledName();
|
||||
if (symbol.getAsFunction()) {
|
||||
// make sure there isn't a variable of this name
|
||||
if (! separateNameSpaces && level.find(name) != level.end())
|
||||
return false;
|
||||
|
||||
// insert, and whatever happens is okay
|
||||
level.insert(tLevelPair(insertName, &symbol));
|
||||
|
||||
return true;
|
||||
} else
|
||||
return level.insert(tLevelPair(insertName, &symbol)).second;
|
||||
}
|
||||
}
|
||||
|
||||
// Add more members to an already inserted aggregate object
|
||||
bool amend(TSymbol& symbol, int firstNewMember)
|
||||
{
|
||||
// See insert() for comments on basic explanation of insert.
|
||||
// This operates similarly, but more simply.
|
||||
// Only supporting amend of anonymous blocks so far.
|
||||
if (IsAnonymous(symbol.getName()))
|
||||
return insertAnonymousMembers(symbol, firstNewMember);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool insertAnonymousMembers(TSymbol& symbol, int firstMember)
|
||||
{
|
||||
const TTypeList& types = *symbol.getAsVariable()->getType().getStruct();
|
||||
for (unsigned int m = firstMember; m < types.size(); ++m) {
|
||||
TAnonMember* member = new TAnonMember(&types[m].type->getFieldName(), m, *symbol.getAsVariable(), symbol.getAsVariable()->getAnonId());
|
||||
if (! level.insert(tLevelPair(member->getMangledName(), member)).second)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TSymbol* find(const TString& name) const
|
||||
{
|
||||
tLevel::const_iterator it = level.find(name);
|
||||
if (it == level.end())
|
||||
return 0;
|
||||
else
|
||||
return (*it).second;
|
||||
}
|
||||
|
||||
void findFunctionNameList(const TString& name, TVector<const TFunction*>& list)
|
||||
{
|
||||
size_t parenAt = name.find_first_of('(');
|
||||
TString base(name, 0, parenAt + 1);
|
||||
|
||||
tLevel::const_iterator begin = level.lower_bound(base);
|
||||
base[parenAt] = ')'; // assume ')' is lexically after '('
|
||||
tLevel::const_iterator end = level.upper_bound(base);
|
||||
for (tLevel::const_iterator it = begin; it != end; ++it)
|
||||
list.push_back(it->second->getAsFunction());
|
||||
}
|
||||
|
||||
// See if there is already a function in the table having the given non-function-style name.
|
||||
bool hasFunctionName(const TString& name) const
|
||||
{
|
||||
tLevel::const_iterator candidate = level.lower_bound(name);
|
||||
if (candidate != level.end()) {
|
||||
const TString& candidateName = (*candidate).first;
|
||||
TString::size_type parenAt = candidateName.find_first_of('(');
|
||||
if (parenAt != candidateName.npos && candidateName.compare(0, parenAt, name) == 0)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// See if there is a variable at this level having the given non-function-style name.
|
||||
// Return true if name is found, and set variable to true if the name was a variable.
|
||||
bool findFunctionVariableName(const TString& name, bool& variable) const
|
||||
{
|
||||
tLevel::const_iterator candidate = level.lower_bound(name);
|
||||
if (candidate != level.end()) {
|
||||
const TString& candidateName = (*candidate).first;
|
||||
TString::size_type parenAt = candidateName.find_first_of('(');
|
||||
if (parenAt == candidateName.npos) {
|
||||
// not a mangled name
|
||||
if (candidateName == name) {
|
||||
// found a variable name match
|
||||
variable = true;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// a mangled name
|
||||
if (candidateName.compare(0, parenAt, name) == 0) {
|
||||
// found a function name match
|
||||
variable = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use this to do a lazy 'push' of precision defaults the first time
|
||||
// a precision statement is seen in a new scope. Leave it at 0 for
|
||||
// when no push was needed. Thus, it is not the current defaults,
|
||||
// it is what to restore the defaults to when popping a level.
|
||||
void setPreviousDefaultPrecisions(const TPrecisionQualifier *p)
|
||||
{
|
||||
// can call multiple times at one scope, will only latch on first call,
|
||||
// as we're tracking the previous scope's values, not the current values
|
||||
if (defaultPrecision != 0)
|
||||
return;
|
||||
|
||||
defaultPrecision = new TPrecisionQualifier[EbtNumTypes];
|
||||
for (int t = 0; t < EbtNumTypes; ++t)
|
||||
defaultPrecision[t] = p[t];
|
||||
}
|
||||
|
||||
void getPreviousDefaultPrecisions(TPrecisionQualifier *p)
|
||||
{
|
||||
// can be called for table level pops that didn't set the
|
||||
// defaults
|
||||
if (defaultPrecision == 0 || p == 0)
|
||||
return;
|
||||
|
||||
for (int t = 0; t < EbtNumTypes; ++t)
|
||||
p[t] = defaultPrecision[t];
|
||||
}
|
||||
|
||||
void relateToOperator(const char* name, TOperator op);
|
||||
void setFunctionExtensions(const char* name, int num, const char* const extensions[]);
|
||||
#ifndef GLSLANG_WEB
|
||||
void dump(TInfoSink& infoSink, bool complete = false) const;
|
||||
#endif
|
||||
TSymbolTableLevel* clone() const;
|
||||
void readOnly();
|
||||
|
||||
void setThisLevel() { thisLevel = true; }
|
||||
bool isThisLevel() const { return thisLevel; }
|
||||
|
||||
protected:
|
||||
explicit TSymbolTableLevel(TSymbolTableLevel&);
|
||||
TSymbolTableLevel& operator=(TSymbolTableLevel&);
|
||||
|
||||
typedef std::map<TString, TSymbol*, std::less<TString>, pool_allocator<std::pair<const TString, TSymbol*> > > tLevel;
|
||||
typedef const tLevel::value_type tLevelPair;
|
||||
typedef std::pair<tLevel::iterator, bool> tInsertResult;
|
||||
|
||||
tLevel level; // named mappings
|
||||
TPrecisionQualifier *defaultPrecision;
|
||||
int anonId;
|
||||
bool thisLevel; // True if this level of the symbol table is a structure scope containing member function
|
||||
// that are supposed to see anonymous access to member variables.
|
||||
};
|
||||
|
||||
class TSymbolTable {
|
||||
public:
|
||||
TSymbolTable() : uniqueId(0), noBuiltInRedeclarations(false), separateNameSpaces(false), adoptedLevels(0)
|
||||
{
|
||||
//
|
||||
// This symbol table cannot be used until push() is called.
|
||||
//
|
||||
}
|
||||
~TSymbolTable()
|
||||
{
|
||||
// this can be called explicitly; safest to code it so it can be called multiple times
|
||||
|
||||
// don't deallocate levels passed in from elsewhere
|
||||
while (table.size() > adoptedLevels)
|
||||
pop(0);
|
||||
}
|
||||
|
||||
void adoptLevels(TSymbolTable& symTable)
|
||||
{
|
||||
for (unsigned int level = 0; level < symTable.table.size(); ++level) {
|
||||
table.push_back(symTable.table[level]);
|
||||
++adoptedLevels;
|
||||
}
|
||||
uniqueId = symTable.uniqueId;
|
||||
noBuiltInRedeclarations = symTable.noBuiltInRedeclarations;
|
||||
separateNameSpaces = symTable.separateNameSpaces;
|
||||
}
|
||||
|
||||
//
|
||||
// While level adopting is generic, the methods below enact a the following
|
||||
// convention for levels:
|
||||
// 0: common built-ins shared across all stages, all compiles, only one copy for all symbol tables
|
||||
// 1: per-stage built-ins, shared across all compiles, but a different copy per stage
|
||||
// 2: built-ins specific to a compile, like resources that are context-dependent, or redeclared built-ins
|
||||
// 3: user-shader globals
|
||||
//
|
||||
protected:
|
||||
static const int globalLevel = 3;
|
||||
bool isSharedLevel(int level) { return level <= 1; } // exclude all per-compile levels
|
||||
bool isBuiltInLevel(int level) { return level <= 2; } // exclude user globals
|
||||
bool isGlobalLevel(int level) { return level <= globalLevel; } // include user globals
|
||||
public:
|
||||
bool isEmpty() { return table.size() == 0; }
|
||||
bool atBuiltInLevel() { return isBuiltInLevel(currentLevel()); }
|
||||
bool atGlobalLevel() { return isGlobalLevel(currentLevel()); }
|
||||
|
||||
void setNoBuiltInRedeclarations() { noBuiltInRedeclarations = true; }
|
||||
void setSeparateNameSpaces() { separateNameSpaces = true; }
|
||||
|
||||
void push()
|
||||
{
|
||||
table.push_back(new TSymbolTableLevel);
|
||||
}
|
||||
|
||||
// Make a new symbol-table level to represent the scope introduced by a structure
|
||||
// containing member functions, such that the member functions can find anonymous
|
||||
// references to member variables.
|
||||
//
|
||||
// 'thisSymbol' should have a name of "" to trigger anonymous structure-member
|
||||
// symbol finds.
|
||||
void pushThis(TSymbol& thisSymbol)
|
||||
{
|
||||
assert(thisSymbol.getName().size() == 0);
|
||||
table.push_back(new TSymbolTableLevel);
|
||||
table.back()->setThisLevel();
|
||||
insert(thisSymbol);
|
||||
}
|
||||
|
||||
void pop(TPrecisionQualifier *p)
|
||||
{
|
||||
table[currentLevel()]->getPreviousDefaultPrecisions(p);
|
||||
delete table.back();
|
||||
table.pop_back();
|
||||
}
|
||||
|
||||
//
|
||||
// Insert a visible symbol into the symbol table so it can
|
||||
// be found later by name.
|
||||
//
|
||||
// Returns false if the was a name collision.
|
||||
//
|
||||
bool insert(TSymbol& symbol)
|
||||
{
|
||||
symbol.setUniqueId(++uniqueId);
|
||||
|
||||
// make sure there isn't a function of this variable name
|
||||
if (! separateNameSpaces && ! symbol.getAsFunction() && table[currentLevel()]->hasFunctionName(symbol.getName()))
|
||||
return false;
|
||||
|
||||
// check for not overloading or redefining a built-in function
|
||||
if (noBuiltInRedeclarations) {
|
||||
if (atGlobalLevel() && currentLevel() > 0) {
|
||||
if (table[0]->hasFunctionName(symbol.getName()))
|
||||
return false;
|
||||
if (currentLevel() > 1 && table[1]->hasFunctionName(symbol.getName()))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return table[currentLevel()]->insert(symbol, separateNameSpaces);
|
||||
}
|
||||
|
||||
// Add more members to an already inserted aggregate object
|
||||
bool amend(TSymbol& symbol, int firstNewMember)
|
||||
{
|
||||
// See insert() for comments on basic explanation of insert.
|
||||
// This operates similarly, but more simply.
|
||||
return table[currentLevel()]->amend(symbol, firstNewMember);
|
||||
}
|
||||
|
||||
//
|
||||
// To allocate an internal temporary, which will need to be uniquely
|
||||
// identified by the consumer of the AST, but never need to
|
||||
// found by doing a symbol table search by name, hence allowed an
|
||||
// arbitrary name in the symbol with no worry of collision.
|
||||
//
|
||||
void makeInternalVariable(TSymbol& symbol)
|
||||
{
|
||||
symbol.setUniqueId(++uniqueId);
|
||||
}
|
||||
|
||||
//
|
||||
// Copy a variable or anonymous member's structure from a shared level so that
|
||||
// it can be added (soon after return) to the symbol table where it can be
|
||||
// modified without impacting other users of the shared table.
|
||||
//
|
||||
TSymbol* copyUpDeferredInsert(TSymbol* shared)
|
||||
{
|
||||
if (shared->getAsVariable()) {
|
||||
TSymbol* copy = shared->clone();
|
||||
copy->setUniqueId(shared->getUniqueId());
|
||||
return copy;
|
||||
} else {
|
||||
const TAnonMember* anon = shared->getAsAnonMember();
|
||||
assert(anon);
|
||||
TVariable* container = anon->getAnonContainer().clone();
|
||||
container->changeName(NewPoolTString(""));
|
||||
container->setUniqueId(anon->getAnonContainer().getUniqueId());
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
||||
TSymbol* copyUp(TSymbol* shared)
|
||||
{
|
||||
TSymbol* copy = copyUpDeferredInsert(shared);
|
||||
table[globalLevel]->insert(*copy, separateNameSpaces);
|
||||
if (shared->getAsVariable())
|
||||
return copy;
|
||||
else {
|
||||
// return the copy of the anonymous member
|
||||
return table[globalLevel]->find(shared->getName());
|
||||
}
|
||||
}
|
||||
|
||||
// Normal find of a symbol, that can optionally say whether the symbol was found
|
||||
// at a built-in level or the current top-scope level.
|
||||
TSymbol* find(const TString& name, bool* builtIn = 0, bool* currentScope = 0, int* thisDepthP = 0)
|
||||
{
|
||||
int level = currentLevel();
|
||||
TSymbol* symbol;
|
||||
int thisDepth = 0;
|
||||
do {
|
||||
if (table[level]->isThisLevel())
|
||||
++thisDepth;
|
||||
symbol = table[level]->find(name);
|
||||
--level;
|
||||
} while (symbol == nullptr && level >= 0);
|
||||
level++;
|
||||
if (builtIn)
|
||||
*builtIn = isBuiltInLevel(level);
|
||||
if (currentScope)
|
||||
*currentScope = isGlobalLevel(currentLevel()) || level == currentLevel(); // consider shared levels as "current scope" WRT user globals
|
||||
if (thisDepthP != nullptr) {
|
||||
if (! table[level]->isThisLevel())
|
||||
thisDepth = 0;
|
||||
*thisDepthP = thisDepth;
|
||||
}
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
// Find of a symbol that returns how many layers deep of nested
|
||||
// structures-with-member-functions ('this' scopes) deep the symbol was
|
||||
// found in.
|
||||
TSymbol* find(const TString& name, int& thisDepth)
|
||||
{
|
||||
int level = currentLevel();
|
||||
TSymbol* symbol;
|
||||
thisDepth = 0;
|
||||
do {
|
||||
if (table[level]->isThisLevel())
|
||||
++thisDepth;
|
||||
symbol = table[level]->find(name);
|
||||
--level;
|
||||
} while (symbol == 0 && level >= 0);
|
||||
|
||||
if (! table[level + 1]->isThisLevel())
|
||||
thisDepth = 0;
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
bool isFunctionNameVariable(const TString& name) const
|
||||
{
|
||||
if (separateNameSpaces)
|
||||
return false;
|
||||
|
||||
int level = currentLevel();
|
||||
do {
|
||||
bool variable;
|
||||
bool found = table[level]->findFunctionVariableName(name, variable);
|
||||
if (found)
|
||||
return variable;
|
||||
--level;
|
||||
} while (level >= 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void findFunctionNameList(const TString& name, TVector<const TFunction*>& list, bool& builtIn)
|
||||
{
|
||||
// For user levels, return the set found in the first scope with a match
|
||||
builtIn = false;
|
||||
int level = currentLevel();
|
||||
do {
|
||||
table[level]->findFunctionNameList(name, list);
|
||||
--level;
|
||||
} while (list.empty() && level >= globalLevel);
|
||||
|
||||
if (! list.empty())
|
||||
return;
|
||||
|
||||
// Gather across all built-in levels; they don't hide each other
|
||||
builtIn = true;
|
||||
do {
|
||||
table[level]->findFunctionNameList(name, list);
|
||||
--level;
|
||||
} while (level >= 0);
|
||||
}
|
||||
|
||||
void relateToOperator(const char* name, TOperator op)
|
||||
{
|
||||
for (unsigned int level = 0; level < table.size(); ++level)
|
||||
table[level]->relateToOperator(name, op);
|
||||
}
|
||||
|
||||
void setFunctionExtensions(const char* name, int num, const char* const extensions[])
|
||||
{
|
||||
for (unsigned int level = 0; level < table.size(); ++level)
|
||||
table[level]->setFunctionExtensions(name, num, extensions);
|
||||
}
|
||||
|
||||
void setVariableExtensions(const char* name, int numExts, const char* const extensions[])
|
||||
{
|
||||
TSymbol* symbol = find(TString(name));
|
||||
if (symbol == nullptr)
|
||||
return;
|
||||
|
||||
symbol->setExtensions(numExts, extensions);
|
||||
}
|
||||
|
||||
void setVariableExtensions(const char* blockName, const char* name, int numExts, const char* const extensions[])
|
||||
{
|
||||
TSymbol* symbol = find(TString(blockName));
|
||||
if (symbol == nullptr)
|
||||
return;
|
||||
TVariable* variable = symbol->getAsVariable();
|
||||
assert(variable != nullptr);
|
||||
|
||||
const TTypeList& structure = *variable->getAsVariable()->getType().getStruct();
|
||||
for (int member = 0; member < (int)structure.size(); ++member) {
|
||||
if (structure[member].type->getFieldName().compare(name) == 0) {
|
||||
variable->setMemberExtensions(member, numExts, extensions);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int getMaxSymbolId() { return uniqueId; }
|
||||
#ifndef GLSLANG_WEB
|
||||
void dump(TInfoSink& infoSink, bool complete = false) const;
|
||||
#endif
|
||||
void copyTable(const TSymbolTable& copyOf);
|
||||
|
||||
void setPreviousDefaultPrecisions(TPrecisionQualifier *p) { table[currentLevel()]->setPreviousDefaultPrecisions(p); }
|
||||
|
||||
void readOnly()
|
||||
{
|
||||
for (unsigned int level = 0; level < table.size(); ++level)
|
||||
table[level]->readOnly();
|
||||
}
|
||||
|
||||
protected:
|
||||
TSymbolTable(TSymbolTable&);
|
||||
TSymbolTable& operator=(TSymbolTableLevel&);
|
||||
|
||||
int currentLevel() const { return static_cast<int>(table.size()) - 1; }
|
||||
|
||||
std::vector<TSymbolTableLevel*> table;
|
||||
int uniqueId; // for unique identification in code generation
|
||||
bool noBuiltInRedeclarations;
|
||||
bool separateNameSpaces;
|
||||
unsigned int adoptedLevels;
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _SYMBOL_TABLE_INCLUDED_
|
||||
|
|
@ -0,0 +1,332 @@
|
|||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2012-2013 LunarG, Inc.
|
||||
// Copyright (C) 2017 ARM Limited.
|
||||
// Copyright (C) 2015-2018 Google, Inc.
|
||||
// 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 _VERSIONS_INCLUDED_
|
||||
#define _VERSIONS_INCLUDED_
|
||||
|
||||
#define LAST_ELEMENT_MARKER(x) x
|
||||
|
||||
//
|
||||
// Help manage multiple profiles, versions, extensions etc.
|
||||
//
|
||||
|
||||
//
|
||||
// Profiles are set up for masking operations, so queries can be done on multiple
|
||||
// profiles at the same time.
|
||||
//
|
||||
// Don't maintain an ordinal set of enums (0,1,2,3...) to avoid all possible
|
||||
// defects from mixing the two different forms.
|
||||
//
|
||||
typedef enum : unsigned {
|
||||
EBadProfile = 0,
|
||||
ENoProfile = (1 << 0), // only for desktop, before profiles showed up
|
||||
ECoreProfile = (1 << 1),
|
||||
ECompatibilityProfile = (1 << 2),
|
||||
EEsProfile = (1 << 3),
|
||||
LAST_ELEMENT_MARKER(EProfileCount),
|
||||
} EProfile;
|
||||
|
||||
namespace glslang {
|
||||
|
||||
//
|
||||
// Map from profile enum to externally readable text name.
|
||||
//
|
||||
inline const char* ProfileName(EProfile profile)
|
||||
{
|
||||
switch (profile) {
|
||||
case ENoProfile: return "none";
|
||||
case ECoreProfile: return "core";
|
||||
case ECompatibilityProfile: return "compatibility";
|
||||
case EEsProfile: return "es";
|
||||
default: return "unknown profile";
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// What source rules, validation rules, target language, etc. are needed or
|
||||
// desired for SPIR-V?
|
||||
//
|
||||
// 0 means a target or rule set is not enabled (ignore rules from that entity).
|
||||
// Non-0 means to apply semantic rules arising from that version of its rule set.
|
||||
// The union of all requested rule sets will be applied.
|
||||
//
|
||||
struct SpvVersion {
|
||||
SpvVersion() : spv(0), vulkanGlsl(0), vulkan(0), openGl(0) {}
|
||||
unsigned int spv; // the version of SPIR-V to target, as defined by "word 1" of the SPIR-V binary header
|
||||
int vulkanGlsl; // the version of GLSL semantics for Vulkan, from GL_KHR_vulkan_glsl, for "#define VULKAN XXX"
|
||||
int vulkan; // the version of Vulkan, for which SPIR-V execution environment rules to use
|
||||
int openGl; // the version of GLSL semantics for OpenGL, from GL_ARB_gl_spirv, for "#define GL_SPIRV XXX"
|
||||
};
|
||||
|
||||
//
|
||||
// The behaviors from the GLSL "#extension extension_name : behavior"
|
||||
//
|
||||
typedef enum {
|
||||
EBhMissing = 0,
|
||||
EBhRequire,
|
||||
EBhEnable,
|
||||
EBhWarn,
|
||||
EBhDisable,
|
||||
EBhDisablePartial // use as initial state of an extension that is only partially implemented
|
||||
} TExtensionBehavior;
|
||||
|
||||
//
|
||||
// Symbolic names for extensions. Strings may be directly used when calling the
|
||||
// functions, but better to have the compiler do spelling checks.
|
||||
//
|
||||
const char* const E_GL_OES_texture_3D = "GL_OES_texture_3D";
|
||||
const char* const E_GL_OES_standard_derivatives = "GL_OES_standard_derivatives";
|
||||
const char* const E_GL_EXT_frag_depth = "GL_EXT_frag_depth";
|
||||
const char* const E_GL_OES_EGL_image_external = "GL_OES_EGL_image_external";
|
||||
const char* const E_GL_OES_EGL_image_external_essl3 = "GL_OES_EGL_image_external_essl3";
|
||||
const char* const E_GL_EXT_YUV_target = "GL_EXT_YUV_target";
|
||||
const char* const E_GL_EXT_shader_texture_lod = "GL_EXT_shader_texture_lod";
|
||||
const char* const E_GL_EXT_shadow_samplers = "GL_EXT_shadow_samplers";
|
||||
|
||||
const char* const E_GL_ARB_texture_rectangle = "GL_ARB_texture_rectangle";
|
||||
const char* const E_GL_3DL_array_objects = "GL_3DL_array_objects";
|
||||
const char* const E_GL_ARB_shading_language_420pack = "GL_ARB_shading_language_420pack";
|
||||
const char* const E_GL_ARB_texture_gather = "GL_ARB_texture_gather";
|
||||
const char* const E_GL_ARB_gpu_shader5 = "GL_ARB_gpu_shader5";
|
||||
const char* const E_GL_ARB_separate_shader_objects = "GL_ARB_separate_shader_objects";
|
||||
const char* const E_GL_ARB_compute_shader = "GL_ARB_compute_shader";
|
||||
const char* const E_GL_ARB_tessellation_shader = "GL_ARB_tessellation_shader";
|
||||
const char* const E_GL_ARB_enhanced_layouts = "GL_ARB_enhanced_layouts";
|
||||
const char* const E_GL_ARB_texture_cube_map_array = "GL_ARB_texture_cube_map_array";
|
||||
const char* const E_GL_ARB_texture_multisample = "GL_ARB_texture_multisample";
|
||||
const char* const E_GL_ARB_shader_texture_lod = "GL_ARB_shader_texture_lod";
|
||||
const char* const E_GL_ARB_explicit_attrib_location = "GL_ARB_explicit_attrib_location";
|
||||
const char* const E_GL_ARB_explicit_uniform_location = "GL_ARB_explicit_uniform_location";
|
||||
const char* const E_GL_ARB_shader_image_load_store = "GL_ARB_shader_image_load_store";
|
||||
const char* const E_GL_ARB_shader_atomic_counters = "GL_ARB_shader_atomic_counters";
|
||||
const char* const E_GL_ARB_shader_draw_parameters = "GL_ARB_shader_draw_parameters";
|
||||
const char* const E_GL_ARB_shader_group_vote = "GL_ARB_shader_group_vote";
|
||||
const char* const E_GL_ARB_derivative_control = "GL_ARB_derivative_control";
|
||||
const char* const E_GL_ARB_shader_texture_image_samples = "GL_ARB_shader_texture_image_samples";
|
||||
const char* const E_GL_ARB_viewport_array = "GL_ARB_viewport_array";
|
||||
const char* const E_GL_ARB_gpu_shader_int64 = "GL_ARB_gpu_shader_int64";
|
||||
const char* const E_GL_ARB_gpu_shader_fp64 = "GL_ARB_gpu_shader_fp64";
|
||||
const char* const E_GL_ARB_shader_ballot = "GL_ARB_shader_ballot";
|
||||
const char* const E_GL_ARB_sparse_texture2 = "GL_ARB_sparse_texture2";
|
||||
const char* const E_GL_ARB_sparse_texture_clamp = "GL_ARB_sparse_texture_clamp";
|
||||
const char* const E_GL_ARB_shader_stencil_export = "GL_ARB_shader_stencil_export";
|
||||
// const char* const E_GL_ARB_cull_distance = "GL_ARB_cull_distance"; // present for 4.5, but need extension control over block members
|
||||
const char* const E_GL_ARB_post_depth_coverage = "GL_ARB_post_depth_coverage";
|
||||
const char* const E_GL_ARB_shader_viewport_layer_array = "GL_ARB_shader_viewport_layer_array";
|
||||
const char* const E_GL_ARB_fragment_shader_interlock = "GL_ARB_fragment_shader_interlock";
|
||||
const char* const E_GL_ARB_shader_clock = "GL_ARB_shader_clock";
|
||||
const char* const E_GL_ARB_uniform_buffer_object = "GL_ARB_uniform_buffer_object";
|
||||
const char* const E_GL_ARB_sample_shading = "GL_ARB_sample_shading";
|
||||
const char* const E_GL_ARB_shader_bit_encoding = "GL_ARB_shader_bit_encoding";
|
||||
const char* const E_GL_ARB_shader_image_size = "GL_ARB_shader_image_size";
|
||||
const char* const E_GL_ARB_shader_storage_buffer_object = "GL_ARB_shader_storage_buffer_object";
|
||||
const char* const E_GL_ARB_shading_language_packing = "GL_ARB_shading_language_packing";
|
||||
const char* const E_GL_ARB_texture_query_lod = "GL_ARB_texture_query_lod";
|
||||
const char* const E_GL_ARB_vertex_attrib_64bit = "GL_ARB_vertex_attrib_64bit";
|
||||
|
||||
const char* const E_GL_KHR_shader_subgroup_basic = "GL_KHR_shader_subgroup_basic";
|
||||
const char* const E_GL_KHR_shader_subgroup_vote = "GL_KHR_shader_subgroup_vote";
|
||||
const char* const E_GL_KHR_shader_subgroup_arithmetic = "GL_KHR_shader_subgroup_arithmetic";
|
||||
const char* const E_GL_KHR_shader_subgroup_ballot = "GL_KHR_shader_subgroup_ballot";
|
||||
const char* const E_GL_KHR_shader_subgroup_shuffle = "GL_KHR_shader_subgroup_shuffle";
|
||||
const char* const E_GL_KHR_shader_subgroup_shuffle_relative = "GL_KHR_shader_subgroup_shuffle_relative";
|
||||
const char* const E_GL_KHR_shader_subgroup_clustered = "GL_KHR_shader_subgroup_clustered";
|
||||
const char* const E_GL_KHR_shader_subgroup_quad = "GL_KHR_shader_subgroup_quad";
|
||||
const char* const E_GL_KHR_memory_scope_semantics = "GL_KHR_memory_scope_semantics";
|
||||
|
||||
const char* const E_GL_EXT_shader_atomic_int64 = "GL_EXT_shader_atomic_int64";
|
||||
|
||||
const char* const E_GL_EXT_shader_non_constant_global_initializers = "GL_EXT_shader_non_constant_global_initializers";
|
||||
const char* const E_GL_EXT_shader_image_load_formatted = "GL_EXT_shader_image_load_formatted";
|
||||
|
||||
const char* const E_GL_EXT_shader_16bit_storage = "GL_EXT_shader_16bit_storage";
|
||||
const char* const E_GL_EXT_shader_8bit_storage = "GL_EXT_shader_8bit_storage";
|
||||
|
||||
|
||||
// EXT extensions
|
||||
const char* const E_GL_EXT_device_group = "GL_EXT_device_group";
|
||||
const char* const E_GL_EXT_multiview = "GL_EXT_multiview";
|
||||
const char* const E_GL_EXT_post_depth_coverage = "GL_EXT_post_depth_coverage";
|
||||
const char* const E_GL_EXT_control_flow_attributes = "GL_EXT_control_flow_attributes";
|
||||
const char* const E_GL_EXT_nonuniform_qualifier = "GL_EXT_nonuniform_qualifier";
|
||||
const char* const E_GL_EXT_samplerless_texture_functions = "GL_EXT_samplerless_texture_functions";
|
||||
const char* const E_GL_EXT_scalar_block_layout = "GL_EXT_scalar_block_layout";
|
||||
const char* const E_GL_EXT_fragment_invocation_density = "GL_EXT_fragment_invocation_density";
|
||||
const char* const E_GL_EXT_buffer_reference = "GL_EXT_buffer_reference";
|
||||
const char* const E_GL_EXT_buffer_reference2 = "GL_EXT_buffer_reference2";
|
||||
const char* const E_GL_EXT_buffer_reference_uvec2 = "GL_EXT_buffer_reference_uvec2";
|
||||
const char* const E_GL_EXT_demote_to_helper_invocation = "GL_EXT_demote_to_helper_invocation";
|
||||
const char* const E_GL_EXT_shader_realtime_clock = "GL_EXT_shader_realtime_clock";
|
||||
const char* const E_GL_EXT_debug_printf = "GL_EXT_debug_printf";
|
||||
const char* const E_GL_EXT_ray_tracing = "GL_EXT_ray_tracing";
|
||||
const char* const E_GL_EXT_ray_query = "GL_EXT_ray_query";
|
||||
const char* const E_GL_EXT_ray_flags_primitive_culling = "GL_EXT_ray_flags_primitive_culling";
|
||||
const char* const E_GL_EXT_blend_func_extended = "GL_EXT_blend_func_extended";
|
||||
const char* const E_GL_EXT_shader_implicit_conversions = "GL_EXT_shader_implicit_conversions";
|
||||
|
||||
// Arrays of extensions for the above viewportEXTs duplications
|
||||
|
||||
const char* const post_depth_coverageEXTs[] = { E_GL_ARB_post_depth_coverage, E_GL_EXT_post_depth_coverage };
|
||||
const int Num_post_depth_coverageEXTs = sizeof(post_depth_coverageEXTs) / sizeof(post_depth_coverageEXTs[0]);
|
||||
|
||||
// OVR extensions
|
||||
const char* const E_GL_OVR_multiview = "GL_OVR_multiview";
|
||||
const char* const E_GL_OVR_multiview2 = "GL_OVR_multiview2";
|
||||
|
||||
const char* const OVR_multiview_EXTs[] = { E_GL_OVR_multiview, E_GL_OVR_multiview2 };
|
||||
const int Num_OVR_multiview_EXTs = sizeof(OVR_multiview_EXTs) / sizeof(OVR_multiview_EXTs[0]);
|
||||
|
||||
// #line and #include
|
||||
const char* const E_GL_GOOGLE_cpp_style_line_directive = "GL_GOOGLE_cpp_style_line_directive";
|
||||
const char* const E_GL_GOOGLE_include_directive = "GL_GOOGLE_include_directive";
|
||||
|
||||
const char* const E_GL_AMD_shader_ballot = "GL_AMD_shader_ballot";
|
||||
const char* const E_GL_AMD_shader_trinary_minmax = "GL_AMD_shader_trinary_minmax";
|
||||
const char* const E_GL_AMD_shader_explicit_vertex_parameter = "GL_AMD_shader_explicit_vertex_parameter";
|
||||
const char* const E_GL_AMD_gcn_shader = "GL_AMD_gcn_shader";
|
||||
const char* const E_GL_AMD_gpu_shader_half_float = "GL_AMD_gpu_shader_half_float";
|
||||
const char* const E_GL_AMD_texture_gather_bias_lod = "GL_AMD_texture_gather_bias_lod";
|
||||
const char* const E_GL_AMD_gpu_shader_int16 = "GL_AMD_gpu_shader_int16";
|
||||
const char* const E_GL_AMD_shader_image_load_store_lod = "GL_AMD_shader_image_load_store_lod";
|
||||
const char* const E_GL_AMD_shader_fragment_mask = "GL_AMD_shader_fragment_mask";
|
||||
const char* const E_GL_AMD_gpu_shader_half_float_fetch = "GL_AMD_gpu_shader_half_float_fetch";
|
||||
|
||||
const char* const E_GL_INTEL_shader_integer_functions2 = "GL_INTEL_shader_integer_functions2";
|
||||
|
||||
const char* const E_GL_NV_sample_mask_override_coverage = "GL_NV_sample_mask_override_coverage";
|
||||
const char* const E_SPV_NV_geometry_shader_passthrough = "GL_NV_geometry_shader_passthrough";
|
||||
const char* const E_GL_NV_viewport_array2 = "GL_NV_viewport_array2";
|
||||
const char* const E_GL_NV_stereo_view_rendering = "GL_NV_stereo_view_rendering";
|
||||
const char* const E_GL_NVX_multiview_per_view_attributes = "GL_NVX_multiview_per_view_attributes";
|
||||
const char* const E_GL_NV_shader_atomic_int64 = "GL_NV_shader_atomic_int64";
|
||||
const char* const E_GL_NV_conservative_raster_underestimation = "GL_NV_conservative_raster_underestimation";
|
||||
const char* const E_GL_NV_shader_noperspective_interpolation = "GL_NV_shader_noperspective_interpolation";
|
||||
const char* const E_GL_NV_shader_subgroup_partitioned = "GL_NV_shader_subgroup_partitioned";
|
||||
const char* const E_GL_NV_shading_rate_image = "GL_NV_shading_rate_image";
|
||||
const char* const E_GL_NV_ray_tracing = "GL_NV_ray_tracing";
|
||||
const char* const E_GL_NV_fragment_shader_barycentric = "GL_NV_fragment_shader_barycentric";
|
||||
const char* const E_GL_NV_compute_shader_derivatives = "GL_NV_compute_shader_derivatives";
|
||||
const char* const E_GL_NV_shader_texture_footprint = "GL_NV_shader_texture_footprint";
|
||||
const char* const E_GL_NV_mesh_shader = "GL_NV_mesh_shader";
|
||||
|
||||
// Arrays of extensions for the above viewportEXTs duplications
|
||||
|
||||
const char* const viewportEXTs[] = { E_GL_ARB_shader_viewport_layer_array, E_GL_NV_viewport_array2 };
|
||||
const int Num_viewportEXTs = sizeof(viewportEXTs) / sizeof(viewportEXTs[0]);
|
||||
|
||||
const char* const E_GL_NV_cooperative_matrix = "GL_NV_cooperative_matrix";
|
||||
const char* const E_GL_NV_shader_sm_builtins = "GL_NV_shader_sm_builtins";
|
||||
const char* const E_GL_NV_integer_cooperative_matrix = "GL_NV_integer_cooperative_matrix";
|
||||
|
||||
// AEP
|
||||
const char* const E_GL_ANDROID_extension_pack_es31a = "GL_ANDROID_extension_pack_es31a";
|
||||
const char* const E_GL_KHR_blend_equation_advanced = "GL_KHR_blend_equation_advanced";
|
||||
const char* const E_GL_OES_sample_variables = "GL_OES_sample_variables";
|
||||
const char* const E_GL_OES_shader_image_atomic = "GL_OES_shader_image_atomic";
|
||||
const char* const E_GL_OES_shader_multisample_interpolation = "GL_OES_shader_multisample_interpolation";
|
||||
const char* const E_GL_OES_texture_storage_multisample_2d_array = "GL_OES_texture_storage_multisample_2d_array";
|
||||
const char* const E_GL_EXT_geometry_shader = "GL_EXT_geometry_shader";
|
||||
const char* const E_GL_EXT_geometry_point_size = "GL_EXT_geometry_point_size";
|
||||
const char* const E_GL_EXT_gpu_shader5 = "GL_EXT_gpu_shader5";
|
||||
const char* const E_GL_EXT_primitive_bounding_box = "GL_EXT_primitive_bounding_box";
|
||||
const char* const E_GL_EXT_shader_io_blocks = "GL_EXT_shader_io_blocks";
|
||||
const char* const E_GL_EXT_tessellation_shader = "GL_EXT_tessellation_shader";
|
||||
const char* const E_GL_EXT_tessellation_point_size = "GL_EXT_tessellation_point_size";
|
||||
const char* const E_GL_EXT_texture_buffer = "GL_EXT_texture_buffer";
|
||||
const char* const E_GL_EXT_texture_cube_map_array = "GL_EXT_texture_cube_map_array";
|
||||
const char* const E_GL_EXT_shader_integer_mix = "GL_EXT_shader_integer_mix";
|
||||
|
||||
// OES matching AEP
|
||||
const char* const E_GL_OES_geometry_shader = "GL_OES_geometry_shader";
|
||||
const char* const E_GL_OES_geometry_point_size = "GL_OES_geometry_point_size";
|
||||
const char* const E_GL_OES_gpu_shader5 = "GL_OES_gpu_shader5";
|
||||
const char* const E_GL_OES_primitive_bounding_box = "GL_OES_primitive_bounding_box";
|
||||
const char* const E_GL_OES_shader_io_blocks = "GL_OES_shader_io_blocks";
|
||||
const char* const E_GL_OES_tessellation_shader = "GL_OES_tessellation_shader";
|
||||
const char* const E_GL_OES_tessellation_point_size = "GL_OES_tessellation_point_size";
|
||||
const char* const E_GL_OES_texture_buffer = "GL_OES_texture_buffer";
|
||||
const char* const E_GL_OES_texture_cube_map_array = "GL_OES_texture_cube_map_array";
|
||||
|
||||
// EXT
|
||||
const char* const E_GL_EXT_shader_explicit_arithmetic_types = "GL_EXT_shader_explicit_arithmetic_types";
|
||||
const char* const E_GL_EXT_shader_explicit_arithmetic_types_int8 = "GL_EXT_shader_explicit_arithmetic_types_int8";
|
||||
const char* const E_GL_EXT_shader_explicit_arithmetic_types_int16 = "GL_EXT_shader_explicit_arithmetic_types_int16";
|
||||
const char* const E_GL_EXT_shader_explicit_arithmetic_types_int32 = "GL_EXT_shader_explicit_arithmetic_types_int32";
|
||||
const char* const E_GL_EXT_shader_explicit_arithmetic_types_int64 = "GL_EXT_shader_explicit_arithmetic_types_int64";
|
||||
const char* const E_GL_EXT_shader_explicit_arithmetic_types_float16 = "GL_EXT_shader_explicit_arithmetic_types_float16";
|
||||
const char* const E_GL_EXT_shader_explicit_arithmetic_types_float32 = "GL_EXT_shader_explicit_arithmetic_types_float32";
|
||||
const char* const E_GL_EXT_shader_explicit_arithmetic_types_float64 = "GL_EXT_shader_explicit_arithmetic_types_float64";
|
||||
|
||||
const char* const E_GL_EXT_shader_subgroup_extended_types_int8 = "GL_EXT_shader_subgroup_extended_types_int8";
|
||||
const char* const E_GL_EXT_shader_subgroup_extended_types_int16 = "GL_EXT_shader_subgroup_extended_types_int16";
|
||||
const char* const E_GL_EXT_shader_subgroup_extended_types_int64 = "GL_EXT_shader_subgroup_extended_types_int64";
|
||||
const char* const E_GL_EXT_shader_subgroup_extended_types_float16 = "GL_EXT_shader_subgroup_extended_types_float16";
|
||||
|
||||
// Arrays of extensions for the above AEP duplications
|
||||
|
||||
const char* const AEP_geometry_shader[] = { E_GL_EXT_geometry_shader, E_GL_OES_geometry_shader };
|
||||
const int Num_AEP_geometry_shader = sizeof(AEP_geometry_shader)/sizeof(AEP_geometry_shader[0]);
|
||||
|
||||
const char* const AEP_geometry_point_size[] = { E_GL_EXT_geometry_point_size, E_GL_OES_geometry_point_size };
|
||||
const int Num_AEP_geometry_point_size = sizeof(AEP_geometry_point_size)/sizeof(AEP_geometry_point_size[0]);
|
||||
|
||||
const char* const AEP_gpu_shader5[] = { E_GL_EXT_gpu_shader5, E_GL_OES_gpu_shader5 };
|
||||
const int Num_AEP_gpu_shader5 = sizeof(AEP_gpu_shader5)/sizeof(AEP_gpu_shader5[0]);
|
||||
|
||||
const char* const AEP_primitive_bounding_box[] = { E_GL_EXT_primitive_bounding_box, E_GL_OES_primitive_bounding_box };
|
||||
const int Num_AEP_primitive_bounding_box = sizeof(AEP_primitive_bounding_box)/sizeof(AEP_primitive_bounding_box[0]);
|
||||
|
||||
const char* const AEP_shader_io_blocks[] = { E_GL_EXT_shader_io_blocks, E_GL_OES_shader_io_blocks };
|
||||
const int Num_AEP_shader_io_blocks = sizeof(AEP_shader_io_blocks)/sizeof(AEP_shader_io_blocks[0]);
|
||||
|
||||
const char* const AEP_tessellation_shader[] = { E_GL_EXT_tessellation_shader, E_GL_OES_tessellation_shader };
|
||||
const int Num_AEP_tessellation_shader = sizeof(AEP_tessellation_shader)/sizeof(AEP_tessellation_shader[0]);
|
||||
|
||||
const char* const AEP_tessellation_point_size[] = { E_GL_EXT_tessellation_point_size, E_GL_OES_tessellation_point_size };
|
||||
const int Num_AEP_tessellation_point_size = sizeof(AEP_tessellation_point_size)/sizeof(AEP_tessellation_point_size[0]);
|
||||
|
||||
const char* const AEP_texture_buffer[] = { E_GL_EXT_texture_buffer, E_GL_OES_texture_buffer };
|
||||
const int Num_AEP_texture_buffer = sizeof(AEP_texture_buffer)/sizeof(AEP_texture_buffer[0]);
|
||||
|
||||
const char* const AEP_texture_cube_map_array[] = { E_GL_EXT_texture_cube_map_array, E_GL_OES_texture_cube_map_array };
|
||||
const int Num_AEP_texture_cube_map_array = sizeof(AEP_texture_cube_map_array)/sizeof(AEP_texture_cube_map_array[0]);
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _VERSIONS_INCLUDED_
|
||||
|
|
@ -0,0 +1,149 @@
|
|||
//
|
||||
// Copyright (C) 2017 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.
|
||||
//
|
||||
|
||||
#ifndef _ATTRIBUTE_INCLUDED_
|
||||
#define _ATTRIBUTE_INCLUDED_
|
||||
|
||||
#include "../Include/Common.h"
|
||||
#include "../Include/ConstantUnion.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
enum TAttributeType {
|
||||
EatNone,
|
||||
EatAllow_uav_condition,
|
||||
EatBranch,
|
||||
EatCall,
|
||||
EatDomain,
|
||||
EatEarlyDepthStencil,
|
||||
EatFastOpt,
|
||||
EatFlatten,
|
||||
EatForceCase,
|
||||
EatInstance,
|
||||
EatMaxTessFactor,
|
||||
EatNumThreads,
|
||||
EatMaxVertexCount,
|
||||
EatOutputControlPoints,
|
||||
EatOutputTopology,
|
||||
EatPartitioning,
|
||||
EatPatchConstantFunc,
|
||||
EatPatchSize,
|
||||
EatUnroll,
|
||||
EatLoop,
|
||||
EatBinding,
|
||||
EatGlobalBinding,
|
||||
EatLocation,
|
||||
EatInputAttachment,
|
||||
EatBuiltIn,
|
||||
EatPushConstant,
|
||||
EatConstantId,
|
||||
EatDependencyInfinite,
|
||||
EatDependencyLength,
|
||||
EatMinIterations,
|
||||
EatMaxIterations,
|
||||
EatIterationMultiple,
|
||||
EatPeelCount,
|
||||
EatPartialCount,
|
||||
EatFormatRgba32f,
|
||||
EatFormatRgba16f,
|
||||
EatFormatR32f,
|
||||
EatFormatRgba8,
|
||||
EatFormatRgba8Snorm,
|
||||
EatFormatRg32f,
|
||||
EatFormatRg16f,
|
||||
EatFormatR11fG11fB10f,
|
||||
EatFormatR16f,
|
||||
EatFormatRgba16,
|
||||
EatFormatRgb10A2,
|
||||
EatFormatRg16,
|
||||
EatFormatRg8,
|
||||
EatFormatR16,
|
||||
EatFormatR8,
|
||||
EatFormatRgba16Snorm,
|
||||
EatFormatRg16Snorm,
|
||||
EatFormatRg8Snorm,
|
||||
EatFormatR16Snorm,
|
||||
EatFormatR8Snorm,
|
||||
EatFormatRgba32i,
|
||||
EatFormatRgba16i,
|
||||
EatFormatRgba8i,
|
||||
EatFormatR32i,
|
||||
EatFormatRg32i,
|
||||
EatFormatRg16i,
|
||||
EatFormatRg8i,
|
||||
EatFormatR16i,
|
||||
EatFormatR8i,
|
||||
EatFormatRgba32ui,
|
||||
EatFormatRgba16ui,
|
||||
EatFormatRgba8ui,
|
||||
EatFormatR32ui,
|
||||
EatFormatRgb10a2ui,
|
||||
EatFormatRg32ui,
|
||||
EatFormatRg16ui,
|
||||
EatFormatRg8ui,
|
||||
EatFormatR16ui,
|
||||
EatFormatR8ui,
|
||||
EatFormatUnknown,
|
||||
EatNonWritable,
|
||||
EatNonReadable
|
||||
};
|
||||
|
||||
class TIntermAggregate;
|
||||
|
||||
struct TAttributeArgs {
|
||||
TAttributeType name;
|
||||
const TIntermAggregate* args;
|
||||
|
||||
// Obtain attribute as integer
|
||||
// Return false if it cannot be obtained
|
||||
bool getInt(int& value, int argNum = 0) const;
|
||||
|
||||
// Obtain attribute as string, with optional to-lower transform
|
||||
// Return false if it cannot be obtained
|
||||
bool getString(TString& value, int argNum = 0, bool convertToLower = true) const;
|
||||
|
||||
// How many arguments were provided to the attribute?
|
||||
int size() const;
|
||||
|
||||
protected:
|
||||
const TConstUnion* getConstUnion(TBasicType basicType, int argNum) const;
|
||||
};
|
||||
|
||||
typedef TList<TAttributeArgs> TAttributes;
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _ATTRIBUTE_INCLUDED_
|
||||
|
|
@ -0,0 +1,210 @@
|
|||
/*
|
||||
** Copyright (c) 2013 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.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define GL_FLOAT 0x1406
|
||||
#define GL_FLOAT_VEC2 0x8B50
|
||||
#define GL_FLOAT_VEC3 0x8B51
|
||||
#define GL_FLOAT_VEC4 0x8B52
|
||||
|
||||
#define GL_DOUBLE 0x140A
|
||||
#define GL_DOUBLE_VEC2 0x8FFC
|
||||
#define GL_DOUBLE_VEC3 0x8FFD
|
||||
#define GL_DOUBLE_VEC4 0x8FFE
|
||||
|
||||
#define GL_INT 0x1404
|
||||
#define GL_INT_VEC2 0x8B53
|
||||
#define GL_INT_VEC3 0x8B54
|
||||
#define GL_INT_VEC4 0x8B55
|
||||
|
||||
#define GL_UNSIGNED_INT 0x1405
|
||||
#define GL_UNSIGNED_INT_VEC2 0x8DC6
|
||||
#define GL_UNSIGNED_INT_VEC3 0x8DC7
|
||||
#define GL_UNSIGNED_INT_VEC4 0x8DC8
|
||||
|
||||
#define GL_INT64_ARB 0x140E
|
||||
#define GL_INT64_VEC2_ARB 0x8FE9
|
||||
#define GL_INT64_VEC3_ARB 0x8FEA
|
||||
#define GL_INT64_VEC4_ARB 0x8FEB
|
||||
|
||||
#define GL_UNSIGNED_INT64_ARB 0x140F
|
||||
#define GL_UNSIGNED_INT64_VEC2_ARB 0x8FE5
|
||||
#define GL_UNSIGNED_INT64_VEC3_ARB 0x8FE6
|
||||
#define GL_UNSIGNED_INT64_VEC4_ARB 0x8FE7
|
||||
|
||||
#define GL_BOOL 0x8B56
|
||||
#define GL_BOOL_VEC2 0x8B57
|
||||
#define GL_BOOL_VEC3 0x8B58
|
||||
#define GL_BOOL_VEC4 0x8B59
|
||||
|
||||
#define GL_FLOAT_MAT2 0x8B5A
|
||||
#define GL_FLOAT_MAT3 0x8B5B
|
||||
#define GL_FLOAT_MAT4 0x8B5C
|
||||
#define GL_FLOAT_MAT2x3 0x8B65
|
||||
#define GL_FLOAT_MAT2x4 0x8B66
|
||||
#define GL_FLOAT_MAT3x2 0x8B67
|
||||
#define GL_FLOAT_MAT3x4 0x8B68
|
||||
#define GL_FLOAT_MAT4x2 0x8B69
|
||||
#define GL_FLOAT_MAT4x3 0x8B6A
|
||||
|
||||
#define GL_DOUBLE_MAT2 0x8F46
|
||||
#define GL_DOUBLE_MAT3 0x8F47
|
||||
#define GL_DOUBLE_MAT4 0x8F48
|
||||
#define GL_DOUBLE_MAT2x3 0x8F49
|
||||
#define GL_DOUBLE_MAT2x4 0x8F4A
|
||||
#define GL_DOUBLE_MAT3x2 0x8F4B
|
||||
#define GL_DOUBLE_MAT3x4 0x8F4C
|
||||
#define GL_DOUBLE_MAT4x2 0x8F4D
|
||||
#define GL_DOUBLE_MAT4x3 0x8F4E
|
||||
|
||||
// Those constants are borrowed from extension NV_gpu_shader5
|
||||
#define GL_FLOAT16_NV 0x8FF8
|
||||
#define GL_FLOAT16_VEC2_NV 0x8FF9
|
||||
#define GL_FLOAT16_VEC3_NV 0x8FFA
|
||||
#define GL_FLOAT16_VEC4_NV 0x8FFB
|
||||
|
||||
#define GL_FLOAT16_MAT2_AMD 0x91C5
|
||||
#define GL_FLOAT16_MAT3_AMD 0x91C6
|
||||
#define GL_FLOAT16_MAT4_AMD 0x91C7
|
||||
#define GL_FLOAT16_MAT2x3_AMD 0x91C8
|
||||
#define GL_FLOAT16_MAT2x4_AMD 0x91C9
|
||||
#define GL_FLOAT16_MAT3x2_AMD 0x91CA
|
||||
#define GL_FLOAT16_MAT3x4_AMD 0x91CB
|
||||
#define GL_FLOAT16_MAT4x2_AMD 0x91CC
|
||||
#define GL_FLOAT16_MAT4x3_AMD 0x91CD
|
||||
|
||||
#define GL_SAMPLER_1D 0x8B5D
|
||||
#define GL_SAMPLER_2D 0x8B5E
|
||||
#define GL_SAMPLER_3D 0x8B5F
|
||||
#define GL_SAMPLER_CUBE 0x8B60
|
||||
#define GL_SAMPLER_BUFFER 0x8DC2
|
||||
#define GL_SAMPLER_1D_ARRAY 0x8DC0
|
||||
#define GL_SAMPLER_2D_ARRAY 0x8DC1
|
||||
#define GL_SAMPLER_1D_ARRAY_SHADOW 0x8DC3
|
||||
#define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4
|
||||
#define GL_SAMPLER_CUBE_SHADOW 0x8DC5
|
||||
#define GL_SAMPLER_1D_SHADOW 0x8B61
|
||||
#define GL_SAMPLER_2D_SHADOW 0x8B62
|
||||
#define GL_SAMPLER_2D_RECT 0x8B63
|
||||
#define GL_SAMPLER_2D_RECT_SHADOW 0x8B64
|
||||
#define GL_SAMPLER_2D_MULTISAMPLE 0x9108
|
||||
#define GL_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910B
|
||||
#define GL_SAMPLER_CUBE_MAP_ARRAY 0x900C
|
||||
#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW 0x900D
|
||||
#define GL_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900C
|
||||
#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_ARB 0x900D
|
||||
|
||||
#define GL_FLOAT16_SAMPLER_1D_AMD 0x91CE
|
||||
#define GL_FLOAT16_SAMPLER_2D_AMD 0x91CF
|
||||
#define GL_FLOAT16_SAMPLER_3D_AMD 0x91D0
|
||||
#define GL_FLOAT16_SAMPLER_CUBE_AMD 0x91D1
|
||||
#define GL_FLOAT16_SAMPLER_2D_RECT_AMD 0x91D2
|
||||
#define GL_FLOAT16_SAMPLER_1D_ARRAY_AMD 0x91D3
|
||||
#define GL_FLOAT16_SAMPLER_2D_ARRAY_AMD 0x91D4
|
||||
#define GL_FLOAT16_SAMPLER_CUBE_MAP_ARRAY_AMD 0x91D5
|
||||
#define GL_FLOAT16_SAMPLER_BUFFER_AMD 0x91D6
|
||||
#define GL_FLOAT16_SAMPLER_2D_MULTISAMPLE_AMD 0x91D7
|
||||
#define GL_FLOAT16_SAMPLER_2D_MULTISAMPLE_ARRAY_AMD 0x91D8
|
||||
|
||||
#define GL_FLOAT16_SAMPLER_1D_SHADOW_AMD 0x91D9
|
||||
#define GL_FLOAT16_SAMPLER_2D_SHADOW_AMD 0x91DA
|
||||
#define GL_FLOAT16_SAMPLER_2D_RECT_SHADOW_AMD 0x91DB
|
||||
#define GL_FLOAT16_SAMPLER_1D_ARRAY_SHADOW_AMD 0x91DC
|
||||
#define GL_FLOAT16_SAMPLER_2D_ARRAY_SHADOW_AMD 0x91DD
|
||||
#define GL_FLOAT16_SAMPLER_CUBE_SHADOW_AMD 0x91DE
|
||||
#define GL_FLOAT16_SAMPLER_CUBE_MAP_ARRAY_SHADOW_AMD 0x91DF
|
||||
|
||||
#define GL_FLOAT16_IMAGE_1D_AMD 0x91E0
|
||||
#define GL_FLOAT16_IMAGE_2D_AMD 0x91E1
|
||||
#define GL_FLOAT16_IMAGE_3D_AMD 0x91E2
|
||||
#define GL_FLOAT16_IMAGE_2D_RECT_AMD 0x91E3
|
||||
#define GL_FLOAT16_IMAGE_CUBE_AMD 0x91E4
|
||||
#define GL_FLOAT16_IMAGE_1D_ARRAY_AMD 0x91E5
|
||||
#define GL_FLOAT16_IMAGE_2D_ARRAY_AMD 0x91E6
|
||||
#define GL_FLOAT16_IMAGE_CUBE_MAP_ARRAY_AMD 0x91E7
|
||||
#define GL_FLOAT16_IMAGE_BUFFER_AMD 0x91E8
|
||||
#define GL_FLOAT16_IMAGE_2D_MULTISAMPLE_AMD 0x91E9
|
||||
#define GL_FLOAT16_IMAGE_2D_MULTISAMPLE_ARRAY_AMD 0x91EA
|
||||
|
||||
#define GL_INT_SAMPLER_1D 0x8DC9
|
||||
#define GL_INT_SAMPLER_2D 0x8DCA
|
||||
#define GL_INT_SAMPLER_3D 0x8DCB
|
||||
#define GL_INT_SAMPLER_CUBE 0x8DCC
|
||||
#define GL_INT_SAMPLER_1D_ARRAY 0x8DCE
|
||||
#define GL_INT_SAMPLER_2D_ARRAY 0x8DCF
|
||||
#define GL_INT_SAMPLER_2D_RECT 0x8DCD
|
||||
#define GL_INT_SAMPLER_BUFFER 0x8DD0
|
||||
#define GL_INT_SAMPLER_2D_MULTISAMPLE 0x9109
|
||||
#define GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910C
|
||||
#define GL_INT_SAMPLER_CUBE_MAP_ARRAY 0x900E
|
||||
#define GL_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900E
|
||||
|
||||
#define GL_UNSIGNED_INT_SAMPLER_1D 0x8DD1
|
||||
#define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2
|
||||
#define GL_UNSIGNED_INT_SAMPLER_3D 0x8DD3
|
||||
#define GL_UNSIGNED_INT_SAMPLER_CUBE 0x8DD4
|
||||
#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY 0x8DD6
|
||||
#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7
|
||||
#define GL_UNSIGNED_INT_SAMPLER_2D_RECT 0x8DD5
|
||||
#define GL_UNSIGNED_INT_SAMPLER_BUFFER 0x8DD8
|
||||
#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910D
|
||||
#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY 0x900F
|
||||
#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900F
|
||||
#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE 0x910A
|
||||
|
||||
#define GL_IMAGE_1D 0x904C
|
||||
#define GL_IMAGE_2D 0x904D
|
||||
#define GL_IMAGE_3D 0x904E
|
||||
#define GL_IMAGE_2D_RECT 0x904F
|
||||
#define GL_IMAGE_CUBE 0x9050
|
||||
#define GL_IMAGE_BUFFER 0x9051
|
||||
#define GL_IMAGE_1D_ARRAY 0x9052
|
||||
#define GL_IMAGE_2D_ARRAY 0x9053
|
||||
#define GL_IMAGE_CUBE_MAP_ARRAY 0x9054
|
||||
#define GL_IMAGE_2D_MULTISAMPLE 0x9055
|
||||
#define GL_IMAGE_2D_MULTISAMPLE_ARRAY 0x9056
|
||||
#define GL_INT_IMAGE_1D 0x9057
|
||||
#define GL_INT_IMAGE_2D 0x9058
|
||||
#define GL_INT_IMAGE_3D 0x9059
|
||||
#define GL_INT_IMAGE_2D_RECT 0x905A
|
||||
#define GL_INT_IMAGE_CUBE 0x905B
|
||||
#define GL_INT_IMAGE_BUFFER 0x905C
|
||||
#define GL_INT_IMAGE_1D_ARRAY 0x905D
|
||||
#define GL_INT_IMAGE_2D_ARRAY 0x905E
|
||||
#define GL_INT_IMAGE_CUBE_MAP_ARRAY 0x905F
|
||||
#define GL_INT_IMAGE_2D_MULTISAMPLE 0x9060
|
||||
#define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x9061
|
||||
#define GL_UNSIGNED_INT_IMAGE_1D 0x9062
|
||||
#define GL_UNSIGNED_INT_IMAGE_2D 0x9063
|
||||
#define GL_UNSIGNED_INT_IMAGE_3D 0x9064
|
||||
#define GL_UNSIGNED_INT_IMAGE_2D_RECT 0x9065
|
||||
#define GL_UNSIGNED_INT_IMAGE_CUBE 0x9066
|
||||
#define GL_UNSIGNED_INT_IMAGE_BUFFER 0x9067
|
||||
#define GL_UNSIGNED_INT_IMAGE_1D_ARRAY 0x9068
|
||||
#define GL_UNSIGNED_INT_IMAGE_2D_ARRAY 0x9069
|
||||
#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY 0x906A
|
||||
#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE 0x906B
|
||||
#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x906C
|
||||
|
||||
#define GL_UNSIGNED_INT_ATOMIC_COUNTER 0x92DB
|
||||
|
|
@ -0,0 +1,521 @@
|
|||
/* A Bison parser, made by GNU Bison 3.0.4. */
|
||||
|
||||
/* Bison interface for Yacc-like parsers in C
|
||||
|
||||
Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* As a special exception, you may create a larger work that contains
|
||||
part or all of the Bison parser skeleton and distribute that work
|
||||
under terms of your choice, so long as that work isn't itself a
|
||||
parser generator using the skeleton or a modified version thereof
|
||||
as a parser skeleton. Alternatively, if you modify or redistribute
|
||||
the parser skeleton itself, you may (at your option) remove this
|
||||
special exception, which will cause the skeleton and the resulting
|
||||
Bison output files to be licensed under the GNU General Public
|
||||
License without this special exception.
|
||||
|
||||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison. */
|
||||
|
||||
#ifndef YY_YY_GLSLANG_TAB_CPP_H_INCLUDED
|
||||
# define YY_YY_GLSLANG_TAB_CPP_H_INCLUDED
|
||||
/* Debug traces. */
|
||||
#ifndef YYDEBUG
|
||||
# define YYDEBUG 1
|
||||
#endif
|
||||
#if YYDEBUG
|
||||
extern int yydebug;
|
||||
#endif
|
||||
|
||||
/* Token type. */
|
||||
#ifndef YYTOKENTYPE
|
||||
# define YYTOKENTYPE
|
||||
enum yytokentype
|
||||
{
|
||||
CONST = 258,
|
||||
BOOL = 259,
|
||||
INT = 260,
|
||||
UINT = 261,
|
||||
FLOAT = 262,
|
||||
BVEC2 = 263,
|
||||
BVEC3 = 264,
|
||||
BVEC4 = 265,
|
||||
IVEC2 = 266,
|
||||
IVEC3 = 267,
|
||||
IVEC4 = 268,
|
||||
UVEC2 = 269,
|
||||
UVEC3 = 270,
|
||||
UVEC4 = 271,
|
||||
VEC2 = 272,
|
||||
VEC3 = 273,
|
||||
VEC4 = 274,
|
||||
MAT2 = 275,
|
||||
MAT3 = 276,
|
||||
MAT4 = 277,
|
||||
MAT2X2 = 278,
|
||||
MAT2X3 = 279,
|
||||
MAT2X4 = 280,
|
||||
MAT3X2 = 281,
|
||||
MAT3X3 = 282,
|
||||
MAT3X4 = 283,
|
||||
MAT4X2 = 284,
|
||||
MAT4X3 = 285,
|
||||
MAT4X4 = 286,
|
||||
SAMPLER2D = 287,
|
||||
SAMPLER3D = 288,
|
||||
SAMPLERCUBE = 289,
|
||||
SAMPLER2DSHADOW = 290,
|
||||
SAMPLERCUBESHADOW = 291,
|
||||
SAMPLER2DARRAY = 292,
|
||||
SAMPLER2DARRAYSHADOW = 293,
|
||||
ISAMPLER2D = 294,
|
||||
ISAMPLER3D = 295,
|
||||
ISAMPLERCUBE = 296,
|
||||
ISAMPLER2DARRAY = 297,
|
||||
USAMPLER2D = 298,
|
||||
USAMPLER3D = 299,
|
||||
USAMPLERCUBE = 300,
|
||||
USAMPLER2DARRAY = 301,
|
||||
SAMPLER = 302,
|
||||
SAMPLERSHADOW = 303,
|
||||
TEXTURE2D = 304,
|
||||
TEXTURE3D = 305,
|
||||
TEXTURECUBE = 306,
|
||||
TEXTURE2DARRAY = 307,
|
||||
ITEXTURE2D = 308,
|
||||
ITEXTURE3D = 309,
|
||||
ITEXTURECUBE = 310,
|
||||
ITEXTURE2DARRAY = 311,
|
||||
UTEXTURE2D = 312,
|
||||
UTEXTURE3D = 313,
|
||||
UTEXTURECUBE = 314,
|
||||
UTEXTURE2DARRAY = 315,
|
||||
ATTRIBUTE = 316,
|
||||
VARYING = 317,
|
||||
FLOAT16_T = 318,
|
||||
FLOAT32_T = 319,
|
||||
DOUBLE = 320,
|
||||
FLOAT64_T = 321,
|
||||
INT64_T = 322,
|
||||
UINT64_T = 323,
|
||||
INT32_T = 324,
|
||||
UINT32_T = 325,
|
||||
INT16_T = 326,
|
||||
UINT16_T = 327,
|
||||
INT8_T = 328,
|
||||
UINT8_T = 329,
|
||||
I64VEC2 = 330,
|
||||
I64VEC3 = 331,
|
||||
I64VEC4 = 332,
|
||||
U64VEC2 = 333,
|
||||
U64VEC3 = 334,
|
||||
U64VEC4 = 335,
|
||||
I32VEC2 = 336,
|
||||
I32VEC3 = 337,
|
||||
I32VEC4 = 338,
|
||||
U32VEC2 = 339,
|
||||
U32VEC3 = 340,
|
||||
U32VEC4 = 341,
|
||||
I16VEC2 = 342,
|
||||
I16VEC3 = 343,
|
||||
I16VEC4 = 344,
|
||||
U16VEC2 = 345,
|
||||
U16VEC3 = 346,
|
||||
U16VEC4 = 347,
|
||||
I8VEC2 = 348,
|
||||
I8VEC3 = 349,
|
||||
I8VEC4 = 350,
|
||||
U8VEC2 = 351,
|
||||
U8VEC3 = 352,
|
||||
U8VEC4 = 353,
|
||||
DVEC2 = 354,
|
||||
DVEC3 = 355,
|
||||
DVEC4 = 356,
|
||||
DMAT2 = 357,
|
||||
DMAT3 = 358,
|
||||
DMAT4 = 359,
|
||||
F16VEC2 = 360,
|
||||
F16VEC3 = 361,
|
||||
F16VEC4 = 362,
|
||||
F16MAT2 = 363,
|
||||
F16MAT3 = 364,
|
||||
F16MAT4 = 365,
|
||||
F32VEC2 = 366,
|
||||
F32VEC3 = 367,
|
||||
F32VEC4 = 368,
|
||||
F32MAT2 = 369,
|
||||
F32MAT3 = 370,
|
||||
F32MAT4 = 371,
|
||||
F64VEC2 = 372,
|
||||
F64VEC3 = 373,
|
||||
F64VEC4 = 374,
|
||||
F64MAT2 = 375,
|
||||
F64MAT3 = 376,
|
||||
F64MAT4 = 377,
|
||||
DMAT2X2 = 378,
|
||||
DMAT2X3 = 379,
|
||||
DMAT2X4 = 380,
|
||||
DMAT3X2 = 381,
|
||||
DMAT3X3 = 382,
|
||||
DMAT3X4 = 383,
|
||||
DMAT4X2 = 384,
|
||||
DMAT4X3 = 385,
|
||||
DMAT4X4 = 386,
|
||||
F16MAT2X2 = 387,
|
||||
F16MAT2X3 = 388,
|
||||
F16MAT2X4 = 389,
|
||||
F16MAT3X2 = 390,
|
||||
F16MAT3X3 = 391,
|
||||
F16MAT3X4 = 392,
|
||||
F16MAT4X2 = 393,
|
||||
F16MAT4X3 = 394,
|
||||
F16MAT4X4 = 395,
|
||||
F32MAT2X2 = 396,
|
||||
F32MAT2X3 = 397,
|
||||
F32MAT2X4 = 398,
|
||||
F32MAT3X2 = 399,
|
||||
F32MAT3X3 = 400,
|
||||
F32MAT3X4 = 401,
|
||||
F32MAT4X2 = 402,
|
||||
F32MAT4X3 = 403,
|
||||
F32MAT4X4 = 404,
|
||||
F64MAT2X2 = 405,
|
||||
F64MAT2X3 = 406,
|
||||
F64MAT2X4 = 407,
|
||||
F64MAT3X2 = 408,
|
||||
F64MAT3X3 = 409,
|
||||
F64MAT3X4 = 410,
|
||||
F64MAT4X2 = 411,
|
||||
F64MAT4X3 = 412,
|
||||
F64MAT4X4 = 413,
|
||||
ATOMIC_UINT = 414,
|
||||
ACCSTRUCTNV = 415,
|
||||
ACCSTRUCTEXT = 416,
|
||||
RAYQUERYEXT = 417,
|
||||
FCOOPMATNV = 418,
|
||||
ICOOPMATNV = 419,
|
||||
UCOOPMATNV = 420,
|
||||
SAMPLERCUBEARRAY = 421,
|
||||
SAMPLERCUBEARRAYSHADOW = 422,
|
||||
ISAMPLERCUBEARRAY = 423,
|
||||
USAMPLERCUBEARRAY = 424,
|
||||
SAMPLER1D = 425,
|
||||
SAMPLER1DARRAY = 426,
|
||||
SAMPLER1DARRAYSHADOW = 427,
|
||||
ISAMPLER1D = 428,
|
||||
SAMPLER1DSHADOW = 429,
|
||||
SAMPLER2DRECT = 430,
|
||||
SAMPLER2DRECTSHADOW = 431,
|
||||
ISAMPLER2DRECT = 432,
|
||||
USAMPLER2DRECT = 433,
|
||||
SAMPLERBUFFER = 434,
|
||||
ISAMPLERBUFFER = 435,
|
||||
USAMPLERBUFFER = 436,
|
||||
SAMPLER2DMS = 437,
|
||||
ISAMPLER2DMS = 438,
|
||||
USAMPLER2DMS = 439,
|
||||
SAMPLER2DMSARRAY = 440,
|
||||
ISAMPLER2DMSARRAY = 441,
|
||||
USAMPLER2DMSARRAY = 442,
|
||||
SAMPLEREXTERNALOES = 443,
|
||||
SAMPLEREXTERNAL2DY2YEXT = 444,
|
||||
ISAMPLER1DARRAY = 445,
|
||||
USAMPLER1D = 446,
|
||||
USAMPLER1DARRAY = 447,
|
||||
F16SAMPLER1D = 448,
|
||||
F16SAMPLER2D = 449,
|
||||
F16SAMPLER3D = 450,
|
||||
F16SAMPLER2DRECT = 451,
|
||||
F16SAMPLERCUBE = 452,
|
||||
F16SAMPLER1DARRAY = 453,
|
||||
F16SAMPLER2DARRAY = 454,
|
||||
F16SAMPLERCUBEARRAY = 455,
|
||||
F16SAMPLERBUFFER = 456,
|
||||
F16SAMPLER2DMS = 457,
|
||||
F16SAMPLER2DMSARRAY = 458,
|
||||
F16SAMPLER1DSHADOW = 459,
|
||||
F16SAMPLER2DSHADOW = 460,
|
||||
F16SAMPLER1DARRAYSHADOW = 461,
|
||||
F16SAMPLER2DARRAYSHADOW = 462,
|
||||
F16SAMPLER2DRECTSHADOW = 463,
|
||||
F16SAMPLERCUBESHADOW = 464,
|
||||
F16SAMPLERCUBEARRAYSHADOW = 465,
|
||||
IMAGE1D = 466,
|
||||
IIMAGE1D = 467,
|
||||
UIMAGE1D = 468,
|
||||
IMAGE2D = 469,
|
||||
IIMAGE2D = 470,
|
||||
UIMAGE2D = 471,
|
||||
IMAGE3D = 472,
|
||||
IIMAGE3D = 473,
|
||||
UIMAGE3D = 474,
|
||||
IMAGE2DRECT = 475,
|
||||
IIMAGE2DRECT = 476,
|
||||
UIMAGE2DRECT = 477,
|
||||
IMAGECUBE = 478,
|
||||
IIMAGECUBE = 479,
|
||||
UIMAGECUBE = 480,
|
||||
IMAGEBUFFER = 481,
|
||||
IIMAGEBUFFER = 482,
|
||||
UIMAGEBUFFER = 483,
|
||||
IMAGE1DARRAY = 484,
|
||||
IIMAGE1DARRAY = 485,
|
||||
UIMAGE1DARRAY = 486,
|
||||
IMAGE2DARRAY = 487,
|
||||
IIMAGE2DARRAY = 488,
|
||||
UIMAGE2DARRAY = 489,
|
||||
IMAGECUBEARRAY = 490,
|
||||
IIMAGECUBEARRAY = 491,
|
||||
UIMAGECUBEARRAY = 492,
|
||||
IMAGE2DMS = 493,
|
||||
IIMAGE2DMS = 494,
|
||||
UIMAGE2DMS = 495,
|
||||
IMAGE2DMSARRAY = 496,
|
||||
IIMAGE2DMSARRAY = 497,
|
||||
UIMAGE2DMSARRAY = 498,
|
||||
F16IMAGE1D = 499,
|
||||
F16IMAGE2D = 500,
|
||||
F16IMAGE3D = 501,
|
||||
F16IMAGE2DRECT = 502,
|
||||
F16IMAGECUBE = 503,
|
||||
F16IMAGE1DARRAY = 504,
|
||||
F16IMAGE2DARRAY = 505,
|
||||
F16IMAGECUBEARRAY = 506,
|
||||
F16IMAGEBUFFER = 507,
|
||||
F16IMAGE2DMS = 508,
|
||||
F16IMAGE2DMSARRAY = 509,
|
||||
TEXTURECUBEARRAY = 510,
|
||||
ITEXTURECUBEARRAY = 511,
|
||||
UTEXTURECUBEARRAY = 512,
|
||||
TEXTURE1D = 513,
|
||||
ITEXTURE1D = 514,
|
||||
UTEXTURE1D = 515,
|
||||
TEXTURE1DARRAY = 516,
|
||||
ITEXTURE1DARRAY = 517,
|
||||
UTEXTURE1DARRAY = 518,
|
||||
TEXTURE2DRECT = 519,
|
||||
ITEXTURE2DRECT = 520,
|
||||
UTEXTURE2DRECT = 521,
|
||||
TEXTUREBUFFER = 522,
|
||||
ITEXTUREBUFFER = 523,
|
||||
UTEXTUREBUFFER = 524,
|
||||
TEXTURE2DMS = 525,
|
||||
ITEXTURE2DMS = 526,
|
||||
UTEXTURE2DMS = 527,
|
||||
TEXTURE2DMSARRAY = 528,
|
||||
ITEXTURE2DMSARRAY = 529,
|
||||
UTEXTURE2DMSARRAY = 530,
|
||||
F16TEXTURE1D = 531,
|
||||
F16TEXTURE2D = 532,
|
||||
F16TEXTURE3D = 533,
|
||||
F16TEXTURE2DRECT = 534,
|
||||
F16TEXTURECUBE = 535,
|
||||
F16TEXTURE1DARRAY = 536,
|
||||
F16TEXTURE2DARRAY = 537,
|
||||
F16TEXTURECUBEARRAY = 538,
|
||||
F16TEXTUREBUFFER = 539,
|
||||
F16TEXTURE2DMS = 540,
|
||||
F16TEXTURE2DMSARRAY = 541,
|
||||
SUBPASSINPUT = 542,
|
||||
SUBPASSINPUTMS = 543,
|
||||
ISUBPASSINPUT = 544,
|
||||
ISUBPASSINPUTMS = 545,
|
||||
USUBPASSINPUT = 546,
|
||||
USUBPASSINPUTMS = 547,
|
||||
F16SUBPASSINPUT = 548,
|
||||
F16SUBPASSINPUTMS = 549,
|
||||
LEFT_OP = 550,
|
||||
RIGHT_OP = 551,
|
||||
INC_OP = 552,
|
||||
DEC_OP = 553,
|
||||
LE_OP = 554,
|
||||
GE_OP = 555,
|
||||
EQ_OP = 556,
|
||||
NE_OP = 557,
|
||||
AND_OP = 558,
|
||||
OR_OP = 559,
|
||||
XOR_OP = 560,
|
||||
MUL_ASSIGN = 561,
|
||||
DIV_ASSIGN = 562,
|
||||
ADD_ASSIGN = 563,
|
||||
MOD_ASSIGN = 564,
|
||||
LEFT_ASSIGN = 565,
|
||||
RIGHT_ASSIGN = 566,
|
||||
AND_ASSIGN = 567,
|
||||
XOR_ASSIGN = 568,
|
||||
OR_ASSIGN = 569,
|
||||
SUB_ASSIGN = 570,
|
||||
STRING_LITERAL = 571,
|
||||
LEFT_PAREN = 572,
|
||||
RIGHT_PAREN = 573,
|
||||
LEFT_BRACKET = 574,
|
||||
RIGHT_BRACKET = 575,
|
||||
LEFT_BRACE = 576,
|
||||
RIGHT_BRACE = 577,
|
||||
DOT = 578,
|
||||
COMMA = 579,
|
||||
COLON = 580,
|
||||
EQUAL = 581,
|
||||
SEMICOLON = 582,
|
||||
BANG = 583,
|
||||
DASH = 584,
|
||||
TILDE = 585,
|
||||
PLUS = 586,
|
||||
STAR = 587,
|
||||
SLASH = 588,
|
||||
PERCENT = 589,
|
||||
LEFT_ANGLE = 590,
|
||||
RIGHT_ANGLE = 591,
|
||||
VERTICAL_BAR = 592,
|
||||
CARET = 593,
|
||||
AMPERSAND = 594,
|
||||
QUESTION = 595,
|
||||
INVARIANT = 596,
|
||||
HIGH_PRECISION = 597,
|
||||
MEDIUM_PRECISION = 598,
|
||||
LOW_PRECISION = 599,
|
||||
PRECISION = 600,
|
||||
PACKED = 601,
|
||||
RESOURCE = 602,
|
||||
SUPERP = 603,
|
||||
FLOATCONSTANT = 604,
|
||||
INTCONSTANT = 605,
|
||||
UINTCONSTANT = 606,
|
||||
BOOLCONSTANT = 607,
|
||||
IDENTIFIER = 608,
|
||||
TYPE_NAME = 609,
|
||||
CENTROID = 610,
|
||||
IN = 611,
|
||||
OUT = 612,
|
||||
INOUT = 613,
|
||||
STRUCT = 614,
|
||||
VOID = 615,
|
||||
WHILE = 616,
|
||||
BREAK = 617,
|
||||
CONTINUE = 618,
|
||||
DO = 619,
|
||||
ELSE = 620,
|
||||
FOR = 621,
|
||||
IF = 622,
|
||||
DISCARD = 623,
|
||||
RETURN = 624,
|
||||
SWITCH = 625,
|
||||
CASE = 626,
|
||||
DEFAULT = 627,
|
||||
UNIFORM = 628,
|
||||
SHARED = 629,
|
||||
BUFFER = 630,
|
||||
FLAT = 631,
|
||||
SMOOTH = 632,
|
||||
LAYOUT = 633,
|
||||
DOUBLECONSTANT = 634,
|
||||
INT16CONSTANT = 635,
|
||||
UINT16CONSTANT = 636,
|
||||
FLOAT16CONSTANT = 637,
|
||||
INT32CONSTANT = 638,
|
||||
UINT32CONSTANT = 639,
|
||||
INT64CONSTANT = 640,
|
||||
UINT64CONSTANT = 641,
|
||||
SUBROUTINE = 642,
|
||||
DEMOTE = 643,
|
||||
PAYLOADNV = 644,
|
||||
PAYLOADINNV = 645,
|
||||
HITATTRNV = 646,
|
||||
CALLDATANV = 647,
|
||||
CALLDATAINNV = 648,
|
||||
PAYLOADEXT = 649,
|
||||
PAYLOADINEXT = 650,
|
||||
HITATTREXT = 651,
|
||||
CALLDATAEXT = 652,
|
||||
CALLDATAINEXT = 653,
|
||||
PATCH = 654,
|
||||
SAMPLE = 655,
|
||||
NONUNIFORM = 656,
|
||||
COHERENT = 657,
|
||||
VOLATILE = 658,
|
||||
RESTRICT = 659,
|
||||
READONLY = 660,
|
||||
WRITEONLY = 661,
|
||||
DEVICECOHERENT = 662,
|
||||
QUEUEFAMILYCOHERENT = 663,
|
||||
WORKGROUPCOHERENT = 664,
|
||||
SUBGROUPCOHERENT = 665,
|
||||
NONPRIVATE = 666,
|
||||
SHADERCALLCOHERENT = 667,
|
||||
NOPERSPECTIVE = 668,
|
||||
EXPLICITINTERPAMD = 669,
|
||||
PERVERTEXNV = 670,
|
||||
PERPRIMITIVENV = 671,
|
||||
PERVIEWNV = 672,
|
||||
PERTASKNV = 673,
|
||||
PRECISE = 674
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Value type. */
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
|
||||
union YYSTYPE
|
||||
{
|
||||
#line 97 "glslang.y" /* yacc.c:1909 */
|
||||
|
||||
struct {
|
||||
glslang::TSourceLoc loc;
|
||||
union {
|
||||
glslang::TString *string;
|
||||
int i;
|
||||
unsigned int u;
|
||||
long long i64;
|
||||
unsigned long long u64;
|
||||
bool b;
|
||||
double d;
|
||||
};
|
||||
glslang::TSymbol* symbol;
|
||||
} lex;
|
||||
struct {
|
||||
glslang::TSourceLoc loc;
|
||||
glslang::TOperator op;
|
||||
union {
|
||||
TIntermNode* intermNode;
|
||||
glslang::TIntermNodePair nodePair;
|
||||
glslang::TIntermTyped* intermTypedNode;
|
||||
glslang::TAttributes* attributes;
|
||||
};
|
||||
union {
|
||||
glslang::TPublicType type;
|
||||
glslang::TFunction* function;
|
||||
glslang::TParameter param;
|
||||
glslang::TTypeLoc typeLine;
|
||||
glslang::TTypeList* typeList;
|
||||
glslang::TArraySizes* arraySizes;
|
||||
glslang::TIdentifierList* identifierList;
|
||||
};
|
||||
glslang::TArraySizes* typeParameters;
|
||||
} interm;
|
||||
|
||||
#line 510 "glslang_tab.cpp.h" /* yacc.c:1909 */
|
||||
};
|
||||
|
||||
typedef union YYSTYPE YYSTYPE;
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
int yyparse (glslang::TParseContext* pParseContext);
|
||||
|
||||
#endif /* !YY_YY_GLSLANG_TAB_CPP_H_INCLUDED */
|
||||
|
|
@ -0,0 +1,302 @@
|
|||
//
|
||||
// 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 GLSLANG_WEB
|
||||
|
||||
#ifndef _IOMAPPER_INCLUDED
|
||||
#define _IOMAPPER_INCLUDED
|
||||
|
||||
#include <cstdint>
|
||||
#include "LiveTraverser.h"
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
//
|
||||
// A reflection database and its interface, consistent with the OpenGL API reflection queries.
|
||||
//
|
||||
|
||||
class TInfoSink;
|
||||
|
||||
namespace glslang {
|
||||
|
||||
class TIntermediate;
|
||||
struct TVarEntryInfo {
|
||||
int id;
|
||||
TIntermSymbol* symbol;
|
||||
bool live;
|
||||
int newBinding;
|
||||
int newSet;
|
||||
int newLocation;
|
||||
int newComponent;
|
||||
int newIndex;
|
||||
EShLanguage stage;
|
||||
struct TOrderById {
|
||||
inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) { return l.id < r.id; }
|
||||
};
|
||||
|
||||
struct TOrderByPriority {
|
||||
// ordering:
|
||||
// 1) has both binding and set
|
||||
// 2) has binding but no set
|
||||
// 3) has no binding but set
|
||||
// 4) has no binding and no set
|
||||
inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) {
|
||||
const TQualifier& lq = l.symbol->getQualifier();
|
||||
const TQualifier& rq = r.symbol->getQualifier();
|
||||
|
||||
// simple rules:
|
||||
// has binding gives 2 points
|
||||
// has set gives 1 point
|
||||
// who has the most points is more important.
|
||||
int lPoints = (lq.hasBinding() ? 2 : 0) + (lq.hasSet() ? 1 : 0);
|
||||
int rPoints = (rq.hasBinding() ? 2 : 0) + (rq.hasSet() ? 1 : 0);
|
||||
|
||||
if (lPoints == rPoints)
|
||||
return l.id < r.id;
|
||||
return lPoints > rPoints;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Base class for shared TIoMapResolver services, used by several derivations.
|
||||
struct TDefaultIoResolverBase : public glslang::TIoMapResolver {
|
||||
public:
|
||||
TDefaultIoResolverBase(const TIntermediate& intermediate);
|
||||
typedef std::vector<int> TSlotSet;
|
||||
typedef std::unordered_map<int, TSlotSet> TSlotSetMap;
|
||||
|
||||
// grow the reflection stage by stage
|
||||
void notifyBinding(EShLanguage, TVarEntryInfo& /*ent*/) override {}
|
||||
void notifyInOut(EShLanguage, TVarEntryInfo& /*ent*/) override {}
|
||||
void beginNotifications(EShLanguage) override {}
|
||||
void endNotifications(EShLanguage) override {}
|
||||
void beginResolve(EShLanguage) override {}
|
||||
void endResolve(EShLanguage) override {}
|
||||
void beginCollect(EShLanguage) override {}
|
||||
void endCollect(EShLanguage) override {}
|
||||
void reserverResourceSlot(TVarEntryInfo& /*ent*/, TInfoSink& /*infoSink*/) override {}
|
||||
void reserverStorageSlot(TVarEntryInfo& /*ent*/, TInfoSink& /*infoSink*/) override {}
|
||||
int getBaseBinding(TResourceType res, unsigned int set) const;
|
||||
const std::vector<std::string>& getResourceSetBinding() const;
|
||||
virtual TResourceType getResourceType(const glslang::TType& type) = 0;
|
||||
bool doAutoBindingMapping() const;
|
||||
bool doAutoLocationMapping() const;
|
||||
TSlotSet::iterator findSlot(int set, int slot);
|
||||
bool checkEmpty(int set, int slot);
|
||||
bool validateInOut(EShLanguage /*stage*/, TVarEntryInfo& /*ent*/) override { return true; }
|
||||
int reserveSlot(int set, int slot, int size = 1);
|
||||
int getFreeSlot(int set, int base, int size = 1);
|
||||
int resolveSet(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
|
||||
int resolveUniformLocation(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
|
||||
int resolveInOutLocation(EShLanguage stage, TVarEntryInfo& ent) override;
|
||||
int resolveInOutComponent(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
|
||||
int resolveInOutIndex(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
|
||||
void addStage(EShLanguage stage) override {
|
||||
if (stage < EShLangCount)
|
||||
stageMask[stage] = true;
|
||||
}
|
||||
uint32_t computeTypeLocationSize(const TType& type, EShLanguage stage);
|
||||
|
||||
TSlotSetMap slots;
|
||||
bool hasError = false;
|
||||
|
||||
protected:
|
||||
TDefaultIoResolverBase(TDefaultIoResolverBase&);
|
||||
TDefaultIoResolverBase& operator=(TDefaultIoResolverBase&);
|
||||
const TIntermediate& intermediate;
|
||||
int nextUniformLocation;
|
||||
int nextInputLocation;
|
||||
int nextOutputLocation;
|
||||
bool stageMask[EShLangCount + 1];
|
||||
// Return descriptor set specific base if there is one, and the generic base otherwise.
|
||||
int selectBaseBinding(int base, int descriptorSetBase) const {
|
||||
return descriptorSetBase != -1 ? descriptorSetBase : base;
|
||||
}
|
||||
|
||||
static int getLayoutSet(const glslang::TType& type) {
|
||||
if (type.getQualifier().hasSet())
|
||||
return type.getQualifier().layoutSet;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool isSamplerType(const glslang::TType& type) {
|
||||
return type.getBasicType() == glslang::EbtSampler && type.getSampler().isPureSampler();
|
||||
}
|
||||
|
||||
static bool isTextureType(const glslang::TType& type) {
|
||||
return (type.getBasicType() == glslang::EbtSampler &&
|
||||
(type.getSampler().isTexture() || type.getSampler().isSubpass()));
|
||||
}
|
||||
|
||||
static bool isUboType(const glslang::TType& type) {
|
||||
return type.getQualifier().storage == EvqUniform;
|
||||
}
|
||||
|
||||
static bool isImageType(const glslang::TType& type) {
|
||||
return type.getBasicType() == glslang::EbtSampler && type.getSampler().isImage();
|
||||
}
|
||||
|
||||
static bool isSsboType(const glslang::TType& type) {
|
||||
return type.getQualifier().storage == EvqBuffer;
|
||||
}
|
||||
|
||||
// Return true if this is a SRV (shader resource view) type:
|
||||
static bool isSrvType(const glslang::TType& type) {
|
||||
return isTextureType(type) || type.getQualifier().storage == EvqBuffer;
|
||||
}
|
||||
|
||||
// Return true if this is a UAV (unordered access view) type:
|
||||
static bool isUavType(const glslang::TType& type) {
|
||||
if (type.getQualifier().isReadOnly())
|
||||
return false;
|
||||
return (type.getBasicType() == glslang::EbtSampler && type.getSampler().isImage()) ||
|
||||
(type.getQualifier().storage == EvqBuffer);
|
||||
}
|
||||
};
|
||||
|
||||
// Defaulf I/O resolver for OpenGL
|
||||
struct TDefaultGlslIoResolver : public TDefaultIoResolverBase {
|
||||
public:
|
||||
typedef std::map<TString, int> TVarSlotMap; // <resourceName, location/binding>
|
||||
typedef std::map<int, TVarSlotMap> TSlotMap; // <resourceKey, TVarSlotMap>
|
||||
TDefaultGlslIoResolver(const TIntermediate& intermediate);
|
||||
bool validateBinding(EShLanguage /*stage*/, TVarEntryInfo& /*ent*/) override { return true; }
|
||||
TResourceType getResourceType(const glslang::TType& type) override;
|
||||
int resolveInOutLocation(EShLanguage stage, TVarEntryInfo& ent) override;
|
||||
int resolveUniformLocation(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
|
||||
int resolveBinding(EShLanguage /*stage*/, TVarEntryInfo& ent) override;
|
||||
void beginResolve(EShLanguage /*stage*/) override;
|
||||
void endResolve(EShLanguage stage) override;
|
||||
void beginCollect(EShLanguage) override;
|
||||
void endCollect(EShLanguage) override;
|
||||
void reserverStorageSlot(TVarEntryInfo& ent, TInfoSink& infoSink) override;
|
||||
void reserverResourceSlot(TVarEntryInfo& ent, TInfoSink& infoSink) override;
|
||||
const TString& getAccessName(const TIntermSymbol*);
|
||||
// in/out symbol and uniform symbol are stored in the same resourceSlotMap, the storage key is used to identify each type of symbol.
|
||||
// We use stage and storage qualifier to construct a storage key. it can help us identify the same storage resource used in different stage.
|
||||
// if a resource is a program resource and we don't need know it usage stage, we can use same stage to build storage key.
|
||||
// Note: both stage and type must less then 0xffff.
|
||||
int buildStorageKey(EShLanguage stage, TStorageQualifier type) {
|
||||
assert(static_cast<uint32_t>(stage) <= 0x0000ffff && static_cast<uint32_t>(type) <= 0x0000ffff);
|
||||
return (stage << 16) | type;
|
||||
}
|
||||
|
||||
protected:
|
||||
// Use for mark pre stage, to get more interface symbol information.
|
||||
EShLanguage preStage;
|
||||
// Use for mark current shader stage for resolver
|
||||
EShLanguage currentStage;
|
||||
// Slot map for storage resource(location of uniform and interface symbol) It's a program share slot
|
||||
TSlotMap resourceSlotMap;
|
||||
// Slot map for other resource(image, ubo, ssbo), It's a program share slot.
|
||||
TSlotMap storageSlotMap;
|
||||
};
|
||||
|
||||
typedef std::map<TString, TVarEntryInfo> TVarLiveMap;
|
||||
|
||||
// override function "operator=", if a vector<const _Kty, _Ty> being sort,
|
||||
// when use vc++, the sort function will call :
|
||||
// pair& operator=(const pair<_Other1, _Other2>& _Right)
|
||||
// {
|
||||
// first = _Right.first;
|
||||
// second = _Right.second;
|
||||
// return (*this);
|
||||
// }
|
||||
// that will make a const type handing on left.
|
||||
// override this function can avoid a compiler error.
|
||||
// In the future, if the vc++ compiler can handle such a situation,
|
||||
// this part of the code will be removed.
|
||||
struct TVarLivePair : std::pair<const TString, TVarEntryInfo> {
|
||||
TVarLivePair(const std::pair<const TString, TVarEntryInfo>& _Right) : pair(_Right.first, _Right.second) {}
|
||||
TVarLivePair& operator=(const TVarLivePair& _Right) {
|
||||
const_cast<TString&>(first) = _Right.first;
|
||||
second = _Right.second;
|
||||
return (*this);
|
||||
}
|
||||
TVarLivePair(const TVarLivePair& src) : pair(src) { }
|
||||
};
|
||||
typedef std::vector<TVarLivePair> TVarLiveVector;
|
||||
|
||||
// I/O mapper
|
||||
class TIoMapper {
|
||||
public:
|
||||
TIoMapper() {}
|
||||
virtual ~TIoMapper() {}
|
||||
// grow the reflection stage by stage
|
||||
bool virtual addStage(EShLanguage, TIntermediate&, TInfoSink&, TIoMapResolver*);
|
||||
bool virtual doMap(TIoMapResolver*, TInfoSink&) { return true; }
|
||||
};
|
||||
|
||||
// I/O mapper for OpenGL
|
||||
class TGlslIoMapper : public TIoMapper {
|
||||
public:
|
||||
TGlslIoMapper() {
|
||||
memset(inVarMaps, 0, sizeof(TVarLiveMap*) * EShLangCount);
|
||||
memset(outVarMaps, 0, sizeof(TVarLiveMap*) * EShLangCount);
|
||||
memset(uniformVarMap, 0, sizeof(TVarLiveMap*) * EShLangCount);
|
||||
memset(intermediates, 0, sizeof(TIntermediate*) * EShLangCount);
|
||||
}
|
||||
virtual ~TGlslIoMapper() {
|
||||
for (size_t stage = 0; stage < EShLangCount; stage++) {
|
||||
if (inVarMaps[stage] != nullptr) {
|
||||
delete inVarMaps[stage];
|
||||
inVarMaps[stage] = nullptr;
|
||||
}
|
||||
if (outVarMaps[stage] != nullptr) {
|
||||
delete outVarMaps[stage];
|
||||
outVarMaps[stage] = nullptr;
|
||||
}
|
||||
if (uniformVarMap[stage] != nullptr) {
|
||||
delete uniformVarMap[stage];
|
||||
uniformVarMap[stage] = nullptr;
|
||||
}
|
||||
if (intermediates[stage] != nullptr)
|
||||
intermediates[stage] = nullptr;
|
||||
}
|
||||
}
|
||||
// grow the reflection stage by stage
|
||||
bool addStage(EShLanguage, TIntermediate&, TInfoSink&, TIoMapResolver*) override;
|
||||
bool doMap(TIoMapResolver*, TInfoSink&) override;
|
||||
TVarLiveMap *inVarMaps[EShLangCount], *outVarMaps[EShLangCount],
|
||||
*uniformVarMap[EShLangCount];
|
||||
TIntermediate* intermediates[EShLangCount];
|
||||
bool hadError = false;
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _IOMAPPER_INCLUDED
|
||||
|
||||
#endif // GLSLANG_WEB
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,240 @@
|
|||
//
|
||||
// Copyright (C) 2015-2018 Google, 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.
|
||||
//
|
||||
|
||||
// This is implemented in Versions.cpp
|
||||
|
||||
#ifndef _PARSE_VERSIONS_INCLUDED_
|
||||
#define _PARSE_VERSIONS_INCLUDED_
|
||||
|
||||
#include "../Public/ShaderLang.h"
|
||||
#include "../Include/InfoSink.h"
|
||||
#include "Scan.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace glslang {
|
||||
|
||||
//
|
||||
// Base class for parse helpers.
|
||||
// This just has version-related information and checking.
|
||||
// This class should be sufficient for preprocessing.
|
||||
//
|
||||
class TParseVersions {
|
||||
public:
|
||||
TParseVersions(TIntermediate& interm, int version, EProfile profile,
|
||||
const SpvVersion& spvVersion, EShLanguage language, TInfoSink& infoSink,
|
||||
bool forwardCompatible, EShMessages messages)
|
||||
:
|
||||
#ifndef GLSLANG_WEB
|
||||
forwardCompatible(forwardCompatible),
|
||||
profile(profile),
|
||||
#endif
|
||||
infoSink(infoSink), version(version),
|
||||
language(language),
|
||||
spvVersion(spvVersion),
|
||||
intermediate(interm), messages(messages), numErrors(0), currentScanner(0) { }
|
||||
virtual ~TParseVersions() { }
|
||||
void requireStage(const TSourceLoc&, EShLanguageMask, const char* featureDesc);
|
||||
void requireStage(const TSourceLoc&, EShLanguage, const char* featureDesc);
|
||||
#ifdef GLSLANG_WEB
|
||||
const EProfile profile = EEsProfile;
|
||||
bool isEsProfile() const { return true; }
|
||||
void requireProfile(const TSourceLoc& loc, int profileMask, const char* featureDesc)
|
||||
{
|
||||
if (! (EEsProfile & profileMask))
|
||||
error(loc, "not supported with this profile:", featureDesc, ProfileName(profile));
|
||||
}
|
||||
void profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, int numExtensions,
|
||||
const char* const extensions[], const char* featureDesc)
|
||||
{
|
||||
if ((EEsProfile & profileMask) && (minVersion == 0 || version < minVersion))
|
||||
error(loc, "not supported for this version or the enabled extensions", featureDesc, "");
|
||||
}
|
||||
void profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, const char* extension,
|
||||
const char* featureDesc)
|
||||
{
|
||||
profileRequires(loc, profileMask, minVersion, extension ? 1 : 0, &extension, featureDesc);
|
||||
}
|
||||
void initializeExtensionBehavior() { }
|
||||
void checkDeprecated(const TSourceLoc&, int queryProfiles, int depVersion, const char* featureDesc) { }
|
||||
void requireNotRemoved(const TSourceLoc&, int queryProfiles, int removedVersion, const char* featureDesc) { }
|
||||
void requireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[],
|
||||
const char* featureDesc) { }
|
||||
void ppRequireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[],
|
||||
const char* featureDesc) { }
|
||||
TExtensionBehavior getExtensionBehavior(const char*) { return EBhMissing; }
|
||||
bool extensionTurnedOn(const char* const extension) { return false; }
|
||||
bool extensionsTurnedOn(int numExtensions, const char* const extensions[]) { return false; }
|
||||
void updateExtensionBehavior(int line, const char* const extension, const char* behavior) { }
|
||||
void updateExtensionBehavior(const char* const extension, TExtensionBehavior) { }
|
||||
void checkExtensionStage(const TSourceLoc&, const char* const extension) { }
|
||||
void extensionRequires(const TSourceLoc&, const char* const extension, const char* behavior) { }
|
||||
void fullIntegerCheck(const TSourceLoc&, const char* op) { }
|
||||
void doubleCheck(const TSourceLoc&, const char* op) { }
|
||||
bool float16Arithmetic() { return false; }
|
||||
void requireFloat16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc) { }
|
||||
bool int16Arithmetic() { return false; }
|
||||
void requireInt16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc) { }
|
||||
bool int8Arithmetic() { return false; }
|
||||
void requireInt8Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc) { }
|
||||
void int64Check(const TSourceLoc&, const char* op, bool builtIn = false) { }
|
||||
void explicitFloat32Check(const TSourceLoc&, const char* op, bool builtIn = false) { }
|
||||
void explicitFloat64Check(const TSourceLoc&, const char* op, bool builtIn = false) { }
|
||||
bool relaxedErrors() const { return false; }
|
||||
bool suppressWarnings() const { return true; }
|
||||
bool isForwardCompatible() const { return false; }
|
||||
#else
|
||||
bool forwardCompatible; // true if errors are to be given for use of deprecated features
|
||||
EProfile profile; // the declared profile in the shader (core by default)
|
||||
bool isEsProfile() const { return profile == EEsProfile; }
|
||||
void requireProfile(const TSourceLoc& loc, int profileMask, const char* featureDesc);
|
||||
void profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, int numExtensions,
|
||||
const char* const extensions[], const char* featureDesc);
|
||||
void profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, const char* extension,
|
||||
const char* featureDesc);
|
||||
virtual void initializeExtensionBehavior();
|
||||
virtual void checkDeprecated(const TSourceLoc&, int queryProfiles, int depVersion, const char* featureDesc);
|
||||
virtual void requireNotRemoved(const TSourceLoc&, int queryProfiles, int removedVersion, const char* featureDesc);
|
||||
virtual void requireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[],
|
||||
const char* featureDesc);
|
||||
virtual void ppRequireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[],
|
||||
const char* featureDesc);
|
||||
virtual TExtensionBehavior getExtensionBehavior(const char*);
|
||||
virtual bool extensionTurnedOn(const char* const extension);
|
||||
virtual bool extensionsTurnedOn(int numExtensions, const char* const extensions[]);
|
||||
virtual void updateExtensionBehavior(int line, const char* const extension, const char* behavior);
|
||||
virtual void updateExtensionBehavior(const char* const extension, TExtensionBehavior);
|
||||
virtual bool checkExtensionsRequested(const TSourceLoc&, int numExtensions, const char* const extensions[],
|
||||
const char* featureDesc);
|
||||
virtual void checkExtensionStage(const TSourceLoc&, const char* const extension);
|
||||
virtual void extensionRequires(const TSourceLoc&, const char* const extension, const char* behavior);
|
||||
virtual void fullIntegerCheck(const TSourceLoc&, const char* op);
|
||||
|
||||
virtual void unimplemented(const TSourceLoc&, const char* featureDesc);
|
||||
virtual void doubleCheck(const TSourceLoc&, const char* op);
|
||||
virtual void float16Check(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||
virtual void float16ScalarVectorCheck(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||
virtual bool float16Arithmetic();
|
||||
virtual void requireFloat16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc);
|
||||
virtual void int16ScalarVectorCheck(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||
virtual bool int16Arithmetic();
|
||||
virtual void requireInt16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc);
|
||||
virtual void int8ScalarVectorCheck(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||
virtual bool int8Arithmetic();
|
||||
virtual void requireInt8Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc);
|
||||
virtual void float16OpaqueCheck(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||
virtual void int64Check(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||
virtual void explicitInt8Check(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||
virtual void explicitInt16Check(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||
virtual void explicitInt32Check(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||
virtual void explicitFloat32Check(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||
virtual void explicitFloat64Check(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||
virtual void fcoopmatCheck(const TSourceLoc&, const char* op, bool builtIn = false);
|
||||
virtual void intcoopmatCheck(const TSourceLoc&, const char *op, bool builtIn = false);
|
||||
bool relaxedErrors() const { return (messages & EShMsgRelaxedErrors) != 0; }
|
||||
bool suppressWarnings() const { return (messages & EShMsgSuppressWarnings) != 0; }
|
||||
bool isForwardCompatible() const { return forwardCompatible; }
|
||||
#endif // GLSLANG_WEB
|
||||
virtual void spvRemoved(const TSourceLoc&, const char* op);
|
||||
virtual void vulkanRemoved(const TSourceLoc&, const char* op);
|
||||
virtual void requireVulkan(const TSourceLoc&, const char* op);
|
||||
virtual void requireSpv(const TSourceLoc&, const char* op);
|
||||
virtual void requireSpv(const TSourceLoc&, const char *op, unsigned int version);
|
||||
|
||||
|
||||
#if defined(GLSLANG_WEB) && !defined(GLSLANG_WEB_DEVEL)
|
||||
void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||
const char* szExtraInfoFormat, ...) { addError(); }
|
||||
void C_DECL warn(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||
const char* szExtraInfoFormat, ...) { }
|
||||
void C_DECL ppError(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||
const char* szExtraInfoFormat, ...) { addError(); }
|
||||
void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||
const char* szExtraInfoFormat, ...) { }
|
||||
#else
|
||||
virtual void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||
const char* szExtraInfoFormat, ...) = 0;
|
||||
virtual void C_DECL warn(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||
const char* szExtraInfoFormat, ...) = 0;
|
||||
virtual void C_DECL ppError(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||
const char* szExtraInfoFormat, ...) = 0;
|
||||
virtual void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||
const char* szExtraInfoFormat, ...) = 0;
|
||||
#endif
|
||||
|
||||
void addError() { ++numErrors; }
|
||||
int getNumErrors() const { return numErrors; }
|
||||
|
||||
void setScanner(TInputScanner* scanner) { currentScanner = scanner; }
|
||||
TInputScanner* getScanner() const { return currentScanner; }
|
||||
const TSourceLoc& getCurrentLoc() const { return currentScanner->getSourceLoc(); }
|
||||
void setCurrentLine(int line) { currentScanner->setLine(line); }
|
||||
void setCurrentColumn(int col) { currentScanner->setColumn(col); }
|
||||
void setCurrentSourceName(const char* name) { currentScanner->setFile(name); }
|
||||
void setCurrentString(int string) { currentScanner->setString(string); }
|
||||
|
||||
void getPreamble(std::string&);
|
||||
#ifdef ENABLE_HLSL
|
||||
bool isReadingHLSL() const { return (messages & EShMsgReadHlsl) == EShMsgReadHlsl; }
|
||||
bool hlslEnable16BitTypes() const { return (messages & EShMsgHlslEnable16BitTypes) != 0; }
|
||||
bool hlslDX9Compatible() const { return (messages & EShMsgHlslDX9Compatible) != 0; }
|
||||
#else
|
||||
bool isReadingHLSL() const { return false; }
|
||||
#endif
|
||||
|
||||
TInfoSink& infoSink;
|
||||
|
||||
// compilation mode
|
||||
int version; // version, updated by #version in the shader
|
||||
EShLanguage language; // really the stage
|
||||
SpvVersion spvVersion;
|
||||
TIntermediate& intermediate; // helper for making and hooking up pieces of the parse tree
|
||||
|
||||
protected:
|
||||
TMap<TString, TExtensionBehavior> extensionBehavior; // for each extension string, what its current behavior is set to
|
||||
TMap<TString, unsigned int> extensionMinSpv; // for each extension string, store minimum spirv required
|
||||
EShMessages messages; // errors/warnings/rule-sets
|
||||
int numErrors; // number of compile-time errors encountered
|
||||
TInputScanner* currentScanner;
|
||||
|
||||
private:
|
||||
explicit TParseVersions(const TParseVersions&);
|
||||
TParseVersions& operator=(const TParseVersions&);
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _PARSE_VERSIONS_INCLUDED_
|
||||
|
|
@ -0,0 +1,703 @@
|
|||
//
|
||||
// Copyright (C) 2013 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.
|
||||
//
|
||||
/****************************************************************************\
|
||||
Copyright (c) 2002, NVIDIA Corporation.
|
||||
|
||||
NVIDIA Corporation("NVIDIA") supplies this software to you in
|
||||
consideration of your agreement to the following terms, and your use,
|
||||
installation, modification or redistribution of this NVIDIA software
|
||||
constitutes acceptance of these terms. If you do not agree with these
|
||||
terms, please do not use, install, modify or redistribute this NVIDIA
|
||||
software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and
|
||||
subject to these terms, NVIDIA grants you a personal, non-exclusive
|
||||
license, under NVIDIA's copyrights in this original NVIDIA software (the
|
||||
"NVIDIA Software"), to use, reproduce, modify and redistribute the
|
||||
NVIDIA Software, with or without modifications, in source and/or binary
|
||||
forms; provided that if you redistribute the NVIDIA Software, you must
|
||||
retain the copyright notice of NVIDIA, this notice and the following
|
||||
text and disclaimers in all such redistributions of the NVIDIA Software.
|
||||
Neither the name, trademarks, service marks nor logos of NVIDIA
|
||||
Corporation may be used to endorse or promote products derived from the
|
||||
NVIDIA Software without specific prior written permission from NVIDIA.
|
||||
Except as expressly stated in this notice, no other rights or licenses
|
||||
express or implied, are granted by NVIDIA herein, including but not
|
||||
limited to any patent rights that may be infringed by your derivative
|
||||
works or by other works in which the NVIDIA Software may be
|
||||
incorporated. No hardware is licensed hereunder.
|
||||
|
||||
THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
|
||||
WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
|
||||
ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
|
||||
PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
|
||||
INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
|
||||
OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
|
||||
NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
|
||||
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
|
||||
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
\****************************************************************************/
|
||||
|
||||
#ifndef PPCONTEXT_H
|
||||
#define PPCONTEXT_H
|
||||
|
||||
#include <stack>
|
||||
#include <unordered_map>
|
||||
#include <sstream>
|
||||
|
||||
#include "../ParseHelper.h"
|
||||
#include "PpTokens.h"
|
||||
|
||||
/* windows only pragma */
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4127)
|
||||
#endif
|
||||
|
||||
namespace glslang {
|
||||
|
||||
class TPpToken {
|
||||
public:
|
||||
TPpToken() { clear(); }
|
||||
void clear()
|
||||
{
|
||||
space = false;
|
||||
i64val = 0;
|
||||
loc.init();
|
||||
name[0] = 0;
|
||||
}
|
||||
|
||||
// Used for comparing macro definitions, so checks what is relevant for that.
|
||||
bool operator==(const TPpToken& right) const
|
||||
{
|
||||
return space == right.space &&
|
||||
ival == right.ival && dval == right.dval && i64val == right.i64val &&
|
||||
strncmp(name, right.name, MaxTokenLength) == 0;
|
||||
}
|
||||
bool operator!=(const TPpToken& right) const { return ! operator==(right); }
|
||||
|
||||
TSourceLoc loc;
|
||||
// True if a space (for white space or a removed comment) should also be
|
||||
// recognized, in front of the token returned:
|
||||
bool space;
|
||||
// Numeric value of the token:
|
||||
union {
|
||||
int ival;
|
||||
double dval;
|
||||
long long i64val;
|
||||
};
|
||||
// Text string of the token:
|
||||
char name[MaxTokenLength + 1];
|
||||
};
|
||||
|
||||
class TStringAtomMap {
|
||||
//
|
||||
// Implementation is in PpAtom.cpp
|
||||
//
|
||||
// Maintain a bi-directional mapping between relevant preprocessor strings and
|
||||
// "atoms" which a unique integers (small, contiguous, not hash-like) per string.
|
||||
//
|
||||
public:
|
||||
TStringAtomMap();
|
||||
|
||||
// Map string -> atom.
|
||||
// Return 0 if no existing string.
|
||||
int getAtom(const char* s) const
|
||||
{
|
||||
auto it = atomMap.find(s);
|
||||
return it == atomMap.end() ? 0 : it->second;
|
||||
}
|
||||
|
||||
// Map a new or existing string -> atom, inventing a new atom if necessary.
|
||||
int getAddAtom(const char* s)
|
||||
{
|
||||
int atom = getAtom(s);
|
||||
if (atom == 0) {
|
||||
atom = nextAtom++;
|
||||
addAtomFixed(s, atom);
|
||||
}
|
||||
return atom;
|
||||
}
|
||||
|
||||
// Map atom -> string.
|
||||
const char* getString(int atom) const { return stringMap[atom]->c_str(); }
|
||||
|
||||
protected:
|
||||
TStringAtomMap(TStringAtomMap&);
|
||||
TStringAtomMap& operator=(TStringAtomMap&);
|
||||
|
||||
TUnorderedMap<TString, int> atomMap;
|
||||
TVector<const TString*> stringMap; // these point into the TString in atomMap
|
||||
int nextAtom;
|
||||
|
||||
// Bad source characters can lead to bad atoms, so gracefully handle those by
|
||||
// pre-filling the table with them (to avoid if tests later).
|
||||
TString badToken;
|
||||
|
||||
// Add bi-directional mappings:
|
||||
// - string -> atom
|
||||
// - atom -> string
|
||||
void addAtomFixed(const char* s, int atom)
|
||||
{
|
||||
auto it = atomMap.insert(std::pair<TString, int>(s, atom)).first;
|
||||
if (stringMap.size() < (size_t)atom + 1)
|
||||
stringMap.resize(atom + 100, &badToken);
|
||||
stringMap[atom] = &it->first;
|
||||
}
|
||||
};
|
||||
|
||||
class TInputScanner;
|
||||
|
||||
enum MacroExpandResult {
|
||||
MacroExpandNotStarted, // macro not expanded, which might not be an error
|
||||
MacroExpandError, // a clear error occurred while expanding, no expansion
|
||||
MacroExpandStarted, // macro expansion process has started
|
||||
MacroExpandUndef // macro is undefined and will be expanded
|
||||
};
|
||||
|
||||
// This class is the result of turning a huge pile of C code communicating through globals
|
||||
// into a class. This was done to allowing instancing to attain thread safety.
|
||||
// Don't expect too much in terms of OO design.
|
||||
class TPpContext {
|
||||
public:
|
||||
TPpContext(TParseContextBase&, const std::string& rootFileName, TShader::Includer&);
|
||||
virtual ~TPpContext();
|
||||
|
||||
void setPreamble(const char* preamble, size_t length);
|
||||
|
||||
int tokenize(TPpToken& ppToken);
|
||||
int tokenPaste(int token, TPpToken&);
|
||||
|
||||
class tInput {
|
||||
public:
|
||||
tInput(TPpContext* p) : done(false), pp(p) { }
|
||||
virtual ~tInput() { }
|
||||
|
||||
virtual int scan(TPpToken*) = 0;
|
||||
virtual int getch() = 0;
|
||||
virtual void ungetch() = 0;
|
||||
virtual bool peekPasting() { return false; } // true when about to see ##
|
||||
virtual bool peekContinuedPasting(int) { return false; } // true when non-spaced tokens can paste
|
||||
virtual bool endOfReplacementList() { return false; } // true when at the end of a macro replacement list (RHS of #define)
|
||||
virtual bool isMacroInput() { return false; }
|
||||
|
||||
// Will be called when we start reading tokens from this instance
|
||||
virtual void notifyActivated() {}
|
||||
// Will be called when we do not read tokens from this instance anymore
|
||||
virtual void notifyDeleted() {}
|
||||
protected:
|
||||
bool done;
|
||||
TPpContext* pp;
|
||||
};
|
||||
|
||||
void setInput(TInputScanner& input, bool versionWillBeError);
|
||||
|
||||
void pushInput(tInput* in)
|
||||
{
|
||||
inputStack.push_back(in);
|
||||
in->notifyActivated();
|
||||
}
|
||||
void popInput()
|
||||
{
|
||||
inputStack.back()->notifyDeleted();
|
||||
delete inputStack.back();
|
||||
inputStack.pop_back();
|
||||
}
|
||||
|
||||
//
|
||||
// From PpTokens.cpp
|
||||
//
|
||||
|
||||
// Capture the needed parts of a token stream for macro recording/playback.
|
||||
class TokenStream {
|
||||
public:
|
||||
// Manage a stream of these 'Token', which capture the relevant parts
|
||||
// of a TPpToken, plus its atom.
|
||||
class Token {
|
||||
public:
|
||||
Token(int atom, const TPpToken& ppToken) :
|
||||
atom(atom),
|
||||
space(ppToken.space),
|
||||
i64val(ppToken.i64val),
|
||||
name(ppToken.name) { }
|
||||
int get(TPpToken& ppToken)
|
||||
{
|
||||
ppToken.clear();
|
||||
ppToken.space = space;
|
||||
ppToken.i64val = i64val;
|
||||
snprintf(ppToken.name, sizeof(ppToken.name), "%s", name.c_str());
|
||||
return atom;
|
||||
}
|
||||
bool isAtom(int a) const { return atom == a; }
|
||||
int getAtom() const { return atom; }
|
||||
bool nonSpaced() const { return !space; }
|
||||
protected:
|
||||
Token() {}
|
||||
int atom;
|
||||
bool space; // did a space precede the token?
|
||||
long long i64val;
|
||||
TString name;
|
||||
};
|
||||
|
||||
TokenStream() : currentPos(0) { }
|
||||
|
||||
void putToken(int token, TPpToken* ppToken);
|
||||
bool peekToken(int atom) { return !atEnd() && stream[currentPos].isAtom(atom); }
|
||||
bool peekContinuedPasting(int atom)
|
||||
{
|
||||
// This is basically necessary because, for example, the PP
|
||||
// tokenizer only accepts valid numeric-literals plus suffixes, so
|
||||
// separates numeric-literals plus bad suffix into two tokens, which
|
||||
// should get both pasted together as one token when token pasting.
|
||||
//
|
||||
// The following code is a bit more generalized than the above example.
|
||||
if (!atEnd() && atom == PpAtomIdentifier && stream[currentPos].nonSpaced()) {
|
||||
switch(stream[currentPos].getAtom()) {
|
||||
case PpAtomConstInt:
|
||||
case PpAtomConstUint:
|
||||
case PpAtomConstInt64:
|
||||
case PpAtomConstUint64:
|
||||
case PpAtomConstInt16:
|
||||
case PpAtomConstUint16:
|
||||
case PpAtomConstFloat:
|
||||
case PpAtomConstDouble:
|
||||
case PpAtomConstFloat16:
|
||||
case PpAtomConstString:
|
||||
case PpAtomIdentifier:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
int getToken(TParseContextBase&, TPpToken*);
|
||||
bool atEnd() { return currentPos >= stream.size(); }
|
||||
bool peekTokenizedPasting(bool lastTokenPastes);
|
||||
bool peekUntokenizedPasting();
|
||||
void reset() { currentPos = 0; }
|
||||
|
||||
protected:
|
||||
TVector<Token> stream;
|
||||
size_t currentPos;
|
||||
};
|
||||
|
||||
//
|
||||
// From Pp.cpp
|
||||
//
|
||||
|
||||
struct MacroSymbol {
|
||||
MacroSymbol() : functionLike(0), busy(0), undef(0) { }
|
||||
TVector<int> args;
|
||||
TokenStream body;
|
||||
unsigned functionLike : 1; // 0 means object-like, 1 means function-like
|
||||
unsigned busy : 1;
|
||||
unsigned undef : 1;
|
||||
};
|
||||
|
||||
typedef TMap<int, MacroSymbol> TSymbolMap;
|
||||
TSymbolMap macroDefs; // map atoms to macro definitions
|
||||
MacroSymbol* lookupMacroDef(int atom)
|
||||
{
|
||||
auto existingMacroIt = macroDefs.find(atom);
|
||||
return (existingMacroIt == macroDefs.end()) ? nullptr : &(existingMacroIt->second);
|
||||
}
|
||||
void addMacroDef(int atom, MacroSymbol& macroDef) { macroDefs[atom] = macroDef; }
|
||||
|
||||
protected:
|
||||
TPpContext(TPpContext&);
|
||||
TPpContext& operator=(TPpContext&);
|
||||
|
||||
TStringAtomMap atomStrings;
|
||||
char* preamble; // string to parse, all before line 1 of string 0, it is 0 if no preamble
|
||||
int preambleLength;
|
||||
char** strings; // official strings of shader, starting a string 0 line 1
|
||||
size_t* lengths;
|
||||
int numStrings; // how many official strings there are
|
||||
int currentString; // which string we're currently parsing (-1 for preamble)
|
||||
|
||||
// Scanner data:
|
||||
int previous_token;
|
||||
TParseContextBase& parseContext;
|
||||
|
||||
// Get the next token from *stack* of input sources, popping input sources
|
||||
// that are out of tokens, down until an input source is found that has a token.
|
||||
// Return EndOfInput when there are no more tokens to be found by doing this.
|
||||
int scanToken(TPpToken* ppToken)
|
||||
{
|
||||
int token = EndOfInput;
|
||||
|
||||
while (! inputStack.empty()) {
|
||||
token = inputStack.back()->scan(ppToken);
|
||||
if (token != EndOfInput || inputStack.empty())
|
||||
break;
|
||||
popInput();
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
int getChar() { return inputStack.back()->getch(); }
|
||||
void ungetChar() { inputStack.back()->ungetch(); }
|
||||
bool peekPasting() { return !inputStack.empty() && inputStack.back()->peekPasting(); }
|
||||
bool peekContinuedPasting(int a)
|
||||
{
|
||||
return !inputStack.empty() && inputStack.back()->peekContinuedPasting(a);
|
||||
}
|
||||
bool endOfReplacementList() { return inputStack.empty() || inputStack.back()->endOfReplacementList(); }
|
||||
bool isMacroInput() { return inputStack.size() > 0 && inputStack.back()->isMacroInput(); }
|
||||
|
||||
static const int maxIfNesting = 65;
|
||||
|
||||
int ifdepth; // current #if-#else-#endif nesting in the cpp.c file (pre-processor)
|
||||
bool elseSeen[maxIfNesting]; // Keep a track of whether an else has been seen at a particular depth
|
||||
int elsetracker; // #if-#else and #endif constructs...Counter.
|
||||
|
||||
class tMacroInput : public tInput {
|
||||
public:
|
||||
tMacroInput(TPpContext* pp) : tInput(pp), prepaste(false), postpaste(false) { }
|
||||
virtual ~tMacroInput()
|
||||
{
|
||||
for (size_t i = 0; i < args.size(); ++i)
|
||||
delete args[i];
|
||||
for (size_t i = 0; i < expandedArgs.size(); ++i)
|
||||
delete expandedArgs[i];
|
||||
}
|
||||
|
||||
virtual int scan(TPpToken*) override;
|
||||
virtual int getch() override { assert(0); return EndOfInput; }
|
||||
virtual void ungetch() override { assert(0); }
|
||||
bool peekPasting() override { return prepaste; }
|
||||
bool peekContinuedPasting(int a) override { return mac->body.peekContinuedPasting(a); }
|
||||
bool endOfReplacementList() override { return mac->body.atEnd(); }
|
||||
bool isMacroInput() override { return true; }
|
||||
|
||||
MacroSymbol *mac;
|
||||
TVector<TokenStream*> args;
|
||||
TVector<TokenStream*> expandedArgs;
|
||||
|
||||
protected:
|
||||
bool prepaste; // true if we are just before ##
|
||||
bool postpaste; // true if we are right after ##
|
||||
};
|
||||
|
||||
class tMarkerInput : public tInput {
|
||||
public:
|
||||
tMarkerInput(TPpContext* pp) : tInput(pp) { }
|
||||
virtual int scan(TPpToken*) override
|
||||
{
|
||||
if (done)
|
||||
return EndOfInput;
|
||||
done = true;
|
||||
|
||||
return marker;
|
||||
}
|
||||
virtual int getch() override { assert(0); return EndOfInput; }
|
||||
virtual void ungetch() override { assert(0); }
|
||||
static const int marker = -3;
|
||||
};
|
||||
|
||||
class tZeroInput : public tInput {
|
||||
public:
|
||||
tZeroInput(TPpContext* pp) : tInput(pp) { }
|
||||
virtual int scan(TPpToken*) override;
|
||||
virtual int getch() override { assert(0); return EndOfInput; }
|
||||
virtual void ungetch() override { assert(0); }
|
||||
};
|
||||
|
||||
std::vector<tInput*> inputStack;
|
||||
bool errorOnVersion;
|
||||
bool versionSeen;
|
||||
|
||||
//
|
||||
// from Pp.cpp
|
||||
//
|
||||
|
||||
// Used to obtain #include content.
|
||||
TShader::Includer& includer;
|
||||
|
||||
int CPPdefine(TPpToken * ppToken);
|
||||
int CPPundef(TPpToken * ppToken);
|
||||
int CPPelse(int matchelse, TPpToken * ppToken);
|
||||
int extraTokenCheck(int atom, TPpToken* ppToken, int token);
|
||||
int eval(int token, int precedence, bool shortCircuit, int& res, bool& err, TPpToken * ppToken);
|
||||
int evalToToken(int token, bool shortCircuit, int& res, bool& err, TPpToken * ppToken);
|
||||
int CPPif (TPpToken * ppToken);
|
||||
int CPPifdef(int defined, TPpToken * ppToken);
|
||||
int CPPinclude(TPpToken * ppToken);
|
||||
int CPPline(TPpToken * ppToken);
|
||||
int CPPerror(TPpToken * ppToken);
|
||||
int CPPpragma(TPpToken * ppToken);
|
||||
int CPPversion(TPpToken * ppToken);
|
||||
int CPPextension(TPpToken * ppToken);
|
||||
int readCPPline(TPpToken * ppToken);
|
||||
int scanHeaderName(TPpToken* ppToken, char delimit);
|
||||
TokenStream* PrescanMacroArg(TokenStream&, TPpToken*, bool newLineOkay);
|
||||
MacroExpandResult MacroExpand(TPpToken* ppToken, bool expandUndef, bool newLineOkay);
|
||||
|
||||
//
|
||||
// From PpTokens.cpp
|
||||
//
|
||||
void pushTokenStreamInput(TokenStream&, bool pasting = false);
|
||||
void UngetToken(int token, TPpToken*);
|
||||
|
||||
class tTokenInput : public tInput {
|
||||
public:
|
||||
tTokenInput(TPpContext* pp, TokenStream* t, bool prepasting) :
|
||||
tInput(pp),
|
||||
tokens(t),
|
||||
lastTokenPastes(prepasting) { }
|
||||
virtual int scan(TPpToken *ppToken) override { return tokens->getToken(pp->parseContext, ppToken); }
|
||||
virtual int getch() override { assert(0); return EndOfInput; }
|
||||
virtual void ungetch() override { assert(0); }
|
||||
virtual bool peekPasting() override { return tokens->peekTokenizedPasting(lastTokenPastes); }
|
||||
bool peekContinuedPasting(int a) override { return tokens->peekContinuedPasting(a); }
|
||||
protected:
|
||||
TokenStream* tokens;
|
||||
bool lastTokenPastes; // true if the last token in the input is to be pasted, rather than consumed as a token
|
||||
};
|
||||
|
||||
class tUngotTokenInput : public tInput {
|
||||
public:
|
||||
tUngotTokenInput(TPpContext* pp, int t, TPpToken* p) : tInput(pp), token(t), lval(*p) { }
|
||||
virtual int scan(TPpToken *) override;
|
||||
virtual int getch() override { assert(0); return EndOfInput; }
|
||||
virtual void ungetch() override { assert(0); }
|
||||
protected:
|
||||
int token;
|
||||
TPpToken lval;
|
||||
};
|
||||
|
||||
//
|
||||
// From PpScanner.cpp
|
||||
//
|
||||
class tStringInput : public tInput {
|
||||
public:
|
||||
tStringInput(TPpContext* pp, TInputScanner& i) : tInput(pp), input(&i) { }
|
||||
virtual int scan(TPpToken*) override;
|
||||
|
||||
// Scanner used to get source stream characters.
|
||||
// - Escaped newlines are handled here, invisibly to the caller.
|
||||
// - All forms of newline are handled, and turned into just a '\n'.
|
||||
int getch() override
|
||||
{
|
||||
int ch = input->get();
|
||||
|
||||
if (ch == '\\') {
|
||||
// Move past escaped newlines, as many as sequentially exist
|
||||
do {
|
||||
if (input->peek() == '\r' || input->peek() == '\n') {
|
||||
bool allowed = pp->parseContext.lineContinuationCheck(input->getSourceLoc(), pp->inComment);
|
||||
if (! allowed && pp->inComment)
|
||||
return '\\';
|
||||
|
||||
// escape one newline now
|
||||
ch = input->get();
|
||||
int nextch = input->get();
|
||||
if (ch == '\r' && nextch == '\n')
|
||||
ch = input->get();
|
||||
else
|
||||
ch = nextch;
|
||||
} else
|
||||
return '\\';
|
||||
} while (ch == '\\');
|
||||
}
|
||||
|
||||
// handle any non-escaped newline
|
||||
if (ch == '\r' || ch == '\n') {
|
||||
if (ch == '\r' && input->peek() == '\n')
|
||||
input->get();
|
||||
return '\n';
|
||||
}
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
// Scanner used to backup the source stream characters. Newlines are
|
||||
// handled here, invisibly to the caller, meaning have to undo exactly
|
||||
// what getch() above does (e.g., don't leave things in the middle of a
|
||||
// sequence of escaped newlines).
|
||||
void ungetch() override
|
||||
{
|
||||
input->unget();
|
||||
|
||||
do {
|
||||
int ch = input->peek();
|
||||
if (ch == '\r' || ch == '\n') {
|
||||
if (ch == '\n') {
|
||||
// correct for two-character newline
|
||||
input->unget();
|
||||
if (input->peek() != '\r')
|
||||
input->get();
|
||||
}
|
||||
// now in front of a complete newline, move past an escape character
|
||||
input->unget();
|
||||
if (input->peek() == '\\')
|
||||
input->unget();
|
||||
else {
|
||||
input->get();
|
||||
break;
|
||||
}
|
||||
} else
|
||||
break;
|
||||
} while (true);
|
||||
}
|
||||
|
||||
protected:
|
||||
TInputScanner* input;
|
||||
};
|
||||
|
||||
// Holds a reference to included file data, as well as a
|
||||
// prologue and an epilogue string. This can be scanned using the tInput
|
||||
// interface and acts as a single source string.
|
||||
class TokenizableIncludeFile : public tInput {
|
||||
public:
|
||||
// Copies prologue and epilogue. The includedFile must remain valid
|
||||
// until this TokenizableIncludeFile is no longer used.
|
||||
TokenizableIncludeFile(const TSourceLoc& startLoc,
|
||||
const std::string& prologue,
|
||||
TShader::Includer::IncludeResult* includedFile,
|
||||
const std::string& epilogue,
|
||||
TPpContext* pp)
|
||||
: tInput(pp),
|
||||
prologue_(prologue),
|
||||
epilogue_(epilogue),
|
||||
includedFile_(includedFile),
|
||||
scanner(3, strings, lengths, nullptr, 0, 0, true),
|
||||
prevScanner(nullptr),
|
||||
stringInput(pp, scanner)
|
||||
{
|
||||
strings[0] = prologue_.data();
|
||||
strings[1] = includedFile_->headerData;
|
||||
strings[2] = epilogue_.data();
|
||||
|
||||
lengths[0] = prologue_.size();
|
||||
lengths[1] = includedFile_->headerLength;
|
||||
lengths[2] = epilogue_.size();
|
||||
|
||||
scanner.setLine(startLoc.line);
|
||||
scanner.setString(startLoc.string);
|
||||
|
||||
scanner.setFile(startLoc.getFilenameStr(), 0);
|
||||
scanner.setFile(startLoc.getFilenameStr(), 1);
|
||||
scanner.setFile(startLoc.getFilenameStr(), 2);
|
||||
}
|
||||
|
||||
// tInput methods:
|
||||
int scan(TPpToken* t) override { return stringInput.scan(t); }
|
||||
int getch() override { return stringInput.getch(); }
|
||||
void ungetch() override { stringInput.ungetch(); }
|
||||
|
||||
void notifyActivated() override
|
||||
{
|
||||
prevScanner = pp->parseContext.getScanner();
|
||||
pp->parseContext.setScanner(&scanner);
|
||||
pp->push_include(includedFile_);
|
||||
}
|
||||
|
||||
void notifyDeleted() override
|
||||
{
|
||||
pp->parseContext.setScanner(prevScanner);
|
||||
pp->pop_include();
|
||||
}
|
||||
|
||||
private:
|
||||
TokenizableIncludeFile& operator=(const TokenizableIncludeFile&);
|
||||
|
||||
// Stores the prologue for this string.
|
||||
const std::string prologue_;
|
||||
|
||||
// Stores the epilogue for this string.
|
||||
const std::string epilogue_;
|
||||
|
||||
// Points to the IncludeResult that this TokenizableIncludeFile represents.
|
||||
TShader::Includer::IncludeResult* includedFile_;
|
||||
|
||||
// Will point to prologue_, includedFile_->headerData and epilogue_
|
||||
// This is passed to scanner constructor.
|
||||
// These do not own the storage and it must remain valid until this
|
||||
// object has been destroyed.
|
||||
const char* strings[3];
|
||||
// Length of str_, passed to scanner constructor.
|
||||
size_t lengths[3];
|
||||
// Scans over str_.
|
||||
TInputScanner scanner;
|
||||
// The previous effective scanner before the scanner in this instance
|
||||
// has been activated.
|
||||
TInputScanner* prevScanner;
|
||||
// Delegate object implementing the tInput interface.
|
||||
tStringInput stringInput;
|
||||
};
|
||||
|
||||
int ScanFromString(char* s);
|
||||
void missingEndifCheck();
|
||||
int lFloatConst(int len, int ch, TPpToken* ppToken);
|
||||
int characterLiteral(TPpToken* ppToken);
|
||||
|
||||
void push_include(TShader::Includer::IncludeResult* result)
|
||||
{
|
||||
currentSourceFile = result->headerName;
|
||||
includeStack.push(result);
|
||||
}
|
||||
|
||||
void pop_include()
|
||||
{
|
||||
TShader::Includer::IncludeResult* include = includeStack.top();
|
||||
includeStack.pop();
|
||||
includer.releaseInclude(include);
|
||||
if (includeStack.empty()) {
|
||||
currentSourceFile = rootFileName;
|
||||
} else {
|
||||
currentSourceFile = includeStack.top()->headerName;
|
||||
}
|
||||
}
|
||||
|
||||
bool inComment;
|
||||
std::string rootFileName;
|
||||
std::stack<TShader::Includer::IncludeResult*> includeStack;
|
||||
std::string currentSourceFile;
|
||||
|
||||
std::istringstream strtodStream;
|
||||
bool disableEscapeSequences;
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // PPCONTEXT_H
|
||||
|
|
@ -0,0 +1,179 @@
|
|||
//
|
||||
// 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.
|
||||
//
|
||||
/****************************************************************************\
|
||||
Copyright (c) 2002, NVIDIA Corporation.
|
||||
|
||||
NVIDIA Corporation("NVIDIA") supplies this software to you in
|
||||
consideration of your agreement to the following terms, and your use,
|
||||
installation, modification or redistribution of this NVIDIA software
|
||||
constitutes acceptance of these terms. If you do not agree with these
|
||||
terms, please do not use, install, modify or redistribute this NVIDIA
|
||||
software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and
|
||||
subject to these terms, NVIDIA grants you a personal, non-exclusive
|
||||
license, under NVIDIA's copyrights in this original NVIDIA software (the
|
||||
"NVIDIA Software"), to use, reproduce, modify and redistribute the
|
||||
NVIDIA Software, with or without modifications, in source and/or binary
|
||||
forms; provided that if you redistribute the NVIDIA Software, you must
|
||||
retain the copyright notice of NVIDIA, this notice and the following
|
||||
text and disclaimers in all such redistributions of the NVIDIA Software.
|
||||
Neither the name, trademarks, service marks nor logos of NVIDIA
|
||||
Corporation may be used to endorse or promote products derived from the
|
||||
NVIDIA Software without specific prior written permission from NVIDIA.
|
||||
Except as expressly stated in this notice, no other rights or licenses
|
||||
express or implied, are granted by NVIDIA herein, including but not
|
||||
limited to any patent rights that may be infringed by your derivative
|
||||
works or by other works in which the NVIDIA Software may be
|
||||
incorporated. No hardware is licensed hereunder.
|
||||
|
||||
THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
|
||||
WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
|
||||
ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
|
||||
PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
|
||||
INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
|
||||
OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
|
||||
NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
|
||||
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
|
||||
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
\****************************************************************************/
|
||||
|
||||
#ifndef PARSER_H
|
||||
#define PARSER_H
|
||||
|
||||
namespace glslang {
|
||||
|
||||
// Multi-character tokens
|
||||
enum EFixedAtoms {
|
||||
// single character tokens get their own char value as their token; start here for multi-character tokens
|
||||
PpAtomMaxSingle = 127,
|
||||
|
||||
// replace bad character tokens with this, to avoid accidental aliasing with the below
|
||||
PpAtomBadToken,
|
||||
|
||||
// Operators
|
||||
|
||||
PPAtomAddAssign,
|
||||
PPAtomSubAssign,
|
||||
PPAtomMulAssign,
|
||||
PPAtomDivAssign,
|
||||
PPAtomModAssign,
|
||||
|
||||
PpAtomRight,
|
||||
PpAtomLeft,
|
||||
|
||||
PpAtomRightAssign,
|
||||
PpAtomLeftAssign,
|
||||
PpAtomAndAssign,
|
||||
PpAtomOrAssign,
|
||||
PpAtomXorAssign,
|
||||
|
||||
PpAtomAnd,
|
||||
PpAtomOr,
|
||||
PpAtomXor,
|
||||
|
||||
PpAtomEQ,
|
||||
PpAtomNE,
|
||||
PpAtomGE,
|
||||
PpAtomLE,
|
||||
|
||||
PpAtomDecrement,
|
||||
PpAtomIncrement,
|
||||
|
||||
PpAtomColonColon,
|
||||
|
||||
PpAtomPaste,
|
||||
|
||||
// Constants
|
||||
|
||||
PpAtomConstInt,
|
||||
PpAtomConstUint,
|
||||
PpAtomConstInt64,
|
||||
PpAtomConstUint64,
|
||||
PpAtomConstInt16,
|
||||
PpAtomConstUint16,
|
||||
PpAtomConstFloat,
|
||||
PpAtomConstDouble,
|
||||
PpAtomConstFloat16,
|
||||
PpAtomConstString,
|
||||
|
||||
// Identifiers
|
||||
PpAtomIdentifier,
|
||||
|
||||
// preprocessor "keywords"
|
||||
|
||||
PpAtomDefine,
|
||||
PpAtomUndef,
|
||||
|
||||
PpAtomIf,
|
||||
PpAtomIfdef,
|
||||
PpAtomIfndef,
|
||||
PpAtomElse,
|
||||
PpAtomElif,
|
||||
PpAtomEndif,
|
||||
|
||||
PpAtomLine,
|
||||
PpAtomPragma,
|
||||
PpAtomError,
|
||||
|
||||
// #version ...
|
||||
PpAtomVersion,
|
||||
PpAtomCore,
|
||||
PpAtomCompatibility,
|
||||
PpAtomEs,
|
||||
|
||||
// #extension
|
||||
PpAtomExtension,
|
||||
|
||||
// __LINE__, __FILE__, __VERSION__
|
||||
|
||||
PpAtomLineMacro,
|
||||
PpAtomFileMacro,
|
||||
PpAtomVersionMacro,
|
||||
|
||||
// #include
|
||||
PpAtomInclude,
|
||||
|
||||
PpAtomLast,
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif /* not PARSER_H */
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
//
|
||||
// Copyright (C) 2015-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.
|
||||
|
||||
//
|
||||
// Visit the nodes in the glslang intermediate tree representation to
|
||||
// propagate 'noContraction' qualifier.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../Include/intermediate.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
// Propagates the 'precise' qualifier for objects (objects marked with
|
||||
// 'noContraction' qualifier) from the shader source specified 'precise'
|
||||
// variables to all the involved objects, and add 'noContraction' qualifier for
|
||||
// the involved arithmetic operations.
|
||||
// Note that the same qualifier: 'noContraction' is used in both object nodes
|
||||
// and arithmetic operation nodes, but has different meaning. For object nodes,
|
||||
// 'noContraction' means the object is 'precise'; and for arithmetic operation
|
||||
// nodes, it means the operation should not be contracted.
|
||||
void PropagateNoContraction(const glslang::TIntermediate& intermediate);
|
||||
};
|
||||
|
|
@ -0,0 +1,223 @@
|
|||
//
|
||||
// Copyright (C) 2013-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 GLSLANG_WEB
|
||||
|
||||
#ifndef _REFLECTION_INCLUDED
|
||||
#define _REFLECTION_INCLUDED
|
||||
|
||||
#include "../Public/ShaderLang.h"
|
||||
#include "../Include/Types.h"
|
||||
|
||||
#include <list>
|
||||
#include <set>
|
||||
|
||||
//
|
||||
// A reflection database and its interface, consistent with the OpenGL API reflection queries.
|
||||
//
|
||||
|
||||
namespace glslang {
|
||||
|
||||
class TIntermediate;
|
||||
class TIntermAggregate;
|
||||
class TReflectionTraverser;
|
||||
|
||||
// The full reflection database
|
||||
class TReflection {
|
||||
public:
|
||||
TReflection(EShReflectionOptions opts, EShLanguage first, EShLanguage last)
|
||||
: options(opts), firstStage(first), lastStage(last), badReflection(TObjectReflection::badReflection())
|
||||
{
|
||||
for (int dim=0; dim<3; ++dim)
|
||||
localSize[dim] = 0;
|
||||
}
|
||||
|
||||
virtual ~TReflection() {}
|
||||
|
||||
// grow the reflection stage by stage
|
||||
bool addStage(EShLanguage, const TIntermediate&);
|
||||
|
||||
// for mapping a uniform index to a uniform object's description
|
||||
int getNumUniforms() { return (int)indexToUniform.size(); }
|
||||
const TObjectReflection& getUniform(int i) const
|
||||
{
|
||||
if (i >= 0 && i < (int)indexToUniform.size())
|
||||
return indexToUniform[i];
|
||||
else
|
||||
return badReflection;
|
||||
}
|
||||
|
||||
// for mapping a block index to the block's description
|
||||
int getNumUniformBlocks() const { return (int)indexToUniformBlock.size(); }
|
||||
const TObjectReflection& getUniformBlock(int i) const
|
||||
{
|
||||
if (i >= 0 && i < (int)indexToUniformBlock.size())
|
||||
return indexToUniformBlock[i];
|
||||
else
|
||||
return badReflection;
|
||||
}
|
||||
|
||||
// for mapping an pipeline input index to the input's description
|
||||
int getNumPipeInputs() { return (int)indexToPipeInput.size(); }
|
||||
const TObjectReflection& getPipeInput(int i) const
|
||||
{
|
||||
if (i >= 0 && i < (int)indexToPipeInput.size())
|
||||
return indexToPipeInput[i];
|
||||
else
|
||||
return badReflection;
|
||||
}
|
||||
|
||||
// for mapping an pipeline output index to the output's description
|
||||
int getNumPipeOutputs() { return (int)indexToPipeOutput.size(); }
|
||||
const TObjectReflection& getPipeOutput(int i) const
|
||||
{
|
||||
if (i >= 0 && i < (int)indexToPipeOutput.size())
|
||||
return indexToPipeOutput[i];
|
||||
else
|
||||
return badReflection;
|
||||
}
|
||||
|
||||
// for mapping from an atomic counter to the uniform index
|
||||
int getNumAtomicCounters() const { return (int)atomicCounterUniformIndices.size(); }
|
||||
const TObjectReflection& getAtomicCounter(int i) const
|
||||
{
|
||||
if (i >= 0 && i < (int)atomicCounterUniformIndices.size())
|
||||
return getUniform(atomicCounterUniformIndices[i]);
|
||||
else
|
||||
return badReflection;
|
||||
}
|
||||
|
||||
// for mapping a buffer variable index to a buffer variable object's description
|
||||
int getNumBufferVariables() { return (int)indexToBufferVariable.size(); }
|
||||
const TObjectReflection& getBufferVariable(int i) const
|
||||
{
|
||||
if (i >= 0 && i < (int)indexToBufferVariable.size())
|
||||
return indexToBufferVariable[i];
|
||||
else
|
||||
return badReflection;
|
||||
}
|
||||
|
||||
// for mapping a storage block index to the storage block's description
|
||||
int getNumStorageBuffers() const { return (int)indexToBufferBlock.size(); }
|
||||
const TObjectReflection& getStorageBufferBlock(int i) const
|
||||
{
|
||||
if (i >= 0 && i < (int)indexToBufferBlock.size())
|
||||
return indexToBufferBlock[i];
|
||||
else
|
||||
return badReflection;
|
||||
}
|
||||
|
||||
// for mapping any name to its index (block names, uniform names and input/output names)
|
||||
int getIndex(const char* name) const
|
||||
{
|
||||
TNameToIndex::const_iterator it = nameToIndex.find(name);
|
||||
if (it == nameToIndex.end())
|
||||
return -1;
|
||||
else
|
||||
return it->second;
|
||||
}
|
||||
|
||||
// see getIndex(const char*)
|
||||
int getIndex(const TString& name) const { return getIndex(name.c_str()); }
|
||||
|
||||
|
||||
// for mapping any name to its index (only pipe input/output names)
|
||||
int getPipeIOIndex(const char* name, const bool inOrOut) const
|
||||
{
|
||||
TNameToIndex::const_iterator it = inOrOut ? pipeInNameToIndex.find(name) : pipeOutNameToIndex.find(name);
|
||||
if (it == (inOrOut ? pipeInNameToIndex.end() : pipeOutNameToIndex.end()))
|
||||
return -1;
|
||||
else
|
||||
return it->second;
|
||||
}
|
||||
|
||||
// see gePipeIOIndex(const char*, const bool)
|
||||
int getPipeIOIndex(const TString& name, const bool inOrOut) const { return getPipeIOIndex(name.c_str(), inOrOut); }
|
||||
|
||||
// Thread local size
|
||||
unsigned getLocalSize(int dim) const { return dim <= 2 ? localSize[dim] : 0; }
|
||||
|
||||
void dump();
|
||||
|
||||
protected:
|
||||
friend class glslang::TReflectionTraverser;
|
||||
|
||||
void buildCounterIndices(const TIntermediate&);
|
||||
void buildUniformStageMask(const TIntermediate& intermediate);
|
||||
void buildAttributeReflection(EShLanguage, const TIntermediate&);
|
||||
|
||||
// Need a TString hash: typedef std::unordered_map<TString, int> TNameToIndex;
|
||||
typedef std::map<std::string, int> TNameToIndex;
|
||||
typedef std::vector<TObjectReflection> TMapIndexToReflection;
|
||||
typedef std::vector<int> TIndices;
|
||||
|
||||
TMapIndexToReflection& GetBlockMapForStorage(TStorageQualifier storage)
|
||||
{
|
||||
if ((options & EShReflectionSeparateBuffers) && storage == EvqBuffer)
|
||||
return indexToBufferBlock;
|
||||
return indexToUniformBlock;
|
||||
}
|
||||
TMapIndexToReflection& GetVariableMapForStorage(TStorageQualifier storage)
|
||||
{
|
||||
if ((options & EShReflectionSeparateBuffers) && storage == EvqBuffer)
|
||||
return indexToBufferVariable;
|
||||
return indexToUniform;
|
||||
}
|
||||
|
||||
EShReflectionOptions options;
|
||||
|
||||
EShLanguage firstStage;
|
||||
EShLanguage lastStage;
|
||||
|
||||
TObjectReflection badReflection; // return for queries of -1 or generally out of range; has expected descriptions with in it for this
|
||||
TNameToIndex nameToIndex; // maps names to indexes; can hold all types of data: uniform/buffer and which function names have been processed
|
||||
TNameToIndex pipeInNameToIndex; // maps pipe in names to indexes, this is a fix to seperate pipe I/O from uniforms and buffers.
|
||||
TNameToIndex pipeOutNameToIndex; // maps pipe out names to indexes, this is a fix to seperate pipe I/O from uniforms and buffers.
|
||||
TMapIndexToReflection indexToUniform;
|
||||
TMapIndexToReflection indexToUniformBlock;
|
||||
TMapIndexToReflection indexToBufferVariable;
|
||||
TMapIndexToReflection indexToBufferBlock;
|
||||
TMapIndexToReflection indexToPipeInput;
|
||||
TMapIndexToReflection indexToPipeOutput;
|
||||
TIndices atomicCounterUniformIndices;
|
||||
|
||||
unsigned int localSize[3];
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _REFLECTION_INCLUDED
|
||||
|
||||
#endif // GLSLANG_WEB
|
||||
|
|
@ -0,0 +1,932 @@
|
|||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2013-2016 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.
|
||||
//
|
||||
#ifndef _COMPILER_INTERFACE_INCLUDED_
|
||||
#define _COMPILER_INTERFACE_INCLUDED_
|
||||
|
||||
#include "../Include/ResourceLimits.h"
|
||||
#include "../MachineIndependent/Versions.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define C_DECL __cdecl
|
||||
//#ifdef SH_EXPORTING
|
||||
// #define SH_IMPORT_EXPORT __declspec(dllexport)
|
||||
//#else
|
||||
// #define SH_IMPORT_EXPORT __declspec(dllimport)
|
||||
//#endif
|
||||
#define SH_IMPORT_EXPORT
|
||||
#else
|
||||
#define SH_IMPORT_EXPORT
|
||||
#define C_DECL
|
||||
#endif
|
||||
|
||||
//
|
||||
// This is the platform independent interface between an OGL driver
|
||||
// and the shading language compiler/linker.
|
||||
//
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// This should always increase, as some paths to do not consume
|
||||
// a more major number.
|
||||
// It should increment by one when new functionality is added.
|
||||
#define GLSLANG_MINOR_VERSION 14
|
||||
|
||||
//
|
||||
// Call before doing any other compiler/linker operations.
|
||||
//
|
||||
// (Call once per process, not once per thread.)
|
||||
//
|
||||
SH_IMPORT_EXPORT int ShInitialize();
|
||||
|
||||
//
|
||||
// Call this at process shutdown to clean up memory.
|
||||
//
|
||||
SH_IMPORT_EXPORT int ShFinalize();
|
||||
|
||||
//
|
||||
// Types of languages the compiler can consume.
|
||||
//
|
||||
typedef enum {
|
||||
EShLangVertex,
|
||||
EShLangTessControl,
|
||||
EShLangTessEvaluation,
|
||||
EShLangGeometry,
|
||||
EShLangFragment,
|
||||
EShLangCompute,
|
||||
EShLangRayGen,
|
||||
EShLangRayGenNV = EShLangRayGen,
|
||||
EShLangIntersect,
|
||||
EShLangIntersectNV = EShLangIntersect,
|
||||
EShLangAnyHit,
|
||||
EShLangAnyHitNV = EShLangAnyHit,
|
||||
EShLangClosestHit,
|
||||
EShLangClosestHitNV = EShLangClosestHit,
|
||||
EShLangMiss,
|
||||
EShLangMissNV = EShLangMiss,
|
||||
EShLangCallable,
|
||||
EShLangCallableNV = EShLangCallable,
|
||||
EShLangTaskNV,
|
||||
EShLangMeshNV,
|
||||
LAST_ELEMENT_MARKER(EShLangCount),
|
||||
} EShLanguage; // would be better as stage, but this is ancient now
|
||||
|
||||
typedef enum : unsigned {
|
||||
EShLangVertexMask = (1 << EShLangVertex),
|
||||
EShLangTessControlMask = (1 << EShLangTessControl),
|
||||
EShLangTessEvaluationMask = (1 << EShLangTessEvaluation),
|
||||
EShLangGeometryMask = (1 << EShLangGeometry),
|
||||
EShLangFragmentMask = (1 << EShLangFragment),
|
||||
EShLangComputeMask = (1 << EShLangCompute),
|
||||
EShLangRayGenMask = (1 << EShLangRayGen),
|
||||
EShLangRayGenNVMask = EShLangRayGenMask,
|
||||
EShLangIntersectMask = (1 << EShLangIntersect),
|
||||
EShLangIntersectNVMask = EShLangIntersectMask,
|
||||
EShLangAnyHitMask = (1 << EShLangAnyHit),
|
||||
EShLangAnyHitNVMask = EShLangAnyHitMask,
|
||||
EShLangClosestHitMask = (1 << EShLangClosestHit),
|
||||
EShLangClosestHitNVMask = EShLangClosestHitMask,
|
||||
EShLangMissMask = (1 << EShLangMiss),
|
||||
EShLangMissNVMask = EShLangMissMask,
|
||||
EShLangCallableMask = (1 << EShLangCallable),
|
||||
EShLangCallableNVMask = EShLangCallableMask,
|
||||
EShLangTaskNVMask = (1 << EShLangTaskNV),
|
||||
EShLangMeshNVMask = (1 << EShLangMeshNV),
|
||||
LAST_ELEMENT_MARKER(EShLanguageMaskCount),
|
||||
} EShLanguageMask;
|
||||
|
||||
namespace glslang {
|
||||
|
||||
class TType;
|
||||
|
||||
typedef enum {
|
||||
EShSourceNone,
|
||||
EShSourceGlsl, // GLSL, includes ESSL (OpenGL ES GLSL)
|
||||
EShSourceHlsl, // HLSL
|
||||
LAST_ELEMENT_MARKER(EShSourceCount),
|
||||
} EShSource; // if EShLanguage were EShStage, this could be EShLanguage instead
|
||||
|
||||
typedef enum {
|
||||
EShClientNone, // use when there is no client, e.g. for validation
|
||||
EShClientVulkan,
|
||||
EShClientOpenGL,
|
||||
LAST_ELEMENT_MARKER(EShClientCount),
|
||||
} EShClient;
|
||||
|
||||
typedef enum {
|
||||
EShTargetNone,
|
||||
EShTargetSpv, // SPIR-V (preferred spelling)
|
||||
EshTargetSpv = EShTargetSpv, // legacy spelling
|
||||
LAST_ELEMENT_MARKER(EShTargetCount),
|
||||
} EShTargetLanguage;
|
||||
|
||||
typedef enum {
|
||||
EShTargetVulkan_1_0 = (1 << 22), // Vulkan 1.0
|
||||
EShTargetVulkan_1_1 = (1 << 22) | (1 << 12), // Vulkan 1.1
|
||||
EShTargetVulkan_1_2 = (1 << 22) | (2 << 12), // Vulkan 1.2
|
||||
EShTargetOpenGL_450 = 450, // OpenGL
|
||||
LAST_ELEMENT_MARKER(EShTargetClientVersionCount),
|
||||
} EShTargetClientVersion;
|
||||
|
||||
typedef EShTargetClientVersion EshTargetClientVersion;
|
||||
|
||||
typedef enum {
|
||||
EShTargetSpv_1_0 = (1 << 16), // SPIR-V 1.0
|
||||
EShTargetSpv_1_1 = (1 << 16) | (1 << 8), // SPIR-V 1.1
|
||||
EShTargetSpv_1_2 = (1 << 16) | (2 << 8), // SPIR-V 1.2
|
||||
EShTargetSpv_1_3 = (1 << 16) | (3 << 8), // SPIR-V 1.3
|
||||
EShTargetSpv_1_4 = (1 << 16) | (4 << 8), // SPIR-V 1.4
|
||||
EShTargetSpv_1_5 = (1 << 16) | (5 << 8), // SPIR-V 1.5
|
||||
LAST_ELEMENT_MARKER(EShTargetLanguageVersionCount),
|
||||
} EShTargetLanguageVersion;
|
||||
|
||||
struct TInputLanguage {
|
||||
EShSource languageFamily; // redundant information with other input, this one overrides when not EShSourceNone
|
||||
EShLanguage stage; // redundant information with other input, this one overrides when not EShSourceNone
|
||||
EShClient dialect;
|
||||
int dialectVersion; // version of client's language definition, not the client (when not EShClientNone)
|
||||
};
|
||||
|
||||
struct TClient {
|
||||
EShClient client;
|
||||
EShTargetClientVersion version; // version of client itself (not the client's input dialect)
|
||||
};
|
||||
|
||||
struct TTarget {
|
||||
EShTargetLanguage language;
|
||||
EShTargetLanguageVersion version; // version to target, if SPIR-V, defined by "word 1" of the SPIR-V header
|
||||
bool hlslFunctionality1; // can target hlsl_functionality1 extension(s)
|
||||
};
|
||||
|
||||
// All source/client/target versions and settings.
|
||||
// Can override previous methods of setting, when items are set here.
|
||||
// Expected to grow, as more are added, rather than growing parameter lists.
|
||||
struct TEnvironment {
|
||||
TInputLanguage input; // definition of the input language
|
||||
TClient client; // what client is the overall compilation being done for?
|
||||
TTarget target; // what to generate
|
||||
};
|
||||
|
||||
const char* StageName(EShLanguage);
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
//
|
||||
// Types of output the linker will create.
|
||||
//
|
||||
typedef enum {
|
||||
EShExVertexFragment,
|
||||
EShExFragment
|
||||
} EShExecutable;
|
||||
|
||||
//
|
||||
// Optimization level for the compiler.
|
||||
//
|
||||
typedef enum {
|
||||
EShOptNoGeneration,
|
||||
EShOptNone,
|
||||
EShOptSimple, // Optimizations that can be done quickly
|
||||
EShOptFull, // Optimizations that will take more time
|
||||
LAST_ELEMENT_MARKER(EshOptLevelCount),
|
||||
} EShOptimizationLevel;
|
||||
|
||||
//
|
||||
// Texture and Sampler transformation mode.
|
||||
//
|
||||
typedef enum {
|
||||
EShTexSampTransKeep, // keep textures and samplers as is (default)
|
||||
EShTexSampTransUpgradeTextureRemoveSampler, // change texture w/o embeded sampler into sampled texture and throw away all samplers
|
||||
LAST_ELEMENT_MARKER(EShTexSampTransCount),
|
||||
} EShTextureSamplerTransformMode;
|
||||
|
||||
//
|
||||
// Message choices for what errors and warnings are given.
|
||||
//
|
||||
enum EShMessages : unsigned {
|
||||
EShMsgDefault = 0, // default is to give all required errors and extra warnings
|
||||
EShMsgRelaxedErrors = (1 << 0), // be liberal in accepting input
|
||||
EShMsgSuppressWarnings = (1 << 1), // suppress all warnings, except those required by the specification
|
||||
EShMsgAST = (1 << 2), // print the AST intermediate representation
|
||||
EShMsgSpvRules = (1 << 3), // issue messages for SPIR-V generation
|
||||
EShMsgVulkanRules = (1 << 4), // issue messages for Vulkan-requirements of GLSL for SPIR-V
|
||||
EShMsgOnlyPreprocessor = (1 << 5), // only print out errors produced by the preprocessor
|
||||
EShMsgReadHlsl = (1 << 6), // use HLSL parsing rules and semantics
|
||||
EShMsgCascadingErrors = (1 << 7), // get cascading errors; risks error-recovery issues, instead of an early exit
|
||||
EShMsgKeepUncalled = (1 << 8), // for testing, don't eliminate uncalled functions
|
||||
EShMsgHlslOffsets = (1 << 9), // allow block offsets to follow HLSL rules instead of GLSL rules
|
||||
EShMsgDebugInfo = (1 << 10), // save debug information
|
||||
EShMsgHlslEnable16BitTypes = (1 << 11), // enable use of 16-bit types in SPIR-V for HLSL
|
||||
EShMsgHlslLegalization = (1 << 12), // enable HLSL Legalization messages
|
||||
EShMsgHlslDX9Compatible = (1 << 13), // enable HLSL DX9 compatible mode (for samplers and semantics)
|
||||
EShMsgBuiltinSymbolTable = (1 << 14), // print the builtin symbol table
|
||||
LAST_ELEMENT_MARKER(EShMsgCount),
|
||||
};
|
||||
|
||||
//
|
||||
// Options for building reflection
|
||||
//
|
||||
typedef enum {
|
||||
EShReflectionDefault = 0, // default is original behaviour before options were added
|
||||
EShReflectionStrictArraySuffix = (1 << 0), // reflection will follow stricter rules for array-of-structs suffixes
|
||||
EShReflectionBasicArraySuffix = (1 << 1), // arrays of basic types will be appended with [0] as in GL reflection
|
||||
EShReflectionIntermediateIO = (1 << 2), // reflect inputs and outputs to program, even with no vertex shader
|
||||
EShReflectionSeparateBuffers = (1 << 3), // buffer variables and buffer blocks are reflected separately
|
||||
EShReflectionAllBlockVariables = (1 << 4), // reflect all variables in blocks, even if they are inactive
|
||||
EShReflectionUnwrapIOBlocks = (1 << 5), // unwrap input/output blocks the same as with uniform blocks
|
||||
EShReflectionAllIOVariables = (1 << 6), // reflect all input/output variables, even if they are inactive
|
||||
EShReflectionSharedStd140SSBO = (1 << 7), // Apply std140/shared rules for ubo to ssbo
|
||||
EShReflectionSharedStd140UBO = (1 << 8), // Apply std140/shared rules for ubo to ssbo
|
||||
LAST_ELEMENT_MARKER(EShReflectionCount),
|
||||
} EShReflectionOptions;
|
||||
|
||||
//
|
||||
// Build a table for bindings. This can be used for locating
|
||||
// attributes, uniforms, globals, etc., as needed.
|
||||
//
|
||||
typedef struct {
|
||||
const char* name;
|
||||
int binding;
|
||||
} ShBinding;
|
||||
|
||||
typedef struct {
|
||||
int numBindings;
|
||||
ShBinding* bindings; // array of bindings
|
||||
} ShBindingTable;
|
||||
|
||||
//
|
||||
// ShHandle held by but opaque to the driver. It is allocated,
|
||||
// managed, and de-allocated by the compiler/linker. It's contents
|
||||
// are defined by and used by the compiler and linker. For example,
|
||||
// symbol table information and object code passed from the compiler
|
||||
// to the linker can be stored where ShHandle points.
|
||||
//
|
||||
// If handle creation fails, 0 will be returned.
|
||||
//
|
||||
typedef void* ShHandle;
|
||||
|
||||
//
|
||||
// Driver calls these to create and destroy compiler/linker
|
||||
// objects.
|
||||
//
|
||||
SH_IMPORT_EXPORT ShHandle ShConstructCompiler(const EShLanguage, int debugOptions); // one per shader
|
||||
SH_IMPORT_EXPORT ShHandle ShConstructLinker(const EShExecutable, int debugOptions); // one per shader pair
|
||||
SH_IMPORT_EXPORT ShHandle ShConstructUniformMap(); // one per uniform namespace (currently entire program object)
|
||||
SH_IMPORT_EXPORT void ShDestruct(ShHandle);
|
||||
|
||||
//
|
||||
// The return value of ShCompile is boolean, non-zero indicating
|
||||
// success.
|
||||
//
|
||||
// The info-log should be written by ShCompile into
|
||||
// ShHandle, so it can answer future queries.
|
||||
//
|
||||
SH_IMPORT_EXPORT int ShCompile(
|
||||
const ShHandle,
|
||||
const char* const shaderStrings[],
|
||||
const int numStrings,
|
||||
const int* lengths,
|
||||
const EShOptimizationLevel,
|
||||
const TBuiltInResource *resources,
|
||||
int debugOptions,
|
||||
int defaultVersion = 110, // use 100 for ES environment, overridden by #version in shader
|
||||
bool forwardCompatible = false, // give errors for use of deprecated features
|
||||
EShMessages messages = EShMsgDefault // warnings and errors
|
||||
);
|
||||
|
||||
SH_IMPORT_EXPORT int ShLinkExt(
|
||||
const ShHandle, // linker object
|
||||
const ShHandle h[], // compiler objects to link together
|
||||
const int numHandles);
|
||||
|
||||
//
|
||||
// ShSetEncrpytionMethod is a place-holder for specifying
|
||||
// how source code is encrypted.
|
||||
//
|
||||
SH_IMPORT_EXPORT void ShSetEncryptionMethod(ShHandle);
|
||||
|
||||
//
|
||||
// All the following return 0 if the information is not
|
||||
// available in the object passed down, or the object is bad.
|
||||
//
|
||||
SH_IMPORT_EXPORT const char* ShGetInfoLog(const ShHandle);
|
||||
SH_IMPORT_EXPORT const void* ShGetExecutable(const ShHandle);
|
||||
SH_IMPORT_EXPORT int ShSetVirtualAttributeBindings(const ShHandle, const ShBindingTable*); // to detect user aliasing
|
||||
SH_IMPORT_EXPORT int ShSetFixedAttributeBindings(const ShHandle, const ShBindingTable*); // to force any physical mappings
|
||||
//
|
||||
// Tell the linker to never assign a vertex attribute to this list of physical attributes
|
||||
//
|
||||
SH_IMPORT_EXPORT int ShExcludeAttributes(const ShHandle, int *attributes, int count);
|
||||
|
||||
//
|
||||
// Returns the location ID of the named uniform.
|
||||
// Returns -1 if error.
|
||||
//
|
||||
SH_IMPORT_EXPORT int ShGetUniformLocation(const ShHandle uniformMap, const char* name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // end extern "C"
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Deferred-Lowering C++ Interface
|
||||
// -----------------------------------
|
||||
//
|
||||
// Below is a new alternate C++ interface, which deprecates the above
|
||||
// opaque handle-based interface.
|
||||
//
|
||||
// The below is further designed to handle multiple compilation units per stage, where
|
||||
// the intermediate results, including the parse tree, are preserved until link time,
|
||||
// rather than the above interface which is designed to have each compilation unit
|
||||
// lowered at compile time. In the above model, linking occurs on the lowered results,
|
||||
// whereas in this model intra-stage linking can occur at the parse tree
|
||||
// (treeRoot in TIntermediate) level, and then a full stage can be lowered.
|
||||
//
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
class TCompiler;
|
||||
class TInfoSink;
|
||||
|
||||
namespace glslang {
|
||||
|
||||
const char* GetEsslVersionString();
|
||||
const char* GetGlslVersionString();
|
||||
int GetKhronosToolId();
|
||||
|
||||
class TIntermediate;
|
||||
class TProgram;
|
||||
class TPoolAllocator;
|
||||
|
||||
// Call this exactly once per process before using anything else
|
||||
bool InitializeProcess();
|
||||
|
||||
// Call once per process to tear down everything
|
||||
void FinalizeProcess();
|
||||
|
||||
// Resource type for IO resolver
|
||||
enum TResourceType {
|
||||
EResSampler,
|
||||
EResTexture,
|
||||
EResImage,
|
||||
EResUbo,
|
||||
EResSsbo,
|
||||
EResUav,
|
||||
EResCount
|
||||
};
|
||||
|
||||
|
||||
// Make one TShader per shader that you will link into a program. Then
|
||||
// - provide the shader through setStrings() or setStringsWithLengths()
|
||||
// - optionally call setEnv*(), see below for more detail
|
||||
// - optionally use setPreamble() to set a special shader string that will be
|
||||
// processed before all others but won't affect the validity of #version
|
||||
// - optionally call addProcesses() for each setting/transform,
|
||||
// see comment for class TProcesses
|
||||
// - call parse(): source language and target environment must be selected
|
||||
// either by correct setting of EShMessages sent to parse(), or by
|
||||
// explicitly calling setEnv*()
|
||||
// - query the info logs
|
||||
//
|
||||
// N.B.: Does not yet support having the same TShader instance being linked into
|
||||
// multiple programs.
|
||||
//
|
||||
// N.B.: Destruct a linked program *before* destructing the shaders linked into it.
|
||||
//
|
||||
class TShader {
|
||||
public:
|
||||
explicit TShader(EShLanguage);
|
||||
virtual ~TShader();
|
||||
void setStrings(const char* const* s, int n);
|
||||
void setStringsWithLengths(const char* const* s, const int* l, int n);
|
||||
void setStringsWithLengthsAndNames(
|
||||
const char* const* s, const int* l, const char* const* names, int n);
|
||||
void setPreamble(const char* s) { preamble = s; }
|
||||
void setEntryPoint(const char* entryPoint);
|
||||
void setSourceEntryPoint(const char* sourceEntryPointName);
|
||||
void addProcesses(const std::vector<std::string>&);
|
||||
|
||||
// IO resolver binding data: see comments in ShaderLang.cpp
|
||||
void setShiftBinding(TResourceType res, unsigned int base);
|
||||
void setShiftSamplerBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||
void setShiftTextureBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||
void setShiftImageBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||
void setShiftUboBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||
void setShiftUavBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||
void setShiftCbufferBinding(unsigned int base); // synonym for setShiftUboBinding
|
||||
void setShiftSsboBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||
void setShiftBindingForSet(TResourceType res, unsigned int base, unsigned int set);
|
||||
void setResourceSetBinding(const std::vector<std::string>& base);
|
||||
void setAutoMapBindings(bool map);
|
||||
void setAutoMapLocations(bool map);
|
||||
void addUniformLocationOverride(const char* name, int loc);
|
||||
void setUniformLocationBase(int base);
|
||||
void setInvertY(bool invert);
|
||||
#ifdef ENABLE_HLSL
|
||||
void setHlslIoMapping(bool hlslIoMap);
|
||||
void setFlattenUniformArrays(bool flatten);
|
||||
#endif
|
||||
void setNoStorageFormat(bool useUnknownFormat);
|
||||
void setNanMinMaxClamp(bool nanMinMaxClamp);
|
||||
void setTextureSamplerTransformMode(EShTextureSamplerTransformMode mode);
|
||||
|
||||
// For setting up the environment (cleared to nothingness in the constructor).
|
||||
// These must be called so that parsing is done for the right source language and
|
||||
// target environment, either indirectly through TranslateEnvironment() based on
|
||||
// EShMessages et. al., or directly by the user.
|
||||
//
|
||||
// setEnvInput: The input source language and stage. If generating code for a
|
||||
// specific client, the input client semantics to use and the
|
||||
// version of the that client's input semantics to use, otherwise
|
||||
// use EShClientNone and version of 0, e.g. for validation mode.
|
||||
// Note 'version' does not describe the target environment,
|
||||
// just the version of the source dialect to compile under.
|
||||
//
|
||||
// See the definitions of TEnvironment, EShSource, EShLanguage,
|
||||
// and EShClient for choices and more detail.
|
||||
//
|
||||
// setEnvClient: The client that will be hosting the execution, and it's version.
|
||||
// Note 'version' is not the version of the languages involved, but
|
||||
// the version of the client environment.
|
||||
// Use EShClientNone and version of 0 if there is no client, e.g.
|
||||
// for validation mode.
|
||||
//
|
||||
// See EShTargetClientVersion for choices.
|
||||
//
|
||||
// setEnvTarget: The language to translate to when generating code, and that
|
||||
// language's version.
|
||||
// Use EShTargetNone and version of 0 if there is no client, e.g.
|
||||
// for validation mode.
|
||||
//
|
||||
void setEnvInput(EShSource lang, EShLanguage envStage, EShClient client, int version)
|
||||
{
|
||||
environment.input.languageFamily = lang;
|
||||
environment.input.stage = envStage;
|
||||
environment.input.dialect = client;
|
||||
environment.input.dialectVersion = version;
|
||||
}
|
||||
void setEnvClient(EShClient client, EShTargetClientVersion version)
|
||||
{
|
||||
environment.client.client = client;
|
||||
environment.client.version = version;
|
||||
}
|
||||
void setEnvTarget(EShTargetLanguage lang, EShTargetLanguageVersion version)
|
||||
{
|
||||
environment.target.language = lang;
|
||||
environment.target.version = version;
|
||||
}
|
||||
|
||||
void getStrings(const char* const* &s, int& n) { s = strings; n = numStrings; }
|
||||
|
||||
#ifdef ENABLE_HLSL
|
||||
void setEnvTargetHlslFunctionality1() { environment.target.hlslFunctionality1 = true; }
|
||||
bool getEnvTargetHlslFunctionality1() const { return environment.target.hlslFunctionality1; }
|
||||
#else
|
||||
bool getEnvTargetHlslFunctionality1() const { return false; }
|
||||
#endif
|
||||
|
||||
// Interface to #include handlers.
|
||||
//
|
||||
// To support #include, a client of Glslang does the following:
|
||||
// 1. Call setStringsWithNames to set the source strings and associated
|
||||
// names. For example, the names could be the names of the files
|
||||
// containing the shader sources.
|
||||
// 2. Call parse with an Includer.
|
||||
//
|
||||
// When the Glslang parser encounters an #include directive, it calls
|
||||
// the Includer's include method with the requested include name
|
||||
// together with the current string name. The returned IncludeResult
|
||||
// contains the fully resolved name of the included source, together
|
||||
// with the source text that should replace the #include directive
|
||||
// in the source stream. After parsing that source, Glslang will
|
||||
// release the IncludeResult object.
|
||||
class Includer {
|
||||
public:
|
||||
// An IncludeResult contains the resolved name and content of a source
|
||||
// inclusion.
|
||||
struct IncludeResult {
|
||||
IncludeResult(const std::string& headerName, const char* const headerData, const size_t headerLength, void* userData) :
|
||||
headerName(headerName), headerData(headerData), headerLength(headerLength), userData(userData) { }
|
||||
// For a successful inclusion, the fully resolved name of the requested
|
||||
// include. For example, in a file system-based includer, full resolution
|
||||
// should convert a relative path name into an absolute path name.
|
||||
// For a failed inclusion, this is an empty string.
|
||||
const std::string headerName;
|
||||
// The content and byte length of the requested inclusion. The
|
||||
// Includer producing this IncludeResult retains ownership of the
|
||||
// storage.
|
||||
// For a failed inclusion, the header
|
||||
// field points to a string containing error details.
|
||||
const char* const headerData;
|
||||
const size_t headerLength;
|
||||
// Include resolver's context.
|
||||
void* userData;
|
||||
protected:
|
||||
IncludeResult& operator=(const IncludeResult&);
|
||||
IncludeResult();
|
||||
};
|
||||
|
||||
// For both include methods below:
|
||||
//
|
||||
// Resolves an inclusion request by name, current source name,
|
||||
// and include depth.
|
||||
// On success, returns an IncludeResult containing the resolved name
|
||||
// and content of the include.
|
||||
// On failure, returns a nullptr, or an IncludeResult
|
||||
// with an empty string for the headerName and error details in the
|
||||
// header field.
|
||||
// The Includer retains ownership of the contents
|
||||
// of the returned IncludeResult value, and those contents must
|
||||
// remain valid until the releaseInclude method is called on that
|
||||
// IncludeResult object.
|
||||
//
|
||||
// Note "local" vs. "system" is not an "either/or": "local" is an
|
||||
// extra thing to do over "system". Both might get called, as per
|
||||
// the C++ specification.
|
||||
|
||||
// For the "system" or <>-style includes; search the "system" paths.
|
||||
virtual IncludeResult* includeSystem(const char* /*headerName*/,
|
||||
const char* /*includerName*/,
|
||||
size_t /*inclusionDepth*/) { return nullptr; }
|
||||
|
||||
// For the "local"-only aspect of a "" include. Should not search in the
|
||||
// "system" paths, because on returning a failure, the parser will
|
||||
// call includeSystem() to look in the "system" locations.
|
||||
virtual IncludeResult* includeLocal(const char* /*headerName*/,
|
||||
const char* /*includerName*/,
|
||||
size_t /*inclusionDepth*/) { return nullptr; }
|
||||
|
||||
// Signals that the parser will no longer use the contents of the
|
||||
// specified IncludeResult.
|
||||
virtual void releaseInclude(IncludeResult*) = 0;
|
||||
virtual ~Includer() {}
|
||||
};
|
||||
|
||||
// Fail all Includer searches
|
||||
class ForbidIncluder : public Includer {
|
||||
public:
|
||||
virtual void releaseInclude(IncludeResult*) override { }
|
||||
};
|
||||
|
||||
bool parse(const TBuiltInResource*, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile,
|
||||
bool forwardCompatible, EShMessages, Includer&);
|
||||
|
||||
bool parse(const TBuiltInResource* res, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile,
|
||||
bool forwardCompatible, EShMessages messages)
|
||||
{
|
||||
TShader::ForbidIncluder includer;
|
||||
return parse(res, defaultVersion, defaultProfile, forceDefaultVersionAndProfile, forwardCompatible, messages, includer);
|
||||
}
|
||||
|
||||
// Equivalent to parse() without a default profile and without forcing defaults.
|
||||
bool parse(const TBuiltInResource* builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages)
|
||||
{
|
||||
return parse(builtInResources, defaultVersion, ENoProfile, false, forwardCompatible, messages);
|
||||
}
|
||||
|
||||
bool parse(const TBuiltInResource* builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages,
|
||||
Includer& includer)
|
||||
{
|
||||
return parse(builtInResources, defaultVersion, ENoProfile, false, forwardCompatible, messages, includer);
|
||||
}
|
||||
|
||||
// NOTE: Doing just preprocessing to obtain a correct preprocessed shader string
|
||||
// is not an officially supported or fully working path.
|
||||
bool preprocess(const TBuiltInResource* builtInResources,
|
||||
int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile,
|
||||
bool forwardCompatible, EShMessages message, std::string* outputString,
|
||||
Includer& includer);
|
||||
|
||||
const char* getInfoLog();
|
||||
const char* getInfoDebugLog();
|
||||
EShLanguage getStage() const { return stage; }
|
||||
TIntermediate* getIntermediate() const { return intermediate; }
|
||||
|
||||
protected:
|
||||
TPoolAllocator* pool;
|
||||
EShLanguage stage;
|
||||
TCompiler* compiler;
|
||||
TIntermediate* intermediate;
|
||||
TInfoSink* infoSink;
|
||||
// strings and lengths follow the standard for glShaderSource:
|
||||
// strings is an array of numStrings pointers to string data.
|
||||
// lengths can be null, but if not it is an array of numStrings
|
||||
// integers containing the length of the associated strings.
|
||||
// if lengths is null or lengths[n] < 0 the associated strings[n] is
|
||||
// assumed to be null-terminated.
|
||||
// stringNames is the optional names for all the strings. If stringNames
|
||||
// is null, then none of the strings has name. If a certain element in
|
||||
// stringNames is null, then the corresponding string does not have name.
|
||||
const char* const* strings; // explicit code to compile, see previous comment
|
||||
const int* lengths;
|
||||
const char* const* stringNames;
|
||||
int numStrings; // size of the above arrays
|
||||
const char* preamble; // string of implicit code to compile before the explicitly provided code
|
||||
|
||||
// a function in the source string can be renamed FROM this TO the name given in setEntryPoint.
|
||||
std::string sourceEntryPointName;
|
||||
|
||||
TEnvironment environment;
|
||||
|
||||
friend class TProgram;
|
||||
|
||||
private:
|
||||
TShader& operator=(TShader&);
|
||||
};
|
||||
|
||||
#ifndef GLSLANG_WEB
|
||||
|
||||
//
|
||||
// A reflection database and its interface, consistent with the OpenGL API reflection queries.
|
||||
//
|
||||
|
||||
// Data needed for just a single object at the granularity exchanged by the reflection API
|
||||
class TObjectReflection {
|
||||
public:
|
||||
TObjectReflection(const std::string& pName, const TType& pType, int pOffset, int pGLDefineType, int pSize, int pIndex);
|
||||
|
||||
const TType* getType() const { return type; }
|
||||
int getBinding() const;
|
||||
void dump() const;
|
||||
static TObjectReflection badReflection() { return TObjectReflection(); }
|
||||
|
||||
std::string name;
|
||||
int offset;
|
||||
int glDefineType;
|
||||
int size; // data size in bytes for a block, array size for a (non-block) object that's an array
|
||||
int index;
|
||||
int counterIndex;
|
||||
int numMembers;
|
||||
int arrayStride; // stride of an array variable
|
||||
int topLevelArraySize; // size of the top-level variable in a storage buffer member
|
||||
int topLevelArrayStride; // stride of the top-level variable in a storage buffer member
|
||||
EShLanguageMask stages;
|
||||
|
||||
protected:
|
||||
TObjectReflection()
|
||||
: offset(-1), glDefineType(-1), size(-1), index(-1), counterIndex(-1), numMembers(-1), arrayStride(0),
|
||||
topLevelArrayStride(0), stages(EShLanguageMask(0)), type(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
const TType* type;
|
||||
};
|
||||
|
||||
class TReflection;
|
||||
class TIoMapper;
|
||||
struct TVarEntryInfo;
|
||||
|
||||
// Allows to customize the binding layout after linking.
|
||||
// All used uniform variables will invoke at least validateBinding.
|
||||
// If validateBinding returned true then the other resolveBinding,
|
||||
// resolveSet, and resolveLocation are invoked to resolve the binding
|
||||
// and descriptor set index respectively.
|
||||
//
|
||||
// Invocations happen in a particular order:
|
||||
// 1) all shader inputs
|
||||
// 2) all shader outputs
|
||||
// 3) all uniforms with binding and set already defined
|
||||
// 4) all uniforms with binding but no set defined
|
||||
// 5) all uniforms with set but no binding defined
|
||||
// 6) all uniforms with no binding and no set defined
|
||||
//
|
||||
// mapIO will use this resolver in two phases. The first
|
||||
// phase is a notification phase, calling the corresponging
|
||||
// notifiy callbacks, this phase ends with a call to endNotifications.
|
||||
// Phase two starts directly after the call to endNotifications
|
||||
// and calls all other callbacks to validate and to get the
|
||||
// bindings, sets, locations, component and color indices.
|
||||
//
|
||||
// NOTE: that still limit checks are applied to bindings and sets
|
||||
// and may result in an error.
|
||||
class TIoMapResolver
|
||||
{
|
||||
public:
|
||||
virtual ~TIoMapResolver() {}
|
||||
|
||||
// Should return true if the resulting/current binding would be okay.
|
||||
// Basic idea is to do aliasing binding checks with this.
|
||||
virtual bool validateBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Should return a value >= 0 if the current binding should be overridden.
|
||||
// Return -1 if the current binding (including no binding) should be kept.
|
||||
virtual int resolveBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Should return a value >= 0 if the current set should be overridden.
|
||||
// Return -1 if the current set (including no set) should be kept.
|
||||
virtual int resolveSet(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Should return a value >= 0 if the current location should be overridden.
|
||||
// Return -1 if the current location (including no location) should be kept.
|
||||
virtual int resolveUniformLocation(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Should return true if the resulting/current setup would be okay.
|
||||
// Basic idea is to do aliasing checks and reject invalid semantic names.
|
||||
virtual bool validateInOut(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Should return a value >= 0 if the current location should be overridden.
|
||||
// Return -1 if the current location (including no location) should be kept.
|
||||
virtual int resolveInOutLocation(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Should return a value >= 0 if the current component index should be overridden.
|
||||
// Return -1 if the current component index (including no index) should be kept.
|
||||
virtual int resolveInOutComponent(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Should return a value >= 0 if the current color index should be overridden.
|
||||
// Return -1 if the current color index (including no index) should be kept.
|
||||
virtual int resolveInOutIndex(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Notification of a uniform variable
|
||||
virtual void notifyBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Notification of a in or out variable
|
||||
virtual void notifyInOut(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Called by mapIO when it starts its notify pass for the given stage
|
||||
virtual void beginNotifications(EShLanguage stage) = 0;
|
||||
// Called by mapIO when it has finished the notify pass
|
||||
virtual void endNotifications(EShLanguage stage) = 0;
|
||||
// Called by mipIO when it starts its resolve pass for the given stage
|
||||
virtual void beginResolve(EShLanguage stage) = 0;
|
||||
// Called by mapIO when it has finished the resolve pass
|
||||
virtual void endResolve(EShLanguage stage) = 0;
|
||||
// Called by mapIO when it starts its symbol collect for teh given stage
|
||||
virtual void beginCollect(EShLanguage stage) = 0;
|
||||
// Called by mapIO when it has finished the symbol collect
|
||||
virtual void endCollect(EShLanguage stage) = 0;
|
||||
// Called by TSlotCollector to resolve storage locations or bindings
|
||||
virtual void reserverStorageSlot(TVarEntryInfo& ent, TInfoSink& infoSink) = 0;
|
||||
// Called by TSlotCollector to resolve resource locations or bindings
|
||||
virtual void reserverResourceSlot(TVarEntryInfo& ent, TInfoSink& infoSink) = 0;
|
||||
// Called by mapIO.addStage to set shader stage mask to mark a stage be added to this pipeline
|
||||
virtual void addStage(EShLanguage stage) = 0;
|
||||
};
|
||||
|
||||
#endif // GLSLANG_WEB
|
||||
|
||||
// Make one TProgram per set of shaders that will get linked together. Add all
|
||||
// the shaders that are to be linked together. After calling shader.parse()
|
||||
// for all shaders, call link().
|
||||
//
|
||||
// N.B.: Destruct a linked program *before* destructing the shaders linked into it.
|
||||
//
|
||||
class TProgram {
|
||||
public:
|
||||
TProgram();
|
||||
virtual ~TProgram();
|
||||
void addShader(TShader* shader) { stages[shader->stage].push_back(shader); }
|
||||
std::list<TShader*>& getShaders(EShLanguage stage) { return stages[stage]; }
|
||||
// Link Validation interface
|
||||
bool link(EShMessages);
|
||||
const char* getInfoLog();
|
||||
const char* getInfoDebugLog();
|
||||
|
||||
TIntermediate* getIntermediate(EShLanguage stage) const { return intermediate[stage]; }
|
||||
|
||||
#ifndef GLSLANG_WEB
|
||||
|
||||
// Reflection Interface
|
||||
|
||||
// call first, to do liveness analysis, index mapping, etc.; returns false on failure
|
||||
bool buildReflection(int opts = EShReflectionDefault);
|
||||
unsigned getLocalSize(int dim) const; // return dim'th local size
|
||||
int getReflectionIndex(const char *name) const;
|
||||
int getReflectionPipeIOIndex(const char* name, const bool inOrOut) const;
|
||||
int getNumUniformVariables() const;
|
||||
const TObjectReflection& getUniform(int index) const;
|
||||
int getNumUniformBlocks() const;
|
||||
const TObjectReflection& getUniformBlock(int index) const;
|
||||
int getNumPipeInputs() const;
|
||||
const TObjectReflection& getPipeInput(int index) const;
|
||||
int getNumPipeOutputs() const;
|
||||
const TObjectReflection& getPipeOutput(int index) const;
|
||||
int getNumBufferVariables() const;
|
||||
const TObjectReflection& getBufferVariable(int index) const;
|
||||
int getNumBufferBlocks() const;
|
||||
const TObjectReflection& getBufferBlock(int index) const;
|
||||
int getNumAtomicCounters() const;
|
||||
const TObjectReflection& getAtomicCounter(int index) const;
|
||||
|
||||
// Legacy Reflection Interface - expressed in terms of above interface
|
||||
|
||||
// can be used for glGetProgramiv(GL_ACTIVE_UNIFORMS)
|
||||
int getNumLiveUniformVariables() const { return getNumUniformVariables(); }
|
||||
|
||||
// can be used for glGetProgramiv(GL_ACTIVE_UNIFORM_BLOCKS)
|
||||
int getNumLiveUniformBlocks() const { return getNumUniformBlocks(); }
|
||||
|
||||
// can be used for glGetProgramiv(GL_ACTIVE_ATTRIBUTES)
|
||||
int getNumLiveAttributes() const { return getNumPipeInputs(); }
|
||||
|
||||
// can be used for glGetUniformIndices()
|
||||
int getUniformIndex(const char *name) const { return getReflectionIndex(name); }
|
||||
|
||||
int getPipeIOIndex(const char *name, const bool inOrOut) const
|
||||
{ return getReflectionPipeIOIndex(name, inOrOut); }
|
||||
|
||||
// can be used for "name" part of glGetActiveUniform()
|
||||
const char *getUniformName(int index) const { return getUniform(index).name.c_str(); }
|
||||
|
||||
// returns the binding number
|
||||
int getUniformBinding(int index) const { return getUniform(index).getBinding(); }
|
||||
|
||||
// returns Shaders Stages where a Uniform is present
|
||||
EShLanguageMask getUniformStages(int index) const { return getUniform(index).stages; }
|
||||
|
||||
// can be used for glGetActiveUniformsiv(GL_UNIFORM_BLOCK_INDEX)
|
||||
int getUniformBlockIndex(int index) const { return getUniform(index).index; }
|
||||
|
||||
// can be used for glGetActiveUniformsiv(GL_UNIFORM_TYPE)
|
||||
int getUniformType(int index) const { return getUniform(index).glDefineType; }
|
||||
|
||||
// can be used for glGetActiveUniformsiv(GL_UNIFORM_OFFSET)
|
||||
int getUniformBufferOffset(int index) const { return getUniform(index).offset; }
|
||||
|
||||
// can be used for glGetActiveUniformsiv(GL_UNIFORM_SIZE)
|
||||
int getUniformArraySize(int index) const { return getUniform(index).size; }
|
||||
|
||||
// returns a TType*
|
||||
const TType *getUniformTType(int index) const { return getUniform(index).getType(); }
|
||||
|
||||
// can be used for glGetActiveUniformBlockName()
|
||||
const char *getUniformBlockName(int index) const { return getUniformBlock(index).name.c_str(); }
|
||||
|
||||
// can be used for glGetActiveUniformBlockiv(UNIFORM_BLOCK_DATA_SIZE)
|
||||
int getUniformBlockSize(int index) const { return getUniformBlock(index).size; }
|
||||
|
||||
// returns the block binding number
|
||||
int getUniformBlockBinding(int index) const { return getUniformBlock(index).getBinding(); }
|
||||
|
||||
// returns block index of associated counter.
|
||||
int getUniformBlockCounterIndex(int index) const { return getUniformBlock(index).counterIndex; }
|
||||
|
||||
// returns a TType*
|
||||
const TType *getUniformBlockTType(int index) const { return getUniformBlock(index).getType(); }
|
||||
|
||||
// can be used for glGetActiveAttrib()
|
||||
const char *getAttributeName(int index) const { return getPipeInput(index).name.c_str(); }
|
||||
|
||||
// can be used for glGetActiveAttrib()
|
||||
int getAttributeType(int index) const { return getPipeInput(index).glDefineType; }
|
||||
|
||||
// returns a TType*
|
||||
const TType *getAttributeTType(int index) const { return getPipeInput(index).getType(); }
|
||||
|
||||
void dumpReflection();
|
||||
// I/O mapping: apply base offsets and map live unbound variables
|
||||
// If resolver is not provided it uses the previous approach
|
||||
// and respects auto assignment and offsets.
|
||||
bool mapIO(TIoMapResolver* pResolver = nullptr, TIoMapper* pIoMapper = nullptr);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool linkStage(EShLanguage, EShMessages);
|
||||
|
||||
TPoolAllocator* pool;
|
||||
std::list<TShader*> stages[EShLangCount];
|
||||
TIntermediate* intermediate[EShLangCount];
|
||||
bool newedIntermediate[EShLangCount]; // track which intermediate were "new" versus reusing a singleton unit in a stage
|
||||
TInfoSink* infoSink;
|
||||
#ifndef GLSLANG_WEB
|
||||
TReflection* reflection;
|
||||
#endif
|
||||
bool linked;
|
||||
|
||||
private:
|
||||
TProgram(TProgram&);
|
||||
TProgram& operator=(TProgram&);
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _COMPILER_INTERFACE_INCLUDED_
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
** 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";
|
||||
|
||||
#endif // #ifndef GLSLextEXT_H
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
** 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 = 2;
|
||||
|
||||
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";
|
||||
#endif // #ifndef GLSLextKHR_H
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
** 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_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
|
||||
|
|
@ -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
|
||||
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
@ -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,304 @@
|
|||
//
|
||||
// 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, 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;
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
|
@ -0,0 +1,838 @@
|
|||
//
|
||||
// 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"
|
||||
|
||||
#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)
|
||||
{
|
||||
source = 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;
|
||||
}
|
||||
void setSourceFile(const std::string& file)
|
||||
{
|
||||
sourceFileStringId = getStringId(file);
|
||||
}
|
||||
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 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);
|
||||
|
||||
// For creating new types (will return old type if the requested one was already made).
|
||||
Id makeVoidType();
|
||||
Id makeBoolType();
|
||||
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*);
|
||||
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);
|
||||
|
||||
// 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); }
|
||||
|
||||
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)); }
|
||||
|
||||
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 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);
|
||||
|
||||
// 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 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 addDecorationId(Id id, Decoration, Id idDecoration);
|
||||
void addMemberDecoration(Id, unsigned int member, Decoration, int num = -1);
|
||||
void addMemberDecoration(Id, unsigned int member, Decoration, const char*);
|
||||
|
||||
// At the end of what block do the next create*() instructions go?
|
||||
void setBuildPoint(Block* bp) { buildPoint = bp; }
|
||||
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<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);
|
||||
|
||||
// Generate all the code needed to finish up a function.
|
||||
void leaveFunction();
|
||||
|
||||
// Create a discard.
|
||||
void makeDiscard();
|
||||
|
||||
// Create a global or function local or IO variable.
|
||||
Id createVariable(StorageClass, Id type, const char* name = 0, Id initializer = NoResult);
|
||||
|
||||
// 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::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 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;
|
||||
|
||||
void clear() {
|
||||
coherent = 0;
|
||||
devicecoherent = 0;
|
||||
queuefamilycoherent = 0;
|
||||
workgroupcoherent = 0;
|
||||
subgroupcoherent = 0;
|
||||
shadercallcoherent = 0;
|
||||
nonprivate = 0;
|
||||
volatil = 0;
|
||||
isImage = 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;
|
||||
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, 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 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 source;
|
||||
int sourceVersion;
|
||||
spv::Id sourceFileStringId;
|
||||
std::string sourceText;
|
||||
int currentLine;
|
||||
const char* currentFile;
|
||||
bool emitOpLines;
|
||||
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;
|
||||
|
||||
// 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;
|
||||
|
||||
// The stream for outputting warnings and errors.
|
||||
SpvBuildLogger* logger;
|
||||
}; // end Builder class
|
||||
|
||||
}; // end spv namespace
|
||||
|
||||
#endif // SpvBuilder_H
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
//
|
||||
// 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
|
||||
|
||||
#ifdef ENABLE_OPT
|
||||
#include <vector>
|
||||
#include <ostream>
|
||||
#endif
|
||||
|
||||
#include "glslang/MachineIndependent/localintermediate.h"
|
||||
#include "Logger.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
struct SpvOptions {
|
||||
SpvOptions() : generateDebugInfo(false), disableOptimizer(true),
|
||||
optimizeSize(false), disassemble(false), validate(false) { }
|
||||
bool generateDebugInfo;
|
||||
bool disableOptimizer;
|
||||
bool optimizeSize;
|
||||
bool disassemble;
|
||||
bool validate;
|
||||
};
|
||||
|
||||
#ifdef ENABLE_OPT
|
||||
|
||||
// Use the SPIRV-Tools disassembler to print SPIR-V.
|
||||
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv);
|
||||
|
||||
// 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, for the purpose of
|
||||
// legalizing HLSL SPIR-V.
|
||||
void SpirvToolsLegalize(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
||||
spv::SpvBuildLogger*, const SpvOptions*);
|
||||
|
||||
#endif
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // GLSLANG_SPV_TOOLS_H
|
||||
|
|
@ -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_
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,258 @@
|
|||
//
|
||||
// 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,
|
||||
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
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,485 @@
|
|||
//
|
||||
// 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>
|
||||
|
||||
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;
|
||||
char* wordString = (char*)&word;
|
||||
char* wordPtr = wordString;
|
||||
int charCount = 0;
|
||||
char c;
|
||||
do {
|
||||
c = *(str++);
|
||||
*(wordPtr++) = c;
|
||||
++charCount;
|
||||
if (charCount == 4) {
|
||||
addImmediateOperand(word);
|
||||
wordPtr = wordString;
|
||||
charCount = 0;
|
||||
}
|
||||
} while (c != 0);
|
||||
|
||||
// deal with partial last word
|
||||
if (charCount > 0) {
|
||||
// pad with 0s
|
||||
for (; charCount < 4; ++charCount)
|
||||
*(wordPtr++) = 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 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(); }
|
||||
|
||||
void setImplicitThis() { implicitThis = true; }
|
||||
bool hasImplicitThis() const { return implicitThis; }
|
||||
|
||||
void dump(std::vector<unsigned int>& out) const
|
||||
{
|
||||
// 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;
|
||||
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
|
||||
};
|
||||
|
||||
//
|
||||
// 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), functionInstruction(id, resultType, OpFunction), implicitThis(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,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 = 3;
|
||||
|
||||
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
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
* Copyright 2016-2020 Arm Limited
|
||||
*
|
||||
* 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 SPIRV_CROSS_CFG_HPP
|
||||
#define SPIRV_CROSS_CFG_HPP
|
||||
|
||||
#include "spirv_common.hpp"
|
||||
#include <assert.h>
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
class Compiler;
|
||||
class CFG
|
||||
{
|
||||
public:
|
||||
CFG(Compiler &compiler, const SPIRFunction &function);
|
||||
|
||||
Compiler &get_compiler()
|
||||
{
|
||||
return compiler;
|
||||
}
|
||||
|
||||
const Compiler &get_compiler() const
|
||||
{
|
||||
return compiler;
|
||||
}
|
||||
|
||||
const SPIRFunction &get_function() const
|
||||
{
|
||||
return func;
|
||||
}
|
||||
|
||||
uint32_t get_immediate_dominator(uint32_t block) const
|
||||
{
|
||||
auto itr = immediate_dominators.find(block);
|
||||
if (itr != std::end(immediate_dominators))
|
||||
return itr->second;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t get_visit_order(uint32_t block) const
|
||||
{
|
||||
auto itr = visit_order.find(block);
|
||||
assert(itr != std::end(visit_order));
|
||||
int v = itr->second.get();
|
||||
assert(v > 0);
|
||||
return uint32_t(v);
|
||||
}
|
||||
|
||||
uint32_t find_common_dominator(uint32_t a, uint32_t b) const;
|
||||
|
||||
const SmallVector<uint32_t> &get_preceding_edges(uint32_t block) const
|
||||
{
|
||||
auto itr = preceding_edges.find(block);
|
||||
if (itr != std::end(preceding_edges))
|
||||
return itr->second;
|
||||
else
|
||||
return empty_vector;
|
||||
}
|
||||
|
||||
const SmallVector<uint32_t> &get_succeeding_edges(uint32_t block) const
|
||||
{
|
||||
auto itr = succeeding_edges.find(block);
|
||||
if (itr != std::end(succeeding_edges))
|
||||
return itr->second;
|
||||
else
|
||||
return empty_vector;
|
||||
}
|
||||
|
||||
template <typename Op>
|
||||
void walk_from(std::unordered_set<uint32_t> &seen_blocks, uint32_t block, const Op &op) const
|
||||
{
|
||||
if (seen_blocks.count(block))
|
||||
return;
|
||||
seen_blocks.insert(block);
|
||||
|
||||
if (op(block))
|
||||
{
|
||||
for (auto b : get_succeeding_edges(block))
|
||||
walk_from(seen_blocks, b, op);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t find_loop_dominator(uint32_t block) const;
|
||||
|
||||
bool node_terminates_control_flow_in_sub_graph(BlockID from, BlockID to) const;
|
||||
|
||||
private:
|
||||
struct VisitOrder
|
||||
{
|
||||
int &get()
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
const int &get() const
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
int v = -1;
|
||||
};
|
||||
|
||||
Compiler &compiler;
|
||||
const SPIRFunction &func;
|
||||
std::unordered_map<uint32_t, SmallVector<uint32_t>> preceding_edges;
|
||||
std::unordered_map<uint32_t, SmallVector<uint32_t>> succeeding_edges;
|
||||
std::unordered_map<uint32_t, uint32_t> immediate_dominators;
|
||||
std::unordered_map<uint32_t, VisitOrder> visit_order;
|
||||
SmallVector<uint32_t> post_order;
|
||||
SmallVector<uint32_t> empty_vector;
|
||||
|
||||
void add_branch(uint32_t from, uint32_t to);
|
||||
void build_post_order_visit_order();
|
||||
void build_immediate_dominators();
|
||||
bool post_order_visit(uint32_t block);
|
||||
uint32_t visit_count = 0;
|
||||
|
||||
bool is_back_edge(uint32_t to) const;
|
||||
bool has_visited_forward_edge(uint32_t to) const;
|
||||
};
|
||||
|
||||
class DominatorBuilder
|
||||
{
|
||||
public:
|
||||
DominatorBuilder(const CFG &cfg);
|
||||
|
||||
void add_block(uint32_t block);
|
||||
uint32_t get_dominator() const
|
||||
{
|
||||
return dominator;
|
||||
}
|
||||
|
||||
void lift_continue_block_dominator();
|
||||
|
||||
private:
|
||||
const CFG &cfg;
|
||||
uint32_t dominator = 0;
|
||||
};
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Copyright 2015-2020 Arm Limited
|
||||
*
|
||||
* 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 SPIRV_CROSS_CPP_HPP
|
||||
#define SPIRV_CROSS_CPP_HPP
|
||||
|
||||
#include "spirv_glsl.hpp"
|
||||
#include <utility>
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
class CompilerCPP : public CompilerGLSL
|
||||
{
|
||||
public:
|
||||
explicit CompilerCPP(std::vector<uint32_t> spirv_)
|
||||
: CompilerGLSL(std::move(spirv_))
|
||||
{
|
||||
}
|
||||
|
||||
CompilerCPP(const uint32_t *ir_, size_t word_count)
|
||||
: CompilerGLSL(ir_, word_count)
|
||||
{
|
||||
}
|
||||
|
||||
explicit CompilerCPP(const ParsedIR &ir_)
|
||||
: CompilerGLSL(ir_)
|
||||
{
|
||||
}
|
||||
|
||||
explicit CompilerCPP(ParsedIR &&ir_)
|
||||
: CompilerGLSL(std::move(ir_))
|
||||
{
|
||||
}
|
||||
|
||||
std::string compile() override;
|
||||
|
||||
// Sets a custom symbol name that can override
|
||||
// spirv_cross_get_interface.
|
||||
//
|
||||
// Useful when several shader interfaces are linked
|
||||
// statically into the same binary.
|
||||
void set_interface_name(std::string name)
|
||||
{
|
||||
interface_name = std::move(name);
|
||||
}
|
||||
|
||||
private:
|
||||
void emit_header() override;
|
||||
void emit_c_linkage();
|
||||
void emit_function_prototype(SPIRFunction &func, const Bitset &return_flags) override;
|
||||
|
||||
void emit_resources();
|
||||
void emit_buffer_block(const SPIRVariable &type) override;
|
||||
void emit_push_constant_block(const SPIRVariable &var) override;
|
||||
void emit_interface_block(const SPIRVariable &type);
|
||||
void emit_block_chain(SPIRBlock &block);
|
||||
void emit_uniform(const SPIRVariable &var) override;
|
||||
void emit_shared(const SPIRVariable &var);
|
||||
void emit_block_struct(SPIRType &type);
|
||||
std::string variable_decl(const SPIRType &type, const std::string &name, uint32_t id) override;
|
||||
|
||||
std::string argument_decl(const SPIRFunction::Parameter &arg);
|
||||
|
||||
SmallVector<std::string> resource_registrations;
|
||||
std::string impl_type;
|
||||
std::string resource_type;
|
||||
uint32_t shared_counter = 0;
|
||||
|
||||
std::string interface_name;
|
||||
};
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,912 @@
|
|||
/*
|
||||
* Copyright 2019-2020 Hans-Kristian Arntzen
|
||||
*
|
||||
* 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 SPIRV_CROSS_C_API_H
|
||||
#define SPIRV_CROSS_C_API_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "spirv.h"
|
||||
|
||||
/*
|
||||
* C89-compatible wrapper for SPIRV-Cross' API.
|
||||
* Documentation here is sparse unless the behavior does not map 1:1 with C++ API.
|
||||
* It is recommended to look at the canonical C++ API for more detailed information.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Bumped if ABI or API breaks backwards compatibility. */
|
||||
#define SPVC_C_API_VERSION_MAJOR 0
|
||||
/* Bumped if APIs or enumerations are added in a backwards compatible way. */
|
||||
#define SPVC_C_API_VERSION_MINOR 33
|
||||
/* Bumped if internal implementation details change. */
|
||||
#define SPVC_C_API_VERSION_PATCH 0
|
||||
|
||||
#if !defined(SPVC_PUBLIC_API)
|
||||
#if defined(SPVC_EXPORT_SYMBOLS)
|
||||
/* Exports symbols. Standard C calling convention is used. */
|
||||
#if defined(__GNUC__)
|
||||
#define SPVC_PUBLIC_API __attribute__((visibility("default")))
|
||||
#elif defined(_MSC_VER)
|
||||
#define SPVC_PUBLIC_API __declspec(dllexport)
|
||||
#else
|
||||
#define SPVC_PUBLIC_API
|
||||
#endif
|
||||
#else
|
||||
#define SPVC_PUBLIC_API
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Gets the SPVC_C_API_VERSION_* used to build this library.
|
||||
* Can be used to check for ABI mismatch if so-versioning did not catch it.
|
||||
*/
|
||||
SPVC_PUBLIC_API void spvc_get_version(unsigned *major, unsigned *minor, unsigned *patch);
|
||||
|
||||
/* Gets a human readable version string to identify which commit a particular binary was created from. */
|
||||
SPVC_PUBLIC_API const char *spvc_get_commit_revision_and_timestamp(void);
|
||||
|
||||
/* These types are opaque to the user. */
|
||||
typedef struct spvc_context_s *spvc_context;
|
||||
typedef struct spvc_parsed_ir_s *spvc_parsed_ir;
|
||||
typedef struct spvc_compiler_s *spvc_compiler;
|
||||
typedef struct spvc_compiler_options_s *spvc_compiler_options;
|
||||
typedef struct spvc_resources_s *spvc_resources;
|
||||
struct spvc_type_s;
|
||||
typedef const struct spvc_type_s *spvc_type;
|
||||
typedef struct spvc_constant_s *spvc_constant;
|
||||
struct spvc_set_s;
|
||||
typedef const struct spvc_set_s *spvc_set;
|
||||
|
||||
/*
|
||||
* Shallow typedefs. All SPIR-V IDs are plain 32-bit numbers, but this helps communicate which data is used.
|
||||
* Maps to a SPIRType.
|
||||
*/
|
||||
typedef SpvId spvc_type_id;
|
||||
/* Maps to a SPIRVariable. */
|
||||
typedef SpvId spvc_variable_id;
|
||||
/* Maps to a SPIRConstant. */
|
||||
typedef SpvId spvc_constant_id;
|
||||
|
||||
/* See C++ API. */
|
||||
typedef struct spvc_reflected_resource
|
||||
{
|
||||
spvc_variable_id id;
|
||||
spvc_type_id base_type_id;
|
||||
spvc_type_id type_id;
|
||||
const char *name;
|
||||
} spvc_reflected_resource;
|
||||
|
||||
/* See C++ API. */
|
||||
typedef struct spvc_entry_point
|
||||
{
|
||||
SpvExecutionModel execution_model;
|
||||
const char *name;
|
||||
} spvc_entry_point;
|
||||
|
||||
/* See C++ API. */
|
||||
typedef struct spvc_combined_image_sampler
|
||||
{
|
||||
spvc_variable_id combined_id;
|
||||
spvc_variable_id image_id;
|
||||
spvc_variable_id sampler_id;
|
||||
} spvc_combined_image_sampler;
|
||||
|
||||
/* See C++ API. */
|
||||
typedef struct spvc_specialization_constant
|
||||
{
|
||||
spvc_constant_id id;
|
||||
unsigned constant_id;
|
||||
} spvc_specialization_constant;
|
||||
|
||||
/* See C++ API. */
|
||||
typedef struct spvc_buffer_range
|
||||
{
|
||||
unsigned index;
|
||||
size_t offset;
|
||||
size_t range;
|
||||
} spvc_buffer_range;
|
||||
|
||||
/* See C++ API. */
|
||||
typedef struct spvc_hlsl_root_constants
|
||||
{
|
||||
unsigned start;
|
||||
unsigned end;
|
||||
unsigned binding;
|
||||
unsigned space;
|
||||
} spvc_hlsl_root_constants;
|
||||
|
||||
/* See C++ API. */
|
||||
typedef struct spvc_hlsl_vertex_attribute_remap
|
||||
{
|
||||
unsigned location;
|
||||
const char *semantic;
|
||||
} spvc_hlsl_vertex_attribute_remap;
|
||||
|
||||
/*
|
||||
* Be compatible with non-C99 compilers, which do not have stdbool.
|
||||
* Only recent MSVC compilers supports this for example, and ideally SPIRV-Cross should be linkable
|
||||
* from a wide range of compilers in its C wrapper.
|
||||
*/
|
||||
typedef unsigned char spvc_bool;
|
||||
#define SPVC_TRUE ((spvc_bool)1)
|
||||
#define SPVC_FALSE ((spvc_bool)0)
|
||||
|
||||
typedef enum spvc_result
|
||||
{
|
||||
/* Success. */
|
||||
SPVC_SUCCESS = 0,
|
||||
|
||||
/* The SPIR-V is invalid. Should have been caught by validation ideally. */
|
||||
SPVC_ERROR_INVALID_SPIRV = -1,
|
||||
|
||||
/* The SPIR-V might be valid or invalid, but SPIRV-Cross currently cannot correctly translate this to your target language. */
|
||||
SPVC_ERROR_UNSUPPORTED_SPIRV = -2,
|
||||
|
||||
/* If for some reason we hit this, new or malloc failed. */
|
||||
SPVC_ERROR_OUT_OF_MEMORY = -3,
|
||||
|
||||
/* Invalid API argument. */
|
||||
SPVC_ERROR_INVALID_ARGUMENT = -4,
|
||||
|
||||
SPVC_ERROR_INT_MAX = 0x7fffffff
|
||||
} spvc_result;
|
||||
|
||||
typedef enum spvc_capture_mode
|
||||
{
|
||||
/* The Parsed IR payload will be copied, and the handle can be reused to create other compiler instances. */
|
||||
SPVC_CAPTURE_MODE_COPY = 0,
|
||||
|
||||
/*
|
||||
* The payload will now be owned by the compiler.
|
||||
* parsed_ir should now be considered a dead blob and must not be used further.
|
||||
* This is optimal for performance and should be the go-to option.
|
||||
*/
|
||||
SPVC_CAPTURE_MODE_TAKE_OWNERSHIP = 1,
|
||||
|
||||
SPVC_CAPTURE_MODE_INT_MAX = 0x7fffffff
|
||||
} spvc_capture_mode;
|
||||
|
||||
typedef enum spvc_backend
|
||||
{
|
||||
/* This backend can only perform reflection, no compiler options are supported. Maps to spirv_cross::Compiler. */
|
||||
SPVC_BACKEND_NONE = 0,
|
||||
SPVC_BACKEND_GLSL = 1, /* spirv_cross::CompilerGLSL */
|
||||
SPVC_BACKEND_HLSL = 2, /* CompilerHLSL */
|
||||
SPVC_BACKEND_MSL = 3, /* CompilerMSL */
|
||||
SPVC_BACKEND_CPP = 4, /* CompilerCPP */
|
||||
SPVC_BACKEND_JSON = 5, /* CompilerReflection w/ JSON backend */
|
||||
SPVC_BACKEND_INT_MAX = 0x7fffffff
|
||||
} spvc_backend;
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef enum spvc_resource_type
|
||||
{
|
||||
SPVC_RESOURCE_TYPE_UNKNOWN = 0,
|
||||
SPVC_RESOURCE_TYPE_UNIFORM_BUFFER = 1,
|
||||
SPVC_RESOURCE_TYPE_STORAGE_BUFFER = 2,
|
||||
SPVC_RESOURCE_TYPE_STAGE_INPUT = 3,
|
||||
SPVC_RESOURCE_TYPE_STAGE_OUTPUT = 4,
|
||||
SPVC_RESOURCE_TYPE_SUBPASS_INPUT = 5,
|
||||
SPVC_RESOURCE_TYPE_STORAGE_IMAGE = 6,
|
||||
SPVC_RESOURCE_TYPE_SAMPLED_IMAGE = 7,
|
||||
SPVC_RESOURCE_TYPE_ATOMIC_COUNTER = 8,
|
||||
SPVC_RESOURCE_TYPE_PUSH_CONSTANT = 9,
|
||||
SPVC_RESOURCE_TYPE_SEPARATE_IMAGE = 10,
|
||||
SPVC_RESOURCE_TYPE_SEPARATE_SAMPLERS = 11,
|
||||
SPVC_RESOURCE_TYPE_ACCELERATION_STRUCTURE = 12,
|
||||
SPVC_RESOURCE_TYPE_RAY_QUERY = 13,
|
||||
SPVC_RESOURCE_TYPE_INT_MAX = 0x7fffffff
|
||||
} spvc_resource_type;
|
||||
|
||||
/* Maps to spirv_cross::SPIRType::BaseType. */
|
||||
typedef enum spvc_basetype
|
||||
{
|
||||
SPVC_BASETYPE_UNKNOWN = 0,
|
||||
SPVC_BASETYPE_VOID = 1,
|
||||
SPVC_BASETYPE_BOOLEAN = 2,
|
||||
SPVC_BASETYPE_INT8 = 3,
|
||||
SPVC_BASETYPE_UINT8 = 4,
|
||||
SPVC_BASETYPE_INT16 = 5,
|
||||
SPVC_BASETYPE_UINT16 = 6,
|
||||
SPVC_BASETYPE_INT32 = 7,
|
||||
SPVC_BASETYPE_UINT32 = 8,
|
||||
SPVC_BASETYPE_INT64 = 9,
|
||||
SPVC_BASETYPE_UINT64 = 10,
|
||||
SPVC_BASETYPE_ATOMIC_COUNTER = 11,
|
||||
SPVC_BASETYPE_FP16 = 12,
|
||||
SPVC_BASETYPE_FP32 = 13,
|
||||
SPVC_BASETYPE_FP64 = 14,
|
||||
SPVC_BASETYPE_STRUCT = 15,
|
||||
SPVC_BASETYPE_IMAGE = 16,
|
||||
SPVC_BASETYPE_SAMPLED_IMAGE = 17,
|
||||
SPVC_BASETYPE_SAMPLER = 18,
|
||||
SPVC_BASETYPE_ACCELERATION_STRUCTURE = 19,
|
||||
|
||||
SPVC_BASETYPE_INT_MAX = 0x7fffffff
|
||||
} spvc_basetype;
|
||||
|
||||
#define SPVC_COMPILER_OPTION_COMMON_BIT 0x1000000
|
||||
#define SPVC_COMPILER_OPTION_GLSL_BIT 0x2000000
|
||||
#define SPVC_COMPILER_OPTION_HLSL_BIT 0x4000000
|
||||
#define SPVC_COMPILER_OPTION_MSL_BIT 0x8000000
|
||||
#define SPVC_COMPILER_OPTION_LANG_BITS 0x0f000000
|
||||
#define SPVC_COMPILER_OPTION_ENUM_BITS 0xffffff
|
||||
|
||||
#define SPVC_MAKE_MSL_VERSION(major, minor, patch) ((major) * 10000 + (minor) * 100 + (patch))
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef enum spvc_msl_platform
|
||||
{
|
||||
SPVC_MSL_PLATFORM_IOS = 0,
|
||||
SPVC_MSL_PLATFORM_MACOS = 1,
|
||||
SPVC_MSL_PLATFORM_MAX_INT = 0x7fffffff
|
||||
} spvc_msl_platform;
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef enum spvc_msl_vertex_format
|
||||
{
|
||||
SPVC_MSL_VERTEX_FORMAT_OTHER = 0,
|
||||
SPVC_MSL_VERTEX_FORMAT_UINT8 = 1,
|
||||
SPVC_MSL_VERTEX_FORMAT_UINT16 = 2
|
||||
} spvc_msl_vertex_format;
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef struct spvc_msl_vertex_attribute
|
||||
{
|
||||
unsigned location;
|
||||
unsigned msl_buffer;
|
||||
unsigned msl_offset;
|
||||
unsigned msl_stride;
|
||||
spvc_bool per_instance;
|
||||
spvc_msl_vertex_format format;
|
||||
SpvBuiltIn builtin;
|
||||
} spvc_msl_vertex_attribute;
|
||||
|
||||
/*
|
||||
* Initializes the vertex attribute struct.
|
||||
*/
|
||||
SPVC_PUBLIC_API void spvc_msl_vertex_attribute_init(spvc_msl_vertex_attribute *attr);
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef struct spvc_msl_resource_binding
|
||||
{
|
||||
SpvExecutionModel stage;
|
||||
unsigned desc_set;
|
||||
unsigned binding;
|
||||
unsigned msl_buffer;
|
||||
unsigned msl_texture;
|
||||
unsigned msl_sampler;
|
||||
} spvc_msl_resource_binding;
|
||||
|
||||
/*
|
||||
* Initializes the resource binding struct.
|
||||
* The defaults are non-zero.
|
||||
*/
|
||||
SPVC_PUBLIC_API void spvc_msl_resource_binding_init(spvc_msl_resource_binding *binding);
|
||||
|
||||
#define SPVC_MSL_PUSH_CONSTANT_DESC_SET (~(0u))
|
||||
#define SPVC_MSL_PUSH_CONSTANT_BINDING (0)
|
||||
#define SPVC_MSL_SWIZZLE_BUFFER_BINDING (~(1u))
|
||||
#define SPVC_MSL_BUFFER_SIZE_BUFFER_BINDING (~(2u))
|
||||
#define SPVC_MSL_ARGUMENT_BUFFER_BINDING (~(3u))
|
||||
|
||||
/* Obsolete. Sticks around for backwards compatibility. */
|
||||
#define SPVC_MSL_AUX_BUFFER_STRUCT_VERSION 1
|
||||
|
||||
/* Runtime check for incompatibility. Obsolete. */
|
||||
SPVC_PUBLIC_API unsigned spvc_msl_get_aux_buffer_struct_version(void);
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef enum spvc_msl_sampler_coord
|
||||
{
|
||||
SPVC_MSL_SAMPLER_COORD_NORMALIZED = 0,
|
||||
SPVC_MSL_SAMPLER_COORD_PIXEL = 1,
|
||||
SPVC_MSL_SAMPLER_INT_MAX = 0x7fffffff
|
||||
} spvc_msl_sampler_coord;
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef enum spvc_msl_sampler_filter
|
||||
{
|
||||
SPVC_MSL_SAMPLER_FILTER_NEAREST = 0,
|
||||
SPVC_MSL_SAMPLER_FILTER_LINEAR = 1,
|
||||
SPVC_MSL_SAMPLER_FILTER_INT_MAX = 0x7fffffff
|
||||
} spvc_msl_sampler_filter;
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef enum spvc_msl_sampler_mip_filter
|
||||
{
|
||||
SPVC_MSL_SAMPLER_MIP_FILTER_NONE = 0,
|
||||
SPVC_MSL_SAMPLER_MIP_FILTER_NEAREST = 1,
|
||||
SPVC_MSL_SAMPLER_MIP_FILTER_LINEAR = 2,
|
||||
SPVC_MSL_SAMPLER_MIP_FILTER_INT_MAX = 0x7fffffff
|
||||
} spvc_msl_sampler_mip_filter;
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef enum spvc_msl_sampler_address
|
||||
{
|
||||
SPVC_MSL_SAMPLER_ADDRESS_CLAMP_TO_ZERO = 0,
|
||||
SPVC_MSL_SAMPLER_ADDRESS_CLAMP_TO_EDGE = 1,
|
||||
SPVC_MSL_SAMPLER_ADDRESS_CLAMP_TO_BORDER = 2,
|
||||
SPVC_MSL_SAMPLER_ADDRESS_REPEAT = 3,
|
||||
SPVC_MSL_SAMPLER_ADDRESS_MIRRORED_REPEAT = 4,
|
||||
SPVC_MSL_SAMPLER_ADDRESS_INT_MAX = 0x7fffffff
|
||||
} spvc_msl_sampler_address;
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef enum spvc_msl_sampler_compare_func
|
||||
{
|
||||
SPVC_MSL_SAMPLER_COMPARE_FUNC_NEVER = 0,
|
||||
SPVC_MSL_SAMPLER_COMPARE_FUNC_LESS = 1,
|
||||
SPVC_MSL_SAMPLER_COMPARE_FUNC_LESS_EQUAL = 2,
|
||||
SPVC_MSL_SAMPLER_COMPARE_FUNC_GREATER = 3,
|
||||
SPVC_MSL_SAMPLER_COMPARE_FUNC_GREATER_EQUAL = 4,
|
||||
SPVC_MSL_SAMPLER_COMPARE_FUNC_EQUAL = 5,
|
||||
SPVC_MSL_SAMPLER_COMPARE_FUNC_NOT_EQUAL = 6,
|
||||
SPVC_MSL_SAMPLER_COMPARE_FUNC_ALWAYS = 7,
|
||||
SPVC_MSL_SAMPLER_COMPARE_FUNC_INT_MAX = 0x7fffffff
|
||||
} spvc_msl_sampler_compare_func;
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef enum spvc_msl_sampler_border_color
|
||||
{
|
||||
SPVC_MSL_SAMPLER_BORDER_COLOR_TRANSPARENT_BLACK = 0,
|
||||
SPVC_MSL_SAMPLER_BORDER_COLOR_OPAQUE_BLACK = 1,
|
||||
SPVC_MSL_SAMPLER_BORDER_COLOR_OPAQUE_WHITE = 2,
|
||||
SPVC_MSL_SAMPLER_BORDER_COLOR_INT_MAX = 0x7fffffff
|
||||
} spvc_msl_sampler_border_color;
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef enum spvc_msl_format_resolution
|
||||
{
|
||||
SPVC_MSL_FORMAT_RESOLUTION_444 = 0,
|
||||
SPVC_MSL_FORMAT_RESOLUTION_422,
|
||||
SPVC_MSL_FORMAT_RESOLUTION_420,
|
||||
SPVC_MSL_FORMAT_RESOLUTION_INT_MAX = 0x7fffffff
|
||||
} spvc_msl_format_resolution;
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef enum spvc_msl_chroma_location
|
||||
{
|
||||
SPVC_MSL_CHROMA_LOCATION_COSITED_EVEN = 0,
|
||||
SPVC_MSL_CHROMA_LOCATION_MIDPOINT,
|
||||
SPVC_MSL_CHROMA_LOCATION_INT_MAX = 0x7fffffff
|
||||
} spvc_msl_chroma_location;
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef enum spvc_msl_component_swizzle
|
||||
{
|
||||
SPVC_MSL_COMPONENT_SWIZZLE_IDENTITY = 0,
|
||||
SPVC_MSL_COMPONENT_SWIZZLE_ZERO,
|
||||
SPVC_MSL_COMPONENT_SWIZZLE_ONE,
|
||||
SPVC_MSL_COMPONENT_SWIZZLE_R,
|
||||
SPVC_MSL_COMPONENT_SWIZZLE_G,
|
||||
SPVC_MSL_COMPONENT_SWIZZLE_B,
|
||||
SPVC_MSL_COMPONENT_SWIZZLE_A,
|
||||
SPVC_MSL_COMPONENT_SWIZZLE_INT_MAX = 0x7fffffff
|
||||
} spvc_msl_component_swizzle;
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef enum spvc_msl_sampler_ycbcr_model_conversion
|
||||
{
|
||||
SPVC_MSL_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY = 0,
|
||||
SPVC_MSL_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_IDENTITY,
|
||||
SPVC_MSL_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_BT_709,
|
||||
SPVC_MSL_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_BT_601,
|
||||
SPVC_MSL_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_BT_2020,
|
||||
SPVC_MSL_SAMPLER_YCBCR_MODEL_CONVERSION_INT_MAX = 0x7fffffff
|
||||
} spvc_msl_sampler_ycbcr_model_conversion;
|
||||
|
||||
/* Maps to C+ API. */
|
||||
typedef enum spvc_msl_sampler_ycbcr_range
|
||||
{
|
||||
SPVC_MSL_SAMPLER_YCBCR_RANGE_ITU_FULL = 0,
|
||||
SPVC_MSL_SAMPLER_YCBCR_RANGE_ITU_NARROW,
|
||||
SPVC_MSL_SAMPLER_YCBCR_RANGE_INT_MAX = 0x7fffffff
|
||||
} spvc_msl_sampler_ycbcr_range;
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef struct spvc_msl_constexpr_sampler
|
||||
{
|
||||
spvc_msl_sampler_coord coord;
|
||||
spvc_msl_sampler_filter min_filter;
|
||||
spvc_msl_sampler_filter mag_filter;
|
||||
spvc_msl_sampler_mip_filter mip_filter;
|
||||
spvc_msl_sampler_address s_address;
|
||||
spvc_msl_sampler_address t_address;
|
||||
spvc_msl_sampler_address r_address;
|
||||
spvc_msl_sampler_compare_func compare_func;
|
||||
spvc_msl_sampler_border_color border_color;
|
||||
float lod_clamp_min;
|
||||
float lod_clamp_max;
|
||||
int max_anisotropy;
|
||||
|
||||
spvc_bool compare_enable;
|
||||
spvc_bool lod_clamp_enable;
|
||||
spvc_bool anisotropy_enable;
|
||||
} spvc_msl_constexpr_sampler;
|
||||
|
||||
/*
|
||||
* Initializes the constexpr sampler struct.
|
||||
* The defaults are non-zero.
|
||||
*/
|
||||
SPVC_PUBLIC_API void spvc_msl_constexpr_sampler_init(spvc_msl_constexpr_sampler *sampler);
|
||||
|
||||
/* Maps to the sampler Y'CbCr conversion-related portions of MSLConstexprSampler. See C++ API for defaults and details. */
|
||||
typedef struct spvc_msl_sampler_ycbcr_conversion
|
||||
{
|
||||
unsigned planes;
|
||||
spvc_msl_format_resolution resolution;
|
||||
spvc_msl_sampler_filter chroma_filter;
|
||||
spvc_msl_chroma_location x_chroma_offset;
|
||||
spvc_msl_chroma_location y_chroma_offset;
|
||||
spvc_msl_component_swizzle swizzle[4];
|
||||
spvc_msl_sampler_ycbcr_model_conversion ycbcr_model;
|
||||
spvc_msl_sampler_ycbcr_range ycbcr_range;
|
||||
unsigned bpc;
|
||||
} spvc_msl_sampler_ycbcr_conversion;
|
||||
|
||||
/*
|
||||
* Initializes the constexpr sampler struct.
|
||||
* The defaults are non-zero.
|
||||
*/
|
||||
SPVC_PUBLIC_API void spvc_msl_sampler_ycbcr_conversion_init(spvc_msl_sampler_ycbcr_conversion *conv);
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef enum spvc_hlsl_binding_flag_bits
|
||||
{
|
||||
SPVC_HLSL_BINDING_AUTO_NONE_BIT = 0,
|
||||
SPVC_HLSL_BINDING_AUTO_PUSH_CONSTANT_BIT = 1 << 0,
|
||||
SPVC_HLSL_BINDING_AUTO_CBV_BIT = 1 << 1,
|
||||
SPVC_HLSL_BINDING_AUTO_SRV_BIT = 1 << 2,
|
||||
SPVC_HLSL_BINDING_AUTO_UAV_BIT = 1 << 3,
|
||||
SPVC_HLSL_BINDING_AUTO_SAMPLER_BIT = 1 << 4,
|
||||
SPVC_HLSL_BINDING_AUTO_ALL = 0x7fffffff
|
||||
} spvc_hlsl_binding_flag_bits;
|
||||
typedef unsigned spvc_hlsl_binding_flags;
|
||||
|
||||
#define SPVC_HLSL_PUSH_CONSTANT_DESC_SET (~(0u))
|
||||
#define SPVC_HLSL_PUSH_CONSTANT_BINDING (0)
|
||||
|
||||
/* Maps to C++ API. */
|
||||
typedef struct spvc_hlsl_resource_binding_mapping
|
||||
{
|
||||
unsigned register_space;
|
||||
unsigned register_binding;
|
||||
} spvc_hlsl_resource_binding_mapping;
|
||||
|
||||
typedef struct spvc_hlsl_resource_binding
|
||||
{
|
||||
SpvExecutionModel stage;
|
||||
unsigned desc_set;
|
||||
unsigned binding;
|
||||
|
||||
spvc_hlsl_resource_binding_mapping cbv, uav, srv, sampler;
|
||||
} spvc_hlsl_resource_binding;
|
||||
|
||||
/*
|
||||
* Initializes the resource binding struct.
|
||||
* The defaults are non-zero.
|
||||
*/
|
||||
SPVC_PUBLIC_API void spvc_hlsl_resource_binding_init(spvc_hlsl_resource_binding *binding);
|
||||
|
||||
/* Maps to the various spirv_cross::Compiler*::Option structures. See C++ API for defaults and details. */
|
||||
typedef enum spvc_compiler_option
|
||||
{
|
||||
SPVC_COMPILER_OPTION_UNKNOWN = 0,
|
||||
|
||||
SPVC_COMPILER_OPTION_FORCE_TEMPORARY = 1 | SPVC_COMPILER_OPTION_COMMON_BIT,
|
||||
SPVC_COMPILER_OPTION_FLATTEN_MULTIDIMENSIONAL_ARRAYS = 2 | SPVC_COMPILER_OPTION_COMMON_BIT,
|
||||
SPVC_COMPILER_OPTION_FIXUP_DEPTH_CONVENTION = 3 | SPVC_COMPILER_OPTION_COMMON_BIT,
|
||||
SPVC_COMPILER_OPTION_FLIP_VERTEX_Y = 4 | SPVC_COMPILER_OPTION_COMMON_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_GLSL_SUPPORT_NONZERO_BASE_INSTANCE = 5 | SPVC_COMPILER_OPTION_GLSL_BIT,
|
||||
SPVC_COMPILER_OPTION_GLSL_SEPARATE_SHADER_OBJECTS = 6 | SPVC_COMPILER_OPTION_GLSL_BIT,
|
||||
SPVC_COMPILER_OPTION_GLSL_ENABLE_420PACK_EXTENSION = 7 | SPVC_COMPILER_OPTION_GLSL_BIT,
|
||||
SPVC_COMPILER_OPTION_GLSL_VERSION = 8 | SPVC_COMPILER_OPTION_GLSL_BIT,
|
||||
SPVC_COMPILER_OPTION_GLSL_ES = 9 | SPVC_COMPILER_OPTION_GLSL_BIT,
|
||||
SPVC_COMPILER_OPTION_GLSL_VULKAN_SEMANTICS = 10 | SPVC_COMPILER_OPTION_GLSL_BIT,
|
||||
SPVC_COMPILER_OPTION_GLSL_ES_DEFAULT_FLOAT_PRECISION_HIGHP = 11 | SPVC_COMPILER_OPTION_GLSL_BIT,
|
||||
SPVC_COMPILER_OPTION_GLSL_ES_DEFAULT_INT_PRECISION_HIGHP = 12 | SPVC_COMPILER_OPTION_GLSL_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_HLSL_SHADER_MODEL = 13 | SPVC_COMPILER_OPTION_HLSL_BIT,
|
||||
SPVC_COMPILER_OPTION_HLSL_POINT_SIZE_COMPAT = 14 | SPVC_COMPILER_OPTION_HLSL_BIT,
|
||||
SPVC_COMPILER_OPTION_HLSL_POINT_COORD_COMPAT = 15 | SPVC_COMPILER_OPTION_HLSL_BIT,
|
||||
SPVC_COMPILER_OPTION_HLSL_SUPPORT_NONZERO_BASE_VERTEX_BASE_INSTANCE = 16 | SPVC_COMPILER_OPTION_HLSL_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_MSL_VERSION = 17 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_TEXEL_BUFFER_TEXTURE_WIDTH = 18 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
|
||||
/* Obsolete, use SWIZZLE_BUFFER_INDEX instead. */
|
||||
SPVC_COMPILER_OPTION_MSL_AUX_BUFFER_INDEX = 19 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_SWIZZLE_BUFFER_INDEX = 19 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_MSL_INDIRECT_PARAMS_BUFFER_INDEX = 20 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_SHADER_OUTPUT_BUFFER_INDEX = 21 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_SHADER_PATCH_OUTPUT_BUFFER_INDEX = 22 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_SHADER_TESS_FACTOR_OUTPUT_BUFFER_INDEX = 23 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_SHADER_INPUT_WORKGROUP_INDEX = 24 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_ENABLE_POINT_SIZE_BUILTIN = 25 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_DISABLE_RASTERIZATION = 26 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_CAPTURE_OUTPUT_TO_BUFFER = 27 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_SWIZZLE_TEXTURE_SAMPLES = 28 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_PAD_FRAGMENT_OUTPUT_COMPONENTS = 29 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_TESS_DOMAIN_ORIGIN_LOWER_LEFT = 30 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_PLATFORM = 31 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_ARGUMENT_BUFFERS = 32 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_GLSL_EMIT_PUSH_CONSTANT_AS_UNIFORM_BUFFER = 33 | SPVC_COMPILER_OPTION_GLSL_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_MSL_TEXTURE_BUFFER_NATIVE = 34 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_GLSL_EMIT_UNIFORM_BUFFER_AS_PLAIN_UNIFORMS = 35 | SPVC_COMPILER_OPTION_GLSL_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_MSL_BUFFER_SIZE_BUFFER_INDEX = 36 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_EMIT_LINE_DIRECTIVES = 37 | SPVC_COMPILER_OPTION_COMMON_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_MSL_MULTIVIEW = 38 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_VIEW_MASK_BUFFER_INDEX = 39 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_DEVICE_INDEX = 40 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_VIEW_INDEX_FROM_DEVICE_INDEX = 41 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_DISPATCH_BASE = 42 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_DYNAMIC_OFFSETS_BUFFER_INDEX = 43 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_TEXTURE_1D_AS_2D = 44 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_ENABLE_BASE_INDEX_ZERO = 45 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_IOS_FRAMEBUFFER_FETCH_SUBPASS = 46 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_INVARIANT_FP_MATH = 47 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_EMULATE_CUBEMAP_ARRAY = 48 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_ENABLE_DECORATION_BINDING = 49 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_FORCE_ACTIVE_ARGUMENT_BUFFER_RESOURCES = 50 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_FORCE_NATIVE_ARRAYS = 51 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_ENABLE_STORAGE_IMAGE_QUALIFIER_DEDUCTION = 52 | SPVC_COMPILER_OPTION_COMMON_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_HLSL_FORCE_STORAGE_BUFFER_AS_UAV = 53 | SPVC_COMPILER_OPTION_HLSL_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_FORCE_ZERO_INITIALIZED_VARIABLES = 54 | SPVC_COMPILER_OPTION_COMMON_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_HLSL_NONWRITABLE_UAV_TEXTURE_AS_SRV = 55 | SPVC_COMPILER_OPTION_HLSL_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_MSL_ENABLE_FRAG_OUTPUT_MASK = 56 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_ENABLE_FRAG_DEPTH_BUILTIN = 57 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_ENABLE_FRAG_STENCIL_REF_BUILTIN = 58 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
SPVC_COMPILER_OPTION_MSL_ENABLE_CLIP_DISTANCE_USER_VARYING = 59 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_INT_MAX = 0x7fffffff
|
||||
} spvc_compiler_option;
|
||||
|
||||
/*
|
||||
* Context is the highest-level API construct.
|
||||
* The context owns all memory allocations made by its child object hierarchy, including various non-opaque structs and strings.
|
||||
* This means that the API user only has to care about one "destroy" call ever when using the C API.
|
||||
* All pointers handed out by the APIs are only valid as long as the context
|
||||
* is alive and spvc_context_release_allocations has not been called.
|
||||
*/
|
||||
SPVC_PUBLIC_API spvc_result spvc_context_create(spvc_context *context);
|
||||
|
||||
/* Frees all memory allocations and objects associated with the context and its child objects. */
|
||||
SPVC_PUBLIC_API void spvc_context_destroy(spvc_context context);
|
||||
|
||||
/* Frees all memory allocations and objects associated with the context and its child objects, but keeps the context alive. */
|
||||
SPVC_PUBLIC_API void spvc_context_release_allocations(spvc_context context);
|
||||
|
||||
/* Get the string for the last error which was logged. */
|
||||
SPVC_PUBLIC_API const char *spvc_context_get_last_error_string(spvc_context context);
|
||||
|
||||
/* Get notified in a callback when an error triggers. Useful for debugging. */
|
||||
typedef void (*spvc_error_callback)(void *userdata, const char *error);
|
||||
SPVC_PUBLIC_API void spvc_context_set_error_callback(spvc_context context, spvc_error_callback cb, void *userdata);
|
||||
|
||||
/* SPIR-V parsing interface. Maps to Parser which then creates a ParsedIR, and that IR is extracted into the handle. */
|
||||
SPVC_PUBLIC_API spvc_result spvc_context_parse_spirv(spvc_context context, const SpvId *spirv, size_t word_count,
|
||||
spvc_parsed_ir *parsed_ir);
|
||||
|
||||
/*
|
||||
* Create a compiler backend. Capture mode controls if we construct by copy or move semantics.
|
||||
* It is always recommended to use SPVC_CAPTURE_MODE_TAKE_OWNERSHIP if you only intend to cross-compile the IR once.
|
||||
*/
|
||||
SPVC_PUBLIC_API spvc_result spvc_context_create_compiler(spvc_context context, spvc_backend backend,
|
||||
spvc_parsed_ir parsed_ir, spvc_capture_mode mode,
|
||||
spvc_compiler *compiler);
|
||||
|
||||
/* Maps directly to C++ API. */
|
||||
SPVC_PUBLIC_API unsigned spvc_compiler_get_current_id_bound(spvc_compiler compiler);
|
||||
|
||||
/* Create compiler options, which will initialize defaults. */
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_create_compiler_options(spvc_compiler compiler,
|
||||
spvc_compiler_options *options);
|
||||
/* Override options. Will return error if e.g. MSL options are used for the HLSL backend, etc. */
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_options_set_bool(spvc_compiler_options options,
|
||||
spvc_compiler_option option, spvc_bool value);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_options_set_uint(spvc_compiler_options options,
|
||||
spvc_compiler_option option, unsigned value);
|
||||
/* Set compiler options. */
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_install_compiler_options(spvc_compiler compiler,
|
||||
spvc_compiler_options options);
|
||||
|
||||
/* Compile IR into a string. *source is owned by the context, and caller must not free it themselves. */
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_compile(spvc_compiler compiler, const char **source);
|
||||
|
||||
/* Maps to C++ API. */
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_add_header_line(spvc_compiler compiler, const char *line);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_require_extension(spvc_compiler compiler, const char *ext);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_flatten_buffer_block(spvc_compiler compiler, spvc_variable_id id);
|
||||
|
||||
SPVC_PUBLIC_API spvc_bool spvc_compiler_variable_is_depth_or_compare(spvc_compiler compiler, spvc_variable_id id);
|
||||
|
||||
/*
|
||||
* HLSL specifics.
|
||||
* Maps to C++ API.
|
||||
*/
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_hlsl_set_root_constants_layout(spvc_compiler compiler,
|
||||
const spvc_hlsl_root_constants *constant_info,
|
||||
size_t count);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_hlsl_add_vertex_attribute_remap(spvc_compiler compiler,
|
||||
const spvc_hlsl_vertex_attribute_remap *remap,
|
||||
size_t remaps);
|
||||
SPVC_PUBLIC_API spvc_variable_id spvc_compiler_hlsl_remap_num_workgroups_builtin(spvc_compiler compiler);
|
||||
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_hlsl_set_resource_binding_flags(spvc_compiler compiler,
|
||||
spvc_hlsl_binding_flags flags);
|
||||
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_hlsl_add_resource_binding(spvc_compiler compiler,
|
||||
const spvc_hlsl_resource_binding *binding);
|
||||
SPVC_PUBLIC_API spvc_bool spvc_compiler_hlsl_is_resource_used(spvc_compiler compiler,
|
||||
SpvExecutionModel model,
|
||||
unsigned set,
|
||||
unsigned binding);
|
||||
|
||||
/*
|
||||
* MSL specifics.
|
||||
* Maps to C++ API.
|
||||
*/
|
||||
SPVC_PUBLIC_API spvc_bool spvc_compiler_msl_is_rasterization_disabled(spvc_compiler compiler);
|
||||
|
||||
/* Obsolete. Renamed to needs_swizzle_buffer. */
|
||||
SPVC_PUBLIC_API spvc_bool spvc_compiler_msl_needs_aux_buffer(spvc_compiler compiler);
|
||||
SPVC_PUBLIC_API spvc_bool spvc_compiler_msl_needs_swizzle_buffer(spvc_compiler compiler);
|
||||
SPVC_PUBLIC_API spvc_bool spvc_compiler_msl_needs_buffer_size_buffer(spvc_compiler compiler);
|
||||
|
||||
SPVC_PUBLIC_API spvc_bool spvc_compiler_msl_needs_output_buffer(spvc_compiler compiler);
|
||||
SPVC_PUBLIC_API spvc_bool spvc_compiler_msl_needs_patch_output_buffer(spvc_compiler compiler);
|
||||
SPVC_PUBLIC_API spvc_bool spvc_compiler_msl_needs_input_threadgroup_mem(spvc_compiler compiler);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_msl_add_vertex_attribute(spvc_compiler compiler,
|
||||
const spvc_msl_vertex_attribute *attrs);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_msl_add_resource_binding(spvc_compiler compiler,
|
||||
const spvc_msl_resource_binding *binding);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_msl_add_discrete_descriptor_set(spvc_compiler compiler, unsigned desc_set);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_msl_set_argument_buffer_device_address_space(spvc_compiler compiler, unsigned desc_set, spvc_bool device_address);
|
||||
SPVC_PUBLIC_API spvc_bool spvc_compiler_msl_is_vertex_attribute_used(spvc_compiler compiler, unsigned location);
|
||||
SPVC_PUBLIC_API spvc_bool spvc_compiler_msl_is_resource_used(spvc_compiler compiler,
|
||||
SpvExecutionModel model,
|
||||
unsigned set,
|
||||
unsigned binding);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_msl_remap_constexpr_sampler(spvc_compiler compiler, spvc_variable_id id, const spvc_msl_constexpr_sampler *sampler);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_msl_remap_constexpr_sampler_by_binding(spvc_compiler compiler, unsigned desc_set, unsigned binding, const spvc_msl_constexpr_sampler *sampler);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_msl_remap_constexpr_sampler_ycbcr(spvc_compiler compiler, spvc_variable_id id, const spvc_msl_constexpr_sampler *sampler, const spvc_msl_sampler_ycbcr_conversion *conv);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_msl_remap_constexpr_sampler_by_binding_ycbcr(spvc_compiler compiler, unsigned desc_set, unsigned binding, const spvc_msl_constexpr_sampler *sampler, const spvc_msl_sampler_ycbcr_conversion *conv);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_msl_set_fragment_output_components(spvc_compiler compiler, unsigned location, unsigned components);
|
||||
|
||||
SPVC_PUBLIC_API unsigned spvc_compiler_msl_get_automatic_resource_binding(spvc_compiler compiler, spvc_variable_id id);
|
||||
SPVC_PUBLIC_API unsigned spvc_compiler_msl_get_automatic_resource_binding_secondary(spvc_compiler compiler, spvc_variable_id id);
|
||||
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_msl_add_dynamic_buffer(spvc_compiler compiler, unsigned desc_set, unsigned binding, unsigned index);
|
||||
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_msl_add_inline_uniform_block(spvc_compiler compiler, unsigned desc_set, unsigned binding);
|
||||
|
||||
/*
|
||||
* Reflect resources.
|
||||
* Maps almost 1:1 to C++ API.
|
||||
*/
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_get_active_interface_variables(spvc_compiler compiler, spvc_set *set);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_set_enabled_interface_variables(spvc_compiler compiler, spvc_set set);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_create_shader_resources(spvc_compiler compiler, spvc_resources *resources);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_create_shader_resources_for_active_variables(spvc_compiler compiler,
|
||||
spvc_resources *resources,
|
||||
spvc_set active);
|
||||
SPVC_PUBLIC_API spvc_result spvc_resources_get_resource_list_for_type(spvc_resources resources, spvc_resource_type type,
|
||||
const spvc_reflected_resource **resource_list,
|
||||
size_t *resource_size);
|
||||
|
||||
/*
|
||||
* Decorations.
|
||||
* Maps to C++ API.
|
||||
*/
|
||||
SPVC_PUBLIC_API void spvc_compiler_set_decoration(spvc_compiler compiler, SpvId id, SpvDecoration decoration,
|
||||
unsigned argument);
|
||||
SPVC_PUBLIC_API void spvc_compiler_set_decoration_string(spvc_compiler compiler, SpvId id, SpvDecoration decoration,
|
||||
const char *argument);
|
||||
SPVC_PUBLIC_API void spvc_compiler_set_name(spvc_compiler compiler, SpvId id, const char *argument);
|
||||
SPVC_PUBLIC_API void spvc_compiler_set_member_decoration(spvc_compiler compiler, spvc_type_id id, unsigned member_index,
|
||||
SpvDecoration decoration, unsigned argument);
|
||||
SPVC_PUBLIC_API void spvc_compiler_set_member_decoration_string(spvc_compiler compiler, spvc_type_id id,
|
||||
unsigned member_index, SpvDecoration decoration,
|
||||
const char *argument);
|
||||
SPVC_PUBLIC_API void spvc_compiler_set_member_name(spvc_compiler compiler, spvc_type_id id, unsigned member_index,
|
||||
const char *argument);
|
||||
SPVC_PUBLIC_API void spvc_compiler_unset_decoration(spvc_compiler compiler, SpvId id, SpvDecoration decoration);
|
||||
SPVC_PUBLIC_API void spvc_compiler_unset_member_decoration(spvc_compiler compiler, spvc_type_id id,
|
||||
unsigned member_index, SpvDecoration decoration);
|
||||
|
||||
SPVC_PUBLIC_API spvc_bool spvc_compiler_has_decoration(spvc_compiler compiler, SpvId id, SpvDecoration decoration);
|
||||
SPVC_PUBLIC_API spvc_bool spvc_compiler_has_member_decoration(spvc_compiler compiler, spvc_type_id id,
|
||||
unsigned member_index, SpvDecoration decoration);
|
||||
SPVC_PUBLIC_API const char *spvc_compiler_get_name(spvc_compiler compiler, SpvId id);
|
||||
SPVC_PUBLIC_API unsigned spvc_compiler_get_decoration(spvc_compiler compiler, SpvId id, SpvDecoration decoration);
|
||||
SPVC_PUBLIC_API const char *spvc_compiler_get_decoration_string(spvc_compiler compiler, SpvId id,
|
||||
SpvDecoration decoration);
|
||||
SPVC_PUBLIC_API unsigned spvc_compiler_get_member_decoration(spvc_compiler compiler, spvc_type_id id,
|
||||
unsigned member_index, SpvDecoration decoration);
|
||||
SPVC_PUBLIC_API const char *spvc_compiler_get_member_decoration_string(spvc_compiler compiler, spvc_type_id id,
|
||||
unsigned member_index, SpvDecoration decoration);
|
||||
SPVC_PUBLIC_API const char *spvc_compiler_get_member_name(spvc_compiler compiler, spvc_type_id id, unsigned member_index);
|
||||
|
||||
/*
|
||||
* Entry points.
|
||||
* Maps to C++ API.
|
||||
*/
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_get_entry_points(spvc_compiler compiler,
|
||||
const spvc_entry_point **entry_points,
|
||||
size_t *num_entry_points);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_set_entry_point(spvc_compiler compiler, const char *name,
|
||||
SpvExecutionModel model);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_rename_entry_point(spvc_compiler compiler, const char *old_name,
|
||||
const char *new_name, SpvExecutionModel model);
|
||||
SPVC_PUBLIC_API const char *spvc_compiler_get_cleansed_entry_point_name(spvc_compiler compiler, const char *name,
|
||||
SpvExecutionModel model);
|
||||
SPVC_PUBLIC_API void spvc_compiler_set_execution_mode(spvc_compiler compiler, SpvExecutionMode mode);
|
||||
SPVC_PUBLIC_API void spvc_compiler_unset_execution_mode(spvc_compiler compiler, SpvExecutionMode mode);
|
||||
SPVC_PUBLIC_API void spvc_compiler_set_execution_mode_with_arguments(spvc_compiler compiler, SpvExecutionMode mode,
|
||||
unsigned arg0, unsigned arg1, unsigned arg2);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_get_execution_modes(spvc_compiler compiler, const SpvExecutionMode **modes,
|
||||
size_t *num_modes);
|
||||
SPVC_PUBLIC_API unsigned spvc_compiler_get_execution_mode_argument(spvc_compiler compiler, SpvExecutionMode mode);
|
||||
SPVC_PUBLIC_API unsigned spvc_compiler_get_execution_mode_argument_by_index(spvc_compiler compiler,
|
||||
SpvExecutionMode mode, unsigned index);
|
||||
SPVC_PUBLIC_API SpvExecutionModel spvc_compiler_get_execution_model(spvc_compiler compiler);
|
||||
|
||||
/*
|
||||
* Type query interface.
|
||||
* Maps to C++ API, except it's read-only.
|
||||
*/
|
||||
SPVC_PUBLIC_API spvc_type spvc_compiler_get_type_handle(spvc_compiler compiler, spvc_type_id id);
|
||||
|
||||
/* Pulls out SPIRType::self. This effectively gives the type ID without array or pointer qualifiers.
|
||||
* This is necessary when reflecting decoration/name information on members of a struct,
|
||||
* which are placed in the base type, not the qualified type.
|
||||
* This is similar to spvc_reflected_resource::base_type_id. */
|
||||
SPVC_PUBLIC_API spvc_type_id spvc_type_get_base_type_id(spvc_type type);
|
||||
|
||||
SPVC_PUBLIC_API spvc_basetype spvc_type_get_basetype(spvc_type type);
|
||||
SPVC_PUBLIC_API unsigned spvc_type_get_bit_width(spvc_type type);
|
||||
SPVC_PUBLIC_API unsigned spvc_type_get_vector_size(spvc_type type);
|
||||
SPVC_PUBLIC_API unsigned spvc_type_get_columns(spvc_type type);
|
||||
SPVC_PUBLIC_API unsigned spvc_type_get_num_array_dimensions(spvc_type type);
|
||||
SPVC_PUBLIC_API spvc_bool spvc_type_array_dimension_is_literal(spvc_type type, unsigned dimension);
|
||||
SPVC_PUBLIC_API SpvId spvc_type_get_array_dimension(spvc_type type, unsigned dimension);
|
||||
SPVC_PUBLIC_API unsigned spvc_type_get_num_member_types(spvc_type type);
|
||||
SPVC_PUBLIC_API spvc_type_id spvc_type_get_member_type(spvc_type type, unsigned index);
|
||||
SPVC_PUBLIC_API SpvStorageClass spvc_type_get_storage_class(spvc_type type);
|
||||
|
||||
/* Image type query. */
|
||||
SPVC_PUBLIC_API spvc_type_id spvc_type_get_image_sampled_type(spvc_type type);
|
||||
SPVC_PUBLIC_API SpvDim spvc_type_get_image_dimension(spvc_type type);
|
||||
SPVC_PUBLIC_API spvc_bool spvc_type_get_image_is_depth(spvc_type type);
|
||||
SPVC_PUBLIC_API spvc_bool spvc_type_get_image_arrayed(spvc_type type);
|
||||
SPVC_PUBLIC_API spvc_bool spvc_type_get_image_multisampled(spvc_type type);
|
||||
SPVC_PUBLIC_API spvc_bool spvc_type_get_image_is_storage(spvc_type type);
|
||||
SPVC_PUBLIC_API SpvImageFormat spvc_type_get_image_storage_format(spvc_type type);
|
||||
SPVC_PUBLIC_API SpvAccessQualifier spvc_type_get_image_access_qualifier(spvc_type type);
|
||||
|
||||
/*
|
||||
* Buffer layout query.
|
||||
* Maps to C++ API.
|
||||
*/
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_get_declared_struct_size(spvc_compiler compiler, spvc_type struct_type, size_t *size);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_get_declared_struct_size_runtime_array(spvc_compiler compiler,
|
||||
spvc_type struct_type, size_t array_size, size_t *size);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_get_declared_struct_member_size(spvc_compiler compiler, spvc_type type, unsigned index, size_t *size);
|
||||
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_type_struct_member_offset(spvc_compiler compiler,
|
||||
spvc_type type, unsigned index, unsigned *offset);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_type_struct_member_array_stride(spvc_compiler compiler,
|
||||
spvc_type type, unsigned index, unsigned *stride);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_type_struct_member_matrix_stride(spvc_compiler compiler,
|
||||
spvc_type type, unsigned index, unsigned *stride);
|
||||
|
||||
/*
|
||||
* Workaround helper functions.
|
||||
* Maps to C++ API.
|
||||
*/
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_build_dummy_sampler_for_combined_images(spvc_compiler compiler, spvc_variable_id *id);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_build_combined_image_samplers(spvc_compiler compiler);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_get_combined_image_samplers(spvc_compiler compiler,
|
||||
const spvc_combined_image_sampler **samplers,
|
||||
size_t *num_samplers);
|
||||
|
||||
/*
|
||||
* Constants
|
||||
* Maps to C++ API.
|
||||
*/
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_get_specialization_constants(spvc_compiler compiler,
|
||||
const spvc_specialization_constant **constants,
|
||||
size_t *num_constants);
|
||||
SPVC_PUBLIC_API spvc_constant spvc_compiler_get_constant_handle(spvc_compiler compiler,
|
||||
spvc_constant_id id);
|
||||
|
||||
SPVC_PUBLIC_API spvc_constant_id spvc_compiler_get_work_group_size_specialization_constants(spvc_compiler compiler,
|
||||
spvc_specialization_constant *x,
|
||||
spvc_specialization_constant *y,
|
||||
spvc_specialization_constant *z);
|
||||
|
||||
/*
|
||||
* Buffer ranges
|
||||
* Maps to C++ API.
|
||||
*/
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_get_active_buffer_ranges(spvc_compiler compiler,
|
||||
spvc_variable_id id,
|
||||
const spvc_buffer_range **ranges,
|
||||
size_t *num_ranges);
|
||||
|
||||
/*
|
||||
* No stdint.h until C99, sigh :(
|
||||
* For smaller types, the result is sign or zero-extended as appropriate.
|
||||
* Maps to C++ API.
|
||||
* TODO: The SPIRConstant query interface and modification interface is not quite complete.
|
||||
*/
|
||||
SPVC_PUBLIC_API float spvc_constant_get_scalar_fp16(spvc_constant constant, unsigned column, unsigned row);
|
||||
SPVC_PUBLIC_API float spvc_constant_get_scalar_fp32(spvc_constant constant, unsigned column, unsigned row);
|
||||
SPVC_PUBLIC_API double spvc_constant_get_scalar_fp64(spvc_constant constant, unsigned column, unsigned row);
|
||||
SPVC_PUBLIC_API unsigned spvc_constant_get_scalar_u32(spvc_constant constant, unsigned column, unsigned row);
|
||||
SPVC_PUBLIC_API int spvc_constant_get_scalar_i32(spvc_constant constant, unsigned column, unsigned row);
|
||||
SPVC_PUBLIC_API unsigned spvc_constant_get_scalar_u16(spvc_constant constant, unsigned column, unsigned row);
|
||||
SPVC_PUBLIC_API int spvc_constant_get_scalar_i16(spvc_constant constant, unsigned column, unsigned row);
|
||||
SPVC_PUBLIC_API unsigned spvc_constant_get_scalar_u8(spvc_constant constant, unsigned column, unsigned row);
|
||||
SPVC_PUBLIC_API int spvc_constant_get_scalar_i8(spvc_constant constant, unsigned column, unsigned row);
|
||||
SPVC_PUBLIC_API void spvc_constant_get_subconstants(spvc_constant constant, const spvc_constant_id **constituents, size_t *count);
|
||||
SPVC_PUBLIC_API spvc_type_id spvc_constant_get_type(spvc_constant constant);
|
||||
|
||||
/*
|
||||
* Misc reflection
|
||||
* Maps to C++ API.
|
||||
*/
|
||||
SPVC_PUBLIC_API spvc_bool spvc_compiler_get_binary_offset_for_decoration(spvc_compiler compiler,
|
||||
spvc_variable_id id,
|
||||
SpvDecoration decoration,
|
||||
unsigned *word_offset);
|
||||
|
||||
SPVC_PUBLIC_API spvc_bool spvc_compiler_buffer_is_hlsl_counter_buffer(spvc_compiler compiler, spvc_variable_id id);
|
||||
SPVC_PUBLIC_API spvc_bool spvc_compiler_buffer_get_hlsl_counter_buffer(spvc_compiler compiler, spvc_variable_id id,
|
||||
spvc_variable_id *counter_id);
|
||||
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_get_declared_capabilities(spvc_compiler compiler,
|
||||
const SpvCapability **capabilities,
|
||||
size_t *num_capabilities);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_get_declared_extensions(spvc_compiler compiler, const char ***extensions,
|
||||
size_t *num_extensions);
|
||||
|
||||
SPVC_PUBLIC_API const char *spvc_compiler_get_remapped_declared_block_name(spvc_compiler compiler, spvc_variable_id id);
|
||||
SPVC_PUBLIC_API spvc_result spvc_compiler_get_buffer_block_decorations(spvc_compiler compiler, spvc_variable_id id,
|
||||
const SpvDecoration **decorations,
|
||||
size_t *num_decorations);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -0,0 +1,734 @@
|
|||
/*
|
||||
* Copyright 2019-2020 Hans-Kristian Arntzen
|
||||
*
|
||||
* 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 SPIRV_CROSS_CONTAINERS_HPP
|
||||
#define SPIRV_CROSS_CONTAINERS_HPP
|
||||
|
||||
#include "spirv_cross_error_handling.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#ifdef SPIRV_CROSS_NAMESPACE_OVERRIDE
|
||||
#define SPIRV_CROSS_NAMESPACE SPIRV_CROSS_NAMESPACE_OVERRIDE
|
||||
#else
|
||||
#define SPIRV_CROSS_NAMESPACE spirv_cross
|
||||
#endif
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
#ifndef SPIRV_CROSS_FORCE_STL_TYPES
|
||||
// std::aligned_storage does not support size == 0, so roll our own.
|
||||
template <typename T, size_t N>
|
||||
class AlignedBuffer
|
||||
{
|
||||
public:
|
||||
T *data()
|
||||
{
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
// MSVC 2013 workarounds, sigh ...
|
||||
// Only use this workaround on MSVC 2013 due to some confusion around default initialized unions.
|
||||
// Spec seems to suggest the memory will be zero-initialized, which is *not* what we want.
|
||||
return reinterpret_cast<T *>(u.aligned_char);
|
||||
#else
|
||||
return reinterpret_cast<T *>(aligned_char);
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
// MSVC 2013 workarounds, sigh ...
|
||||
union {
|
||||
char aligned_char[sizeof(T) * N];
|
||||
double dummy_aligner;
|
||||
} u;
|
||||
#else
|
||||
alignas(T) char aligned_char[sizeof(T) * N];
|
||||
#endif
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class AlignedBuffer<T, 0>
|
||||
{
|
||||
public:
|
||||
T *data()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
// An immutable version of SmallVector which erases type information about storage.
|
||||
template <typename T>
|
||||
class VectorView
|
||||
{
|
||||
public:
|
||||
T &operator[](size_t i) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr[i];
|
||||
}
|
||||
|
||||
const T &operator[](size_t i) const SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr[i];
|
||||
}
|
||||
|
||||
bool empty() const SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return buffer_size == 0;
|
||||
}
|
||||
|
||||
size_t size() const SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return buffer_size;
|
||||
}
|
||||
|
||||
T *data() SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
const T *data() const SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
T *begin() SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
T *end() SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr + buffer_size;
|
||||
}
|
||||
|
||||
const T *begin() const SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
const T *end() const SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr + buffer_size;
|
||||
}
|
||||
|
||||
T &front() SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr[0];
|
||||
}
|
||||
|
||||
const T &front() const SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr[0];
|
||||
}
|
||||
|
||||
T &back() SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr[buffer_size - 1];
|
||||
}
|
||||
|
||||
const T &back() const SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr[buffer_size - 1];
|
||||
}
|
||||
|
||||
// Makes it easier to consume SmallVector.
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
explicit operator std::vector<T>() const
|
||||
{
|
||||
// Another MSVC 2013 workaround. It does not understand lvalue/rvalue qualified operations.
|
||||
return std::vector<T>(ptr, ptr + buffer_size);
|
||||
}
|
||||
#else
|
||||
// Makes it easier to consume SmallVector.
|
||||
explicit operator std::vector<T>() const &
|
||||
{
|
||||
return std::vector<T>(ptr, ptr + buffer_size);
|
||||
}
|
||||
|
||||
// If we are converting as an r-value, we can pilfer our elements.
|
||||
explicit operator std::vector<T>() &&
|
||||
{
|
||||
return std::vector<T>(std::make_move_iterator(ptr), std::make_move_iterator(ptr + buffer_size));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Avoid sliced copies. Base class should only be read as a reference.
|
||||
VectorView(const VectorView &) = delete;
|
||||
void operator=(const VectorView &) = delete;
|
||||
|
||||
protected:
|
||||
VectorView() = default;
|
||||
T *ptr = nullptr;
|
||||
size_t buffer_size = 0;
|
||||
};
|
||||
|
||||
// Simple vector which supports up to N elements inline, without malloc/free.
|
||||
// We use a lot of throwaway vectors all over the place which triggers allocations.
|
||||
// This class only implements the subset of std::vector we need in SPIRV-Cross.
|
||||
// It is *NOT* a drop-in replacement in general projects.
|
||||
template <typename T, size_t N = 8>
|
||||
class SmallVector : public VectorView<T>
|
||||
{
|
||||
public:
|
||||
SmallVector() SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
this->ptr = stack_storage.data();
|
||||
buffer_capacity = N;
|
||||
}
|
||||
|
||||
SmallVector(const T *arg_list_begin, const T *arg_list_end) SPIRV_CROSS_NOEXCEPT : SmallVector()
|
||||
{
|
||||
auto count = size_t(arg_list_end - arg_list_begin);
|
||||
reserve(count);
|
||||
for (size_t i = 0; i < count; i++, arg_list_begin++)
|
||||
new (&this->ptr[i]) T(*arg_list_begin);
|
||||
this->buffer_size = count;
|
||||
}
|
||||
|
||||
SmallVector(SmallVector &&other) SPIRV_CROSS_NOEXCEPT : SmallVector()
|
||||
{
|
||||
*this = std::move(other);
|
||||
}
|
||||
|
||||
SmallVector &operator=(SmallVector &&other) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
clear();
|
||||
if (other.ptr != other.stack_storage.data())
|
||||
{
|
||||
// Pilfer allocated pointer.
|
||||
if (this->ptr != stack_storage.data())
|
||||
free(this->ptr);
|
||||
this->ptr = other.ptr;
|
||||
this->buffer_size = other.buffer_size;
|
||||
buffer_capacity = other.buffer_capacity;
|
||||
other.ptr = nullptr;
|
||||
other.buffer_size = 0;
|
||||
other.buffer_capacity = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Need to move the stack contents individually.
|
||||
reserve(other.buffer_size);
|
||||
for (size_t i = 0; i < other.buffer_size; i++)
|
||||
{
|
||||
new (&this->ptr[i]) T(std::move(other.ptr[i]));
|
||||
other.ptr[i].~T();
|
||||
}
|
||||
this->buffer_size = other.buffer_size;
|
||||
other.buffer_size = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
SmallVector(const SmallVector &other) SPIRV_CROSS_NOEXCEPT : SmallVector()
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
|
||||
SmallVector &operator=(const SmallVector &other) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
clear();
|
||||
reserve(other.buffer_size);
|
||||
for (size_t i = 0; i < other.buffer_size; i++)
|
||||
new (&this->ptr[i]) T(other.ptr[i]);
|
||||
this->buffer_size = other.buffer_size;
|
||||
return *this;
|
||||
}
|
||||
|
||||
explicit SmallVector(size_t count) SPIRV_CROSS_NOEXCEPT : SmallVector()
|
||||
{
|
||||
resize(count);
|
||||
}
|
||||
|
||||
~SmallVector()
|
||||
{
|
||||
clear();
|
||||
if (this->ptr != stack_storage.data())
|
||||
free(this->ptr);
|
||||
}
|
||||
|
||||
void clear() SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
for (size_t i = 0; i < this->buffer_size; i++)
|
||||
this->ptr[i].~T();
|
||||
this->buffer_size = 0;
|
||||
}
|
||||
|
||||
void push_back(const T &t) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
reserve(this->buffer_size + 1);
|
||||
new (&this->ptr[this->buffer_size]) T(t);
|
||||
this->buffer_size++;
|
||||
}
|
||||
|
||||
void push_back(T &&t) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
reserve(this->buffer_size + 1);
|
||||
new (&this->ptr[this->buffer_size]) T(std::move(t));
|
||||
this->buffer_size++;
|
||||
}
|
||||
|
||||
void pop_back() SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
// Work around false positive warning on GCC 8.3.
|
||||
// Calling pop_back on empty vector is undefined.
|
||||
if (!this->empty())
|
||||
resize(this->buffer_size - 1);
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
void emplace_back(Ts &&... ts) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
reserve(this->buffer_size + 1);
|
||||
new (&this->ptr[this->buffer_size]) T(std::forward<Ts>(ts)...);
|
||||
this->buffer_size++;
|
||||
}
|
||||
|
||||
void reserve(size_t count) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
if ((count > std::numeric_limits<size_t>::max() / sizeof(T)) ||
|
||||
(count > std::numeric_limits<size_t>::max() / 2))
|
||||
{
|
||||
// Only way this should ever happen is with garbage input, terminate.
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
if (count > buffer_capacity)
|
||||
{
|
||||
size_t target_capacity = buffer_capacity;
|
||||
if (target_capacity == 0)
|
||||
target_capacity = 1;
|
||||
if (target_capacity < N)
|
||||
target_capacity = N;
|
||||
|
||||
// Need to ensure there is a POT value of target capacity which is larger than count,
|
||||
// otherwise this will overflow.
|
||||
while (target_capacity < count)
|
||||
target_capacity <<= 1u;
|
||||
|
||||
T *new_buffer =
|
||||
target_capacity > N ? static_cast<T *>(malloc(target_capacity * sizeof(T))) : stack_storage.data();
|
||||
|
||||
// If we actually fail this malloc, we are hosed anyways, there is no reason to attempt recovery.
|
||||
if (!new_buffer)
|
||||
std::terminate();
|
||||
|
||||
// In case for some reason two allocations both come from same stack.
|
||||
if (new_buffer != this->ptr)
|
||||
{
|
||||
// We don't deal with types which can throw in move constructor.
|
||||
for (size_t i = 0; i < this->buffer_size; i++)
|
||||
{
|
||||
new (&new_buffer[i]) T(std::move(this->ptr[i]));
|
||||
this->ptr[i].~T();
|
||||
}
|
||||
}
|
||||
|
||||
if (this->ptr != stack_storage.data())
|
||||
free(this->ptr);
|
||||
this->ptr = new_buffer;
|
||||
buffer_capacity = target_capacity;
|
||||
}
|
||||
}
|
||||
|
||||
void insert(T *itr, const T *insert_begin, const T *insert_end) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
auto count = size_t(insert_end - insert_begin);
|
||||
if (itr == this->end())
|
||||
{
|
||||
reserve(this->buffer_size + count);
|
||||
for (size_t i = 0; i < count; i++, insert_begin++)
|
||||
new (&this->ptr[this->buffer_size + i]) T(*insert_begin);
|
||||
this->buffer_size += count;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this->buffer_size + count > buffer_capacity)
|
||||
{
|
||||
auto target_capacity = this->buffer_size + count;
|
||||
if (target_capacity == 0)
|
||||
target_capacity = 1;
|
||||
if (target_capacity < N)
|
||||
target_capacity = N;
|
||||
|
||||
while (target_capacity < count)
|
||||
target_capacity <<= 1u;
|
||||
|
||||
// Need to allocate new buffer. Move everything to a new buffer.
|
||||
T *new_buffer =
|
||||
target_capacity > N ? static_cast<T *>(malloc(target_capacity * sizeof(T))) : stack_storage.data();
|
||||
|
||||
// If we actually fail this malloc, we are hosed anyways, there is no reason to attempt recovery.
|
||||
if (!new_buffer)
|
||||
std::terminate();
|
||||
|
||||
// First, move elements from source buffer to new buffer.
|
||||
// We don't deal with types which can throw in move constructor.
|
||||
auto *target_itr = new_buffer;
|
||||
auto *original_source_itr = this->begin();
|
||||
|
||||
if (new_buffer != this->ptr)
|
||||
{
|
||||
while (original_source_itr != itr)
|
||||
{
|
||||
new (target_itr) T(std::move(*original_source_itr));
|
||||
original_source_itr->~T();
|
||||
++original_source_itr;
|
||||
++target_itr;
|
||||
}
|
||||
}
|
||||
|
||||
// Copy-construct new elements.
|
||||
for (auto *source_itr = insert_begin; source_itr != insert_end; ++source_itr, ++target_itr)
|
||||
new (target_itr) T(*source_itr);
|
||||
|
||||
// Move over the other half.
|
||||
if (new_buffer != this->ptr || insert_begin != insert_end)
|
||||
{
|
||||
while (original_source_itr != this->end())
|
||||
{
|
||||
new (target_itr) T(std::move(*original_source_itr));
|
||||
original_source_itr->~T();
|
||||
++original_source_itr;
|
||||
++target_itr;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->ptr != stack_storage.data())
|
||||
free(this->ptr);
|
||||
this->ptr = new_buffer;
|
||||
buffer_capacity = target_capacity;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Move in place, need to be a bit careful about which elements are constructed and which are not.
|
||||
// Move the end and construct the new elements.
|
||||
auto *target_itr = this->end() + count;
|
||||
auto *source_itr = this->end();
|
||||
while (target_itr != this->end() && source_itr != itr)
|
||||
{
|
||||
--target_itr;
|
||||
--source_itr;
|
||||
new (target_itr) T(std::move(*source_itr));
|
||||
}
|
||||
|
||||
// For already constructed elements we can move-assign.
|
||||
std::move_backward(itr, source_itr, target_itr);
|
||||
|
||||
// For the inserts which go to already constructed elements, we can do a plain copy.
|
||||
while (itr != this->end() && insert_begin != insert_end)
|
||||
*itr++ = *insert_begin++;
|
||||
|
||||
// For inserts into newly allocated memory, we must copy-construct instead.
|
||||
while (insert_begin != insert_end)
|
||||
{
|
||||
new (itr) T(*insert_begin);
|
||||
++itr;
|
||||
++insert_begin;
|
||||
}
|
||||
}
|
||||
|
||||
this->buffer_size += count;
|
||||
}
|
||||
}
|
||||
|
||||
void insert(T *itr, const T &value) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
insert(itr, &value, &value + 1);
|
||||
}
|
||||
|
||||
T *erase(T *itr) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
std::move(itr + 1, this->end(), itr);
|
||||
this->ptr[--this->buffer_size].~T();
|
||||
return itr;
|
||||
}
|
||||
|
||||
void erase(T *start_erase, T *end_erase) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
if (end_erase == this->end())
|
||||
{
|
||||
resize(size_t(start_erase - this->begin()));
|
||||
}
|
||||
else
|
||||
{
|
||||
auto new_size = this->buffer_size - (end_erase - start_erase);
|
||||
std::move(end_erase, this->end(), start_erase);
|
||||
resize(new_size);
|
||||
}
|
||||
}
|
||||
|
||||
void resize(size_t new_size) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
if (new_size < this->buffer_size)
|
||||
{
|
||||
for (size_t i = new_size; i < this->buffer_size; i++)
|
||||
this->ptr[i].~T();
|
||||
}
|
||||
else if (new_size > this->buffer_size)
|
||||
{
|
||||
reserve(new_size);
|
||||
for (size_t i = this->buffer_size; i < new_size; i++)
|
||||
new (&this->ptr[i]) T();
|
||||
}
|
||||
|
||||
this->buffer_size = new_size;
|
||||
}
|
||||
|
||||
private:
|
||||
size_t buffer_capacity = 0;
|
||||
AlignedBuffer<T, N> stack_storage;
|
||||
};
|
||||
|
||||
// A vector without stack storage.
|
||||
// Could also be a typedef-ed to std::vector,
|
||||
// but might as well use the one we have.
|
||||
template <typename T>
|
||||
using Vector = SmallVector<T, 0>;
|
||||
|
||||
#else // SPIRV_CROSS_FORCE_STL_TYPES
|
||||
|
||||
template <typename T, size_t N = 8>
|
||||
using SmallVector = std::vector<T>;
|
||||
template <typename T>
|
||||
using Vector = std::vector<T>;
|
||||
template <typename T>
|
||||
using VectorView = std::vector<T>;
|
||||
|
||||
#endif // SPIRV_CROSS_FORCE_STL_TYPES
|
||||
|
||||
// An object pool which we use for allocating IVariant-derived objects.
|
||||
// We know we are going to allocate a bunch of objects of each type,
|
||||
// so amortize the mallocs.
|
||||
class ObjectPoolBase
|
||||
{
|
||||
public:
|
||||
virtual ~ObjectPoolBase() = default;
|
||||
virtual void free_opaque(void *ptr) = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class ObjectPool : public ObjectPoolBase
|
||||
{
|
||||
public:
|
||||
explicit ObjectPool(unsigned start_object_count_ = 16)
|
||||
: start_object_count(start_object_count_)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename... P>
|
||||
T *allocate(P &&... p)
|
||||
{
|
||||
if (vacants.empty())
|
||||
{
|
||||
unsigned num_objects = start_object_count << memory.size();
|
||||
T *ptr = static_cast<T *>(malloc(num_objects * sizeof(T)));
|
||||
if (!ptr)
|
||||
return nullptr;
|
||||
|
||||
for (unsigned i = 0; i < num_objects; i++)
|
||||
vacants.push_back(&ptr[i]);
|
||||
|
||||
memory.emplace_back(ptr);
|
||||
}
|
||||
|
||||
T *ptr = vacants.back();
|
||||
vacants.pop_back();
|
||||
new (ptr) T(std::forward<P>(p)...);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void free(T *ptr)
|
||||
{
|
||||
ptr->~T();
|
||||
vacants.push_back(ptr);
|
||||
}
|
||||
|
||||
void free_opaque(void *ptr) override
|
||||
{
|
||||
free(static_cast<T *>(ptr));
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
vacants.clear();
|
||||
memory.clear();
|
||||
}
|
||||
|
||||
protected:
|
||||
Vector<T *> vacants;
|
||||
|
||||
struct MallocDeleter
|
||||
{
|
||||
void operator()(T *ptr)
|
||||
{
|
||||
::free(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
SmallVector<std::unique_ptr<T, MallocDeleter>> memory;
|
||||
unsigned start_object_count;
|
||||
};
|
||||
|
||||
template <size_t StackSize = 4096, size_t BlockSize = 4096>
|
||||
class StringStream
|
||||
{
|
||||
public:
|
||||
StringStream()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
~StringStream()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
// Disable copies and moves. Makes it easier to implement, and we don't need it.
|
||||
StringStream(const StringStream &) = delete;
|
||||
void operator=(const StringStream &) = delete;
|
||||
|
||||
template <typename T, typename std::enable_if<!std::is_floating_point<T>::value, int>::type = 0>
|
||||
StringStream &operator<<(const T &t)
|
||||
{
|
||||
auto s = std::to_string(t);
|
||||
append(s.data(), s.size());
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Only overload this to make float/double conversions ambiguous.
|
||||
StringStream &operator<<(uint32_t v)
|
||||
{
|
||||
auto s = std::to_string(v);
|
||||
append(s.data(), s.size());
|
||||
return *this;
|
||||
}
|
||||
|
||||
StringStream &operator<<(char c)
|
||||
{
|
||||
append(&c, 1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
StringStream &operator<<(const std::string &s)
|
||||
{
|
||||
append(s.data(), s.size());
|
||||
return *this;
|
||||
}
|
||||
|
||||
StringStream &operator<<(const char *s)
|
||||
{
|
||||
append(s, strlen(s));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
StringStream &operator<<(const char (&s)[N])
|
||||
{
|
||||
append(s, strlen(s));
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string str() const
|
||||
{
|
||||
std::string ret;
|
||||
size_t target_size = 0;
|
||||
for (auto &saved : saved_buffers)
|
||||
target_size += saved.offset;
|
||||
target_size += current_buffer.offset;
|
||||
ret.reserve(target_size);
|
||||
|
||||
for (auto &saved : saved_buffers)
|
||||
ret.insert(ret.end(), saved.buffer, saved.buffer + saved.offset);
|
||||
ret.insert(ret.end(), current_buffer.buffer, current_buffer.buffer + current_buffer.offset);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
for (auto &saved : saved_buffers)
|
||||
if (saved.buffer != stack_buffer)
|
||||
free(saved.buffer);
|
||||
if (current_buffer.buffer != stack_buffer)
|
||||
free(current_buffer.buffer);
|
||||
|
||||
saved_buffers.clear();
|
||||
current_buffer.buffer = stack_buffer;
|
||||
current_buffer.offset = 0;
|
||||
current_buffer.size = sizeof(stack_buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
struct Buffer
|
||||
{
|
||||
char *buffer = nullptr;
|
||||
size_t offset = 0;
|
||||
size_t size = 0;
|
||||
};
|
||||
Buffer current_buffer;
|
||||
char stack_buffer[StackSize];
|
||||
SmallVector<Buffer> saved_buffers;
|
||||
|
||||
void append(const char *s, size_t len)
|
||||
{
|
||||
size_t avail = current_buffer.size - current_buffer.offset;
|
||||
if (avail < len)
|
||||
{
|
||||
if (avail > 0)
|
||||
{
|
||||
memcpy(current_buffer.buffer + current_buffer.offset, s, avail);
|
||||
s += avail;
|
||||
len -= avail;
|
||||
current_buffer.offset += avail;
|
||||
}
|
||||
|
||||
saved_buffers.push_back(current_buffer);
|
||||
size_t target_size = len > BlockSize ? len : BlockSize;
|
||||
current_buffer.buffer = static_cast<char *>(malloc(target_size));
|
||||
if (!current_buffer.buffer)
|
||||
SPIRV_CROSS_THROW("Out of memory.");
|
||||
|
||||
memcpy(current_buffer.buffer, s, len);
|
||||
current_buffer.offset = len;
|
||||
current_buffer.size = target_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(current_buffer.buffer + current_buffer.offset, s, len);
|
||||
current_buffer.offset += len;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright 2015-2020 Arm Limited
|
||||
*
|
||||
* 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 SPIRV_CROSS_ERROR_HANDLING
|
||||
#define SPIRV_CROSS_ERROR_HANDLING
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#ifndef SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS
|
||||
#include <stdexcept>
|
||||
#endif
|
||||
|
||||
#ifdef SPIRV_CROSS_NAMESPACE_OVERRIDE
|
||||
#define SPIRV_CROSS_NAMESPACE SPIRV_CROSS_NAMESPACE_OVERRIDE
|
||||
#else
|
||||
#define SPIRV_CROSS_NAMESPACE spirv_cross
|
||||
#endif
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
#ifdef SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS
|
||||
#if !defined(_MSC_VER) || defined(__clang__)
|
||||
[[noreturn]]
|
||||
#elif defined(_MSC_VER)
|
||||
__declspec(noreturn)
|
||||
#endif
|
||||
inline void
|
||||
report_and_abort(const std::string &msg)
|
||||
{
|
||||
#ifdef NDEBUG
|
||||
(void)msg;
|
||||
#else
|
||||
fprintf(stderr, "There was a compiler error: %s\n", msg.c_str());
|
||||
#endif
|
||||
fflush(stderr);
|
||||
abort();
|
||||
}
|
||||
|
||||
#define SPIRV_CROSS_THROW(x) report_and_abort(x)
|
||||
#else
|
||||
class CompilerError : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
explicit CompilerError(const std::string &str)
|
||||
: std::runtime_error(str)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#define SPIRV_CROSS_THROW(x) throw CompilerError(x)
|
||||
#endif
|
||||
|
||||
// MSVC 2013 does not have noexcept. We need this for Variant to get move constructor to work correctly
|
||||
// instead of copy constructor.
|
||||
// MSVC 2013 ignores that move constructors cannot throw in std::vector, so just don't define it.
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#define SPIRV_CROSS_NOEXCEPT
|
||||
#else
|
||||
#define SPIRV_CROSS_NOEXCEPT noexcept
|
||||
#endif
|
||||
|
||||
#if __cplusplus >= 201402l
|
||||
#define SPIRV_CROSS_DEPRECATED(reason) [[deprecated(reason)]]
|
||||
#elif defined(__GNUC__)
|
||||
#define SPIRV_CROSS_DEPRECATED(reason) __attribute__((deprecated))
|
||||
#elif defined(_MSC_VER)
|
||||
#define SPIRV_CROSS_DEPRECATED(reason) __declspec(deprecated(reason))
|
||||
#else
|
||||
#define SPIRV_CROSS_DEPRECATED(reason)
|
||||
#endif
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
* Copyright 2018-2020 Arm Limited
|
||||
*
|
||||
* 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 SPIRV_CROSS_PARSED_IR_HPP
|
||||
#define SPIRV_CROSS_PARSED_IR_HPP
|
||||
|
||||
#include "spirv_common.hpp"
|
||||
#include <stdint.h>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
|
||||
// This data structure holds all information needed to perform cross-compilation and reflection.
|
||||
// It is the output of the Parser, but any implementation could create this structure.
|
||||
// It is intentionally very "open" and struct-like with some helper functions to deal with decorations.
|
||||
// Parser is the reference implementation of how this data structure should be filled in.
|
||||
|
||||
class ParsedIR
|
||||
{
|
||||
private:
|
||||
// This must be destroyed after the "ids" vector.
|
||||
std::unique_ptr<ObjectPoolGroup> pool_group;
|
||||
|
||||
public:
|
||||
ParsedIR();
|
||||
|
||||
// Due to custom allocations from object pools, we cannot use a default copy constructor.
|
||||
ParsedIR(const ParsedIR &other);
|
||||
ParsedIR &operator=(const ParsedIR &other);
|
||||
|
||||
// Moves are unproblematic, but we need to implement it anyways, since MSVC 2013 does not understand
|
||||
// how to default-implement these.
|
||||
ParsedIR(ParsedIR &&other) SPIRV_CROSS_NOEXCEPT;
|
||||
ParsedIR &operator=(ParsedIR &&other) SPIRV_CROSS_NOEXCEPT;
|
||||
|
||||
// Resizes ids, meta and block_meta.
|
||||
void set_id_bounds(uint32_t bounds);
|
||||
|
||||
// The raw SPIR-V, instructions and opcodes refer to this by offset + count.
|
||||
std::vector<uint32_t> spirv;
|
||||
|
||||
// Holds various data structures which inherit from IVariant.
|
||||
SmallVector<Variant> ids;
|
||||
|
||||
// Various meta data for IDs, decorations, names, etc.
|
||||
std::unordered_map<ID, Meta> meta;
|
||||
|
||||
// Holds all IDs which have a certain type.
|
||||
// This is needed so we can iterate through a specific kind of resource quickly,
|
||||
// and in-order of module declaration.
|
||||
SmallVector<ID> ids_for_type[TypeCount];
|
||||
|
||||
// Special purpose lists which contain a union of types.
|
||||
// This is needed so we can declare specialization constants and structs in an interleaved fashion,
|
||||
// among other things.
|
||||
// Constants can be of struct type, and struct array sizes can use specialization constants.
|
||||
SmallVector<ID> ids_for_constant_or_type;
|
||||
SmallVector<ID> ids_for_constant_or_variable;
|
||||
|
||||
// Declared capabilities and extensions in the SPIR-V module.
|
||||
// Not really used except for reflection at the moment.
|
||||
SmallVector<spv::Capability> declared_capabilities;
|
||||
SmallVector<std::string> declared_extensions;
|
||||
|
||||
// Meta data about blocks. The cross-compiler needs to query if a block is either of these types.
|
||||
// It is a bitset as there can be more than one tag per block.
|
||||
enum BlockMetaFlagBits
|
||||
{
|
||||
BLOCK_META_LOOP_HEADER_BIT = 1 << 0,
|
||||
BLOCK_META_CONTINUE_BIT = 1 << 1,
|
||||
BLOCK_META_LOOP_MERGE_BIT = 1 << 2,
|
||||
BLOCK_META_SELECTION_MERGE_BIT = 1 << 3,
|
||||
BLOCK_META_MULTISELECT_MERGE_BIT = 1 << 4
|
||||
};
|
||||
using BlockMetaFlags = uint8_t;
|
||||
SmallVector<BlockMetaFlags> block_meta;
|
||||
std::unordered_map<BlockID, BlockID> continue_block_to_loop_header;
|
||||
|
||||
// Normally, we'd stick SPIREntryPoint in ids array, but it conflicts with SPIRFunction.
|
||||
// Entry points can therefore be seen as some sort of meta structure.
|
||||
std::unordered_map<FunctionID, SPIREntryPoint> entry_points;
|
||||
FunctionID default_entry_point = 0;
|
||||
|
||||
struct Source
|
||||
{
|
||||
uint32_t version = 0;
|
||||
bool es = false;
|
||||
bool known = false;
|
||||
bool hlsl = false;
|
||||
|
||||
Source() = default;
|
||||
};
|
||||
|
||||
Source source;
|
||||
|
||||
spv::AddressingModel addressing_model = spv::AddressingModelMax;
|
||||
spv::MemoryModel memory_model = spv::MemoryModelMax;
|
||||
|
||||
// Decoration handling methods.
|
||||
// Can be useful for simple "raw" reflection.
|
||||
// However, most members are here because the Parser needs most of these,
|
||||
// and might as well just have the whole suite of decoration/name handling in one place.
|
||||
void set_name(ID id, const std::string &name);
|
||||
const std::string &get_name(ID id) const;
|
||||
void set_decoration(ID id, spv::Decoration decoration, uint32_t argument = 0);
|
||||
void set_decoration_string(ID id, spv::Decoration decoration, const std::string &argument);
|
||||
bool has_decoration(ID id, spv::Decoration decoration) const;
|
||||
uint32_t get_decoration(ID id, spv::Decoration decoration) const;
|
||||
const std::string &get_decoration_string(ID id, spv::Decoration decoration) const;
|
||||
const Bitset &get_decoration_bitset(ID id) const;
|
||||
void unset_decoration(ID id, spv::Decoration decoration);
|
||||
|
||||
// Decoration handling methods (for members of a struct).
|
||||
void set_member_name(TypeID id, uint32_t index, const std::string &name);
|
||||
const std::string &get_member_name(TypeID id, uint32_t index) const;
|
||||
void set_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration, uint32_t argument = 0);
|
||||
void set_member_decoration_string(TypeID id, uint32_t index, spv::Decoration decoration,
|
||||
const std::string &argument);
|
||||
uint32_t get_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration) const;
|
||||
const std::string &get_member_decoration_string(TypeID id, uint32_t index, spv::Decoration decoration) const;
|
||||
bool has_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration) const;
|
||||
const Bitset &get_member_decoration_bitset(TypeID id, uint32_t index) const;
|
||||
void unset_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration);
|
||||
|
||||
void mark_used_as_array_length(ID id);
|
||||
uint32_t increase_bound_by(uint32_t count);
|
||||
Bitset get_buffer_block_flags(const SPIRVariable &var) const;
|
||||
|
||||
void add_typed_id(Types type, ID id);
|
||||
void remove_typed_id(Types type, ID id);
|
||||
|
||||
class LoopLock
|
||||
{
|
||||
public:
|
||||
explicit LoopLock(uint32_t *counter);
|
||||
LoopLock(const LoopLock &) = delete;
|
||||
void operator=(const LoopLock &) = delete;
|
||||
LoopLock(LoopLock &&other) SPIRV_CROSS_NOEXCEPT;
|
||||
LoopLock &operator=(LoopLock &&other) SPIRV_CROSS_NOEXCEPT;
|
||||
~LoopLock();
|
||||
|
||||
private:
|
||||
uint32_t *lock;
|
||||
};
|
||||
|
||||
// This must be held while iterating over a type ID array.
|
||||
// It is undefined if someone calls set<>() while we're iterating over a data structure, so we must
|
||||
// make sure that this case is avoided.
|
||||
|
||||
// If we have a hard lock, it is an error to call set<>(), and an exception is thrown.
|
||||
// If we have a soft lock, we silently ignore any additions to the typed arrays.
|
||||
// This should only be used for physical ID remapping where we need to create an ID, but we will never
|
||||
// care about iterating over them.
|
||||
LoopLock create_loop_hard_lock() const;
|
||||
LoopLock create_loop_soft_lock() const;
|
||||
|
||||
template <typename T, typename Op>
|
||||
void for_each_typed_id(const Op &op)
|
||||
{
|
||||
auto loop_lock = create_loop_hard_lock();
|
||||
for (auto &id : ids_for_type[T::type])
|
||||
{
|
||||
if (ids[id].get_type() == static_cast<Types>(T::type))
|
||||
op(id, get<T>(id));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename Op>
|
||||
void for_each_typed_id(const Op &op) const
|
||||
{
|
||||
auto loop_lock = create_loop_hard_lock();
|
||||
for (auto &id : ids_for_type[T::type])
|
||||
{
|
||||
if (ids[id].get_type() == static_cast<Types>(T::type))
|
||||
op(id, get<T>(id));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void reset_all_of_type()
|
||||
{
|
||||
reset_all_of_type(static_cast<Types>(T::type));
|
||||
}
|
||||
|
||||
void reset_all_of_type(Types type);
|
||||
|
||||
Meta *find_meta(ID id);
|
||||
const Meta *find_meta(ID id) const;
|
||||
|
||||
const std::string &get_empty_string() const
|
||||
{
|
||||
return empty_string;
|
||||
}
|
||||
|
||||
void make_constant_null(uint32_t id, uint32_t type, bool add_to_typed_id_set);
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
T &get(uint32_t id)
|
||||
{
|
||||
return variant_get<T>(ids[id]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T &get(uint32_t id) const
|
||||
{
|
||||
return variant_get<T>(ids[id]);
|
||||
}
|
||||
|
||||
mutable uint32_t loop_iteration_depth_hard = 0;
|
||||
mutable uint32_t loop_iteration_depth_soft = 0;
|
||||
std::string empty_string;
|
||||
Bitset cleared_bitset;
|
||||
};
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright 2015-2020 Arm Limited
|
||||
*
|
||||
* 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 SPIRV_CROSS_UTIL_HPP
|
||||
#define SPIRV_CROSS_UTIL_HPP
|
||||
|
||||
#include "spirv_cross.hpp"
|
||||
|
||||
namespace spirv_cross_util
|
||||
{
|
||||
void rename_interface_variable(SPIRV_CROSS_NAMESPACE::Compiler &compiler,
|
||||
const SPIRV_CROSS_NAMESPACE::SmallVector<SPIRV_CROSS_NAMESPACE::Resource> &resources,
|
||||
uint32_t location, const std::string &name);
|
||||
void inherit_combined_sampler_bindings(SPIRV_CROSS_NAMESPACE::Compiler &compiler);
|
||||
} // namespace spirv_cross_util
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,760 @@
|
|||
/*
|
||||
* Copyright 2015-2020 Arm Limited
|
||||
*
|
||||
* 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 SPIRV_CROSS_GLSL_HPP
|
||||
#define SPIRV_CROSS_GLSL_HPP
|
||||
|
||||
#include "GLSL.std.450.h"
|
||||
#include "spirv_cross.hpp"
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
enum PlsFormat
|
||||
{
|
||||
PlsNone = 0,
|
||||
|
||||
PlsR11FG11FB10F,
|
||||
PlsR32F,
|
||||
PlsRG16F,
|
||||
PlsRGB10A2,
|
||||
PlsRGBA8,
|
||||
PlsRG16,
|
||||
|
||||
PlsRGBA8I,
|
||||
PlsRG16I,
|
||||
|
||||
PlsRGB10A2UI,
|
||||
PlsRGBA8UI,
|
||||
PlsRG16UI,
|
||||
PlsR32UI
|
||||
};
|
||||
|
||||
struct PlsRemap
|
||||
{
|
||||
uint32_t id;
|
||||
PlsFormat format;
|
||||
};
|
||||
|
||||
enum AccessChainFlagBits
|
||||
{
|
||||
ACCESS_CHAIN_INDEX_IS_LITERAL_BIT = 1 << 0,
|
||||
ACCESS_CHAIN_CHAIN_ONLY_BIT = 1 << 1,
|
||||
ACCESS_CHAIN_PTR_CHAIN_BIT = 1 << 2,
|
||||
ACCESS_CHAIN_SKIP_REGISTER_EXPRESSION_READ_BIT = 1 << 3,
|
||||
ACCESS_CHAIN_LITERAL_MSB_FORCE_ID = 1 << 4
|
||||
};
|
||||
typedef uint32_t AccessChainFlags;
|
||||
|
||||
class CompilerGLSL : public Compiler
|
||||
{
|
||||
public:
|
||||
struct Options
|
||||
{
|
||||
// The shading language version. Corresponds to #version $VALUE.
|
||||
uint32_t version = 450;
|
||||
|
||||
// Emit the OpenGL ES shading language instead of desktop OpenGL.
|
||||
bool es = false;
|
||||
|
||||
// Debug option to always emit temporary variables for all expressions.
|
||||
bool force_temporary = false;
|
||||
|
||||
// If true, Vulkan GLSL features are used instead of GL-compatible features.
|
||||
// Mostly useful for debugging SPIR-V files.
|
||||
bool vulkan_semantics = false;
|
||||
|
||||
// If true, gl_PerVertex is explicitly redeclared in vertex, geometry and tessellation shaders.
|
||||
// The members of gl_PerVertex is determined by which built-ins are declared by the shader.
|
||||
// This option is ignored in ES versions, as redeclaration in ES is not required, and it depends on a different extension
|
||||
// (EXT_shader_io_blocks) which makes things a bit more fuzzy.
|
||||
bool separate_shader_objects = false;
|
||||
|
||||
// Flattens multidimensional arrays, e.g. float foo[a][b][c] into single-dimensional arrays,
|
||||
// e.g. float foo[a * b * c].
|
||||
// This function does not change the actual SPIRType of any object.
|
||||
// Only the generated code, including declarations of interface variables are changed to be single array dimension.
|
||||
bool flatten_multidimensional_arrays = false;
|
||||
|
||||
// For older desktop GLSL targets than version 420, the
|
||||
// GL_ARB_shading_language_420pack extensions is used to be able to support
|
||||
// layout(binding) on UBOs and samplers.
|
||||
// If disabled on older targets, binding decorations will be stripped.
|
||||
bool enable_420pack_extension = true;
|
||||
|
||||
// In non-Vulkan GLSL, emit push constant blocks as UBOs rather than plain uniforms.
|
||||
bool emit_push_constant_as_uniform_buffer = false;
|
||||
|
||||
// Always emit uniform blocks as plain uniforms, regardless of the GLSL version, even when UBOs are supported.
|
||||
// Does not apply to shader storage or push constant blocks.
|
||||
bool emit_uniform_buffer_as_plain_uniforms = false;
|
||||
|
||||
// Emit OpLine directives if present in the module.
|
||||
// May not correspond exactly to original source, but should be a good approximation.
|
||||
bool emit_line_directives = false;
|
||||
|
||||
// In cases where readonly/writeonly decoration are not used at all,
|
||||
// we try to deduce which qualifier(s) we should actually used, since actually emitting
|
||||
// read-write decoration is very rare, and older glslang/HLSL compilers tend to just emit readwrite as a matter of fact.
|
||||
// The default (true) is to enable automatic deduction for these cases, but if you trust the decorations set
|
||||
// by the SPIR-V, it's recommended to set this to false.
|
||||
bool enable_storage_image_qualifier_deduction = true;
|
||||
|
||||
// On some targets (WebGPU), uninitialized variables are banned.
|
||||
// If this is enabled, all variables (temporaries, Private, Function)
|
||||
// which would otherwise be uninitialized will now be initialized to 0 instead.
|
||||
bool force_zero_initialized_variables = false;
|
||||
|
||||
enum Precision
|
||||
{
|
||||
DontCare,
|
||||
Lowp,
|
||||
Mediump,
|
||||
Highp
|
||||
};
|
||||
|
||||
struct
|
||||
{
|
||||
// GLSL: In vertex shaders, rewrite [0, w] depth (Vulkan/D3D style) to [-w, w] depth (GL style).
|
||||
// MSL: In vertex shaders, rewrite [-w, w] depth (GL style) to [0, w] depth.
|
||||
// HLSL: In vertex shaders, rewrite [-w, w] depth (GL style) to [0, w] depth.
|
||||
bool fixup_clipspace = false;
|
||||
|
||||
// Inverts gl_Position.y or equivalent.
|
||||
bool flip_vert_y = false;
|
||||
|
||||
// GLSL only, for HLSL version of this option, see CompilerHLSL.
|
||||
// If true, the backend will assume that InstanceIndex will need to apply
|
||||
// a base instance offset. Set to false if you know you will never use base instance
|
||||
// functionality as it might remove some internal uniforms.
|
||||
bool support_nonzero_base_instance = true;
|
||||
} vertex;
|
||||
|
||||
struct
|
||||
{
|
||||
// Add precision mediump float in ES targets when emitting GLES source.
|
||||
// Add precision highp int in ES targets when emitting GLES source.
|
||||
Precision default_float_precision = Mediump;
|
||||
Precision default_int_precision = Highp;
|
||||
} fragment;
|
||||
};
|
||||
|
||||
void remap_pixel_local_storage(std::vector<PlsRemap> inputs, std::vector<PlsRemap> outputs)
|
||||
{
|
||||
pls_inputs = std::move(inputs);
|
||||
pls_outputs = std::move(outputs);
|
||||
remap_pls_variables();
|
||||
}
|
||||
|
||||
// Redirect a subpassInput reading from input_attachment_index to instead load its value from
|
||||
// the color attachment at location = color_location. Requires ESSL.
|
||||
void remap_ext_framebuffer_fetch(uint32_t input_attachment_index, uint32_t color_location);
|
||||
|
||||
explicit CompilerGLSL(std::vector<uint32_t> spirv_)
|
||||
: Compiler(std::move(spirv_))
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
CompilerGLSL(const uint32_t *ir_, size_t word_count)
|
||||
: Compiler(ir_, word_count)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
explicit CompilerGLSL(const ParsedIR &ir_)
|
||||
: Compiler(ir_)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
explicit CompilerGLSL(ParsedIR &&ir_)
|
||||
: Compiler(std::move(ir_))
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
const Options &get_common_options() const
|
||||
{
|
||||
return options;
|
||||
}
|
||||
|
||||
void set_common_options(const Options &opts)
|
||||
{
|
||||
options = opts;
|
||||
}
|
||||
|
||||
std::string compile() override;
|
||||
|
||||
// Returns the current string held in the conversion buffer. Useful for
|
||||
// capturing what has been converted so far when compile() throws an error.
|
||||
std::string get_partial_source();
|
||||
|
||||
// Adds a line to be added right after #version in GLSL backend.
|
||||
// This is useful for enabling custom extensions which are outside the scope of SPIRV-Cross.
|
||||
// This can be combined with variable remapping.
|
||||
// A new-line will be added.
|
||||
//
|
||||
// While add_header_line() is a more generic way of adding arbitrary text to the header
|
||||
// of a GLSL file, require_extension() should be used when adding extensions since it will
|
||||
// avoid creating collisions with SPIRV-Cross generated extensions.
|
||||
//
|
||||
// Code added via add_header_line() is typically backend-specific.
|
||||
void add_header_line(const std::string &str);
|
||||
|
||||
// Adds an extension which is required to run this shader, e.g.
|
||||
// require_extension("GL_KHR_my_extension");
|
||||
void require_extension(const std::string &ext);
|
||||
|
||||
// Legacy GLSL compatibility method.
|
||||
// Takes a uniform or push constant variable and flattens it into a (i|u)vec4 array[N]; array instead.
|
||||
// For this to work, all types in the block must be the same basic type, e.g. mixing vec2 and vec4 is fine, but
|
||||
// mixing int and float is not.
|
||||
// The name of the uniform array will be the same as the interface block name.
|
||||
void flatten_buffer_block(VariableID id);
|
||||
|
||||
// After compilation, query if a variable ID was used as a depth resource.
|
||||
// This is meaningful for MSL since descriptor types depend on this knowledge.
|
||||
// Cases which return true:
|
||||
// - Images which are declared with depth = 1 image type.
|
||||
// - Samplers which are statically used at least once with Dref opcodes.
|
||||
// - Images which are statically used at least once with Dref opcodes.
|
||||
bool variable_is_depth_or_compare(VariableID id) const;
|
||||
|
||||
protected:
|
||||
void reset();
|
||||
void emit_function(SPIRFunction &func, const Bitset &return_flags);
|
||||
|
||||
bool has_extension(const std::string &ext) const;
|
||||
void require_extension_internal(const std::string &ext);
|
||||
|
||||
// Virtualize methods which need to be overridden by subclass targets like C++ and such.
|
||||
virtual void emit_function_prototype(SPIRFunction &func, const Bitset &return_flags);
|
||||
|
||||
SPIRBlock *current_emitting_block = nullptr;
|
||||
SPIRBlock *current_emitting_switch = nullptr;
|
||||
bool current_emitting_switch_fallthrough = false;
|
||||
|
||||
virtual void emit_instruction(const Instruction &instr);
|
||||
void emit_block_instructions(SPIRBlock &block);
|
||||
virtual void emit_glsl_op(uint32_t result_type, uint32_t result_id, uint32_t op, const uint32_t *args,
|
||||
uint32_t count);
|
||||
virtual void emit_spv_amd_shader_ballot_op(uint32_t result_type, uint32_t result_id, uint32_t op,
|
||||
const uint32_t *args, uint32_t count);
|
||||
virtual void emit_spv_amd_shader_explicit_vertex_parameter_op(uint32_t result_type, uint32_t result_id, uint32_t op,
|
||||
const uint32_t *args, uint32_t count);
|
||||
virtual void emit_spv_amd_shader_trinary_minmax_op(uint32_t result_type, uint32_t result_id, uint32_t op,
|
||||
const uint32_t *args, uint32_t count);
|
||||
virtual void emit_spv_amd_gcn_shader_op(uint32_t result_type, uint32_t result_id, uint32_t op, const uint32_t *args,
|
||||
uint32_t count);
|
||||
virtual void emit_header();
|
||||
void emit_line_directive(uint32_t file_id, uint32_t line_literal);
|
||||
void build_workgroup_size(SmallVector<std::string> &arguments, const SpecializationConstant &x,
|
||||
const SpecializationConstant &y, const SpecializationConstant &z);
|
||||
|
||||
virtual void emit_sampled_image_op(uint32_t result_type, uint32_t result_id, uint32_t image_id, uint32_t samp_id);
|
||||
virtual void emit_texture_op(const Instruction &i);
|
||||
virtual std::string to_texture_op(const Instruction &i, bool *forward,
|
||||
SmallVector<uint32_t> &inherited_expressions);
|
||||
virtual void emit_subgroup_op(const Instruction &i);
|
||||
virtual std::string type_to_glsl(const SPIRType &type, uint32_t id = 0);
|
||||
virtual std::string builtin_to_glsl(spv::BuiltIn builtin, spv::StorageClass storage);
|
||||
virtual void emit_struct_member(const SPIRType &type, uint32_t member_type_id, uint32_t index,
|
||||
const std::string &qualifier = "", uint32_t base_offset = 0);
|
||||
virtual void emit_struct_padding_target(const SPIRType &type);
|
||||
virtual std::string image_type_glsl(const SPIRType &type, uint32_t id = 0);
|
||||
std::string constant_expression(const SPIRConstant &c);
|
||||
std::string constant_op_expression(const SPIRConstantOp &cop);
|
||||
virtual std::string constant_expression_vector(const SPIRConstant &c, uint32_t vector);
|
||||
virtual void emit_fixup();
|
||||
virtual std::string variable_decl(const SPIRType &type, const std::string &name, uint32_t id = 0);
|
||||
virtual std::string to_func_call_arg(const SPIRFunction::Parameter &arg, uint32_t id);
|
||||
virtual std::string to_function_name(VariableID img, const SPIRType &imgtype, bool is_fetch, bool is_gather,
|
||||
bool is_proj, bool has_array_offsets, bool has_offset, bool has_grad,
|
||||
bool has_dref, uint32_t lod, uint32_t minlod);
|
||||
virtual std::string to_function_args(VariableID img, const SPIRType &imgtype, bool is_fetch, bool is_gather,
|
||||
bool is_proj, uint32_t coord, uint32_t coord_components, uint32_t dref,
|
||||
uint32_t grad_x, uint32_t grad_y, uint32_t lod, uint32_t coffset,
|
||||
uint32_t offset, uint32_t bias, uint32_t comp, uint32_t sample,
|
||||
uint32_t minlod, bool *p_forward);
|
||||
virtual void emit_buffer_block(const SPIRVariable &type);
|
||||
virtual void emit_push_constant_block(const SPIRVariable &var);
|
||||
virtual void emit_uniform(const SPIRVariable &var);
|
||||
virtual std::string unpack_expression_type(std::string expr_str, const SPIRType &type, uint32_t physical_type_id,
|
||||
bool packed_type, bool row_major);
|
||||
|
||||
virtual bool builtin_translates_to_nonarray(spv::BuiltIn builtin) const;
|
||||
|
||||
void emit_copy_logical_type(uint32_t lhs_id, uint32_t lhs_type_id, uint32_t rhs_id, uint32_t rhs_type_id,
|
||||
SmallVector<uint32_t> chain);
|
||||
|
||||
StringStream<> buffer;
|
||||
|
||||
template <typename T>
|
||||
inline void statement_inner(T &&t)
|
||||
{
|
||||
buffer << std::forward<T>(t);
|
||||
statement_count++;
|
||||
}
|
||||
|
||||
template <typename T, typename... Ts>
|
||||
inline void statement_inner(T &&t, Ts &&... ts)
|
||||
{
|
||||
buffer << std::forward<T>(t);
|
||||
statement_count++;
|
||||
statement_inner(std::forward<Ts>(ts)...);
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
inline void statement(Ts &&... ts)
|
||||
{
|
||||
if (is_forcing_recompilation())
|
||||
{
|
||||
// Do not bother emitting code while force_recompile is active.
|
||||
// We will compile again.
|
||||
statement_count++;
|
||||
return;
|
||||
}
|
||||
|
||||
if (redirect_statement)
|
||||
{
|
||||
redirect_statement->push_back(join(std::forward<Ts>(ts)...));
|
||||
statement_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (uint32_t i = 0; i < indent; i++)
|
||||
buffer << " ";
|
||||
statement_inner(std::forward<Ts>(ts)...);
|
||||
buffer << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
inline void statement_no_indent(Ts &&... ts)
|
||||
{
|
||||
auto old_indent = indent;
|
||||
indent = 0;
|
||||
statement(std::forward<Ts>(ts)...);
|
||||
indent = old_indent;
|
||||
}
|
||||
|
||||
// Used for implementing continue blocks where
|
||||
// we want to obtain a list of statements we can merge
|
||||
// on a single line separated by comma.
|
||||
SmallVector<std::string> *redirect_statement = nullptr;
|
||||
const SPIRBlock *current_continue_block = nullptr;
|
||||
|
||||
void begin_scope();
|
||||
void end_scope();
|
||||
void end_scope(const std::string &trailer);
|
||||
void end_scope_decl();
|
||||
void end_scope_decl(const std::string &decl);
|
||||
|
||||
Options options;
|
||||
|
||||
virtual std::string type_to_array_glsl(
|
||||
const SPIRType &type); // Allow Metal to use the array<T> template to make arrays a value type
|
||||
std::string to_array_size(const SPIRType &type, uint32_t index);
|
||||
uint32_t to_array_size_literal(const SPIRType &type, uint32_t index) const;
|
||||
uint32_t to_array_size_literal(const SPIRType &type) const;
|
||||
virtual std::string variable_decl(const SPIRVariable &variable); // Threadgroup arrays can't have a wrapper type
|
||||
std::string variable_decl_function_local(SPIRVariable &variable);
|
||||
|
||||
void add_local_variable_name(uint32_t id);
|
||||
void add_resource_name(uint32_t id);
|
||||
void add_member_name(SPIRType &type, uint32_t name);
|
||||
void add_function_overload(const SPIRFunction &func);
|
||||
|
||||
virtual bool is_non_native_row_major_matrix(uint32_t id);
|
||||
virtual bool member_is_non_native_row_major_matrix(const SPIRType &type, uint32_t index);
|
||||
bool member_is_remapped_physical_type(const SPIRType &type, uint32_t index) const;
|
||||
bool member_is_packed_physical_type(const SPIRType &type, uint32_t index) const;
|
||||
virtual std::string convert_row_major_matrix(std::string exp_str, const SPIRType &exp_type,
|
||||
uint32_t physical_type_id, bool is_packed);
|
||||
|
||||
std::unordered_set<std::string> local_variable_names;
|
||||
std::unordered_set<std::string> resource_names;
|
||||
std::unordered_set<std::string> block_input_names;
|
||||
std::unordered_set<std::string> block_output_names;
|
||||
std::unordered_set<std::string> block_ubo_names;
|
||||
std::unordered_set<std::string> block_ssbo_names;
|
||||
std::unordered_set<std::string> block_names; // A union of all block_*_names.
|
||||
std::unordered_map<std::string, std::unordered_set<uint64_t>> function_overloads;
|
||||
std::unordered_map<uint32_t, std::string> preserved_aliases;
|
||||
void preserve_alias_on_reset(uint32_t id);
|
||||
void reset_name_caches();
|
||||
|
||||
bool processing_entry_point = false;
|
||||
|
||||
// Can be overriden by subclass backends for trivial things which
|
||||
// shouldn't need polymorphism.
|
||||
struct BackendVariations
|
||||
{
|
||||
std::string discard_literal = "discard";
|
||||
std::string demote_literal = "demote";
|
||||
std::string null_pointer_literal = "";
|
||||
bool float_literal_suffix = false;
|
||||
bool double_literal_suffix = true;
|
||||
bool uint32_t_literal_suffix = true;
|
||||
bool long_long_literal_suffix = false;
|
||||
const char *basic_int_type = "int";
|
||||
const char *basic_uint_type = "uint";
|
||||
const char *basic_int8_type = "int8_t";
|
||||
const char *basic_uint8_type = "uint8_t";
|
||||
const char *basic_int16_type = "int16_t";
|
||||
const char *basic_uint16_type = "uint16_t";
|
||||
const char *int16_t_literal_suffix = "s";
|
||||
const char *uint16_t_literal_suffix = "us";
|
||||
const char *nonuniform_qualifier = "nonuniformEXT";
|
||||
const char *boolean_mix_function = "mix";
|
||||
bool swizzle_is_function = false;
|
||||
bool shared_is_implied = false;
|
||||
bool unsized_array_supported = true;
|
||||
bool explicit_struct_type = false;
|
||||
bool use_initializer_list = false;
|
||||
bool use_typed_initializer_list = false;
|
||||
bool can_declare_struct_inline = true;
|
||||
bool can_declare_arrays_inline = true;
|
||||
bool native_row_major_matrix = true;
|
||||
bool use_constructor_splatting = true;
|
||||
bool allow_precision_qualifiers = false;
|
||||
bool can_swizzle_scalar = false;
|
||||
bool force_gl_in_out_block = false;
|
||||
bool can_return_array = true;
|
||||
bool allow_truncated_access_chain = false;
|
||||
bool supports_extensions = false;
|
||||
bool supports_empty_struct = false;
|
||||
bool array_is_value_type = true;
|
||||
bool comparison_image_samples_scalar = false;
|
||||
bool native_pointers = false;
|
||||
bool support_small_type_sampling_result = false;
|
||||
bool support_case_fallthrough = true;
|
||||
bool use_array_constructor = false;
|
||||
} backend;
|
||||
|
||||
void emit_struct(SPIRType &type);
|
||||
void emit_resources();
|
||||
void emit_buffer_block_native(const SPIRVariable &var);
|
||||
void emit_buffer_reference_block(SPIRType &type, bool forward_declaration);
|
||||
void emit_buffer_block_legacy(const SPIRVariable &var);
|
||||
void emit_buffer_block_flattened(const SPIRVariable &type);
|
||||
void emit_declared_builtin_block(spv::StorageClass storage, spv::ExecutionModel model);
|
||||
bool should_force_emit_builtin_block(spv::StorageClass storage);
|
||||
void emit_push_constant_block_vulkan(const SPIRVariable &var);
|
||||
void emit_push_constant_block_glsl(const SPIRVariable &var);
|
||||
void emit_interface_block(const SPIRVariable &type);
|
||||
void emit_flattened_io_block(const SPIRVariable &var, const char *qual);
|
||||
void emit_block_chain(SPIRBlock &block);
|
||||
void emit_hoisted_temporaries(SmallVector<std::pair<TypeID, ID>> &temporaries);
|
||||
std::string constant_value_macro_name(uint32_t id);
|
||||
void emit_constant(const SPIRConstant &constant);
|
||||
void emit_specialization_constant_op(const SPIRConstantOp &constant);
|
||||
std::string emit_continue_block(uint32_t continue_block, bool follow_true_block, bool follow_false_block);
|
||||
bool attempt_emit_loop_header(SPIRBlock &block, SPIRBlock::Method method);
|
||||
|
||||
void branch(BlockID from, BlockID to);
|
||||
void branch_to_continue(BlockID from, BlockID to);
|
||||
void branch(BlockID from, uint32_t cond, BlockID true_block, BlockID false_block);
|
||||
void flush_phi(BlockID from, BlockID to);
|
||||
void flush_variable_declaration(uint32_t id);
|
||||
void flush_undeclared_variables(SPIRBlock &block);
|
||||
void emit_variable_temporary_copies(const SPIRVariable &var);
|
||||
|
||||
bool should_dereference(uint32_t id);
|
||||
bool should_forward(uint32_t id) const;
|
||||
bool should_suppress_usage_tracking(uint32_t id) const;
|
||||
void emit_mix_op(uint32_t result_type, uint32_t id, uint32_t left, uint32_t right, uint32_t lerp);
|
||||
void emit_nminmax_op(uint32_t result_type, uint32_t id, uint32_t op0, uint32_t op1, GLSLstd450 op);
|
||||
bool to_trivial_mix_op(const SPIRType &type, std::string &op, uint32_t left, uint32_t right, uint32_t lerp);
|
||||
void emit_quaternary_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, uint32_t op2,
|
||||
uint32_t op3, const char *op);
|
||||
void emit_trinary_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, uint32_t op2,
|
||||
const char *op);
|
||||
void emit_binary_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op);
|
||||
|
||||
void emit_unary_func_op_cast(uint32_t result_type, uint32_t result_id, uint32_t op0, const char *op,
|
||||
SPIRType::BaseType input_type, SPIRType::BaseType expected_result_type);
|
||||
void emit_binary_func_op_cast(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op,
|
||||
SPIRType::BaseType input_type, bool skip_cast_if_equal_type);
|
||||
void emit_binary_func_op_cast_clustered(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1,
|
||||
const char *op, SPIRType::BaseType input_type);
|
||||
void emit_trinary_func_op_cast(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, uint32_t op2,
|
||||
const char *op, SPIRType::BaseType input_type);
|
||||
void emit_trinary_func_op_bitextract(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1,
|
||||
uint32_t op2, const char *op, SPIRType::BaseType expected_result_type,
|
||||
SPIRType::BaseType input_type0, SPIRType::BaseType input_type1,
|
||||
SPIRType::BaseType input_type2);
|
||||
void emit_bitfield_insert_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, uint32_t op2,
|
||||
uint32_t op3, const char *op, SPIRType::BaseType offset_count_type);
|
||||
|
||||
void emit_unary_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, const char *op);
|
||||
void emit_unrolled_unary_op(uint32_t result_type, uint32_t result_id, uint32_t operand, const char *op);
|
||||
void emit_binary_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op);
|
||||
void emit_unrolled_binary_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op,
|
||||
bool negate, SPIRType::BaseType expected_type);
|
||||
void emit_binary_op_cast(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op,
|
||||
SPIRType::BaseType input_type, bool skip_cast_if_equal_type);
|
||||
|
||||
SPIRType binary_op_bitcast_helper(std::string &cast_op0, std::string &cast_op1, SPIRType::BaseType &input_type,
|
||||
uint32_t op0, uint32_t op1, bool skip_cast_if_equal_type);
|
||||
|
||||
virtual bool emit_complex_bitcast(uint32_t result_type, uint32_t id, uint32_t op0);
|
||||
|
||||
std::string to_ternary_expression(const SPIRType &result_type, uint32_t select, uint32_t true_value,
|
||||
uint32_t false_value);
|
||||
|
||||
void emit_unary_op(uint32_t result_type, uint32_t result_id, uint32_t op0, const char *op);
|
||||
bool expression_is_forwarded(uint32_t id) const;
|
||||
bool expression_suppresses_usage_tracking(uint32_t id) const;
|
||||
SPIRExpression &emit_op(uint32_t result_type, uint32_t result_id, const std::string &rhs, bool forward_rhs,
|
||||
bool suppress_usage_tracking = false);
|
||||
|
||||
void access_chain_internal_append_index(std::string &expr, uint32_t base, const SPIRType *type,
|
||||
AccessChainFlags flags, bool &access_chain_is_arrayed, uint32_t index);
|
||||
|
||||
std::string access_chain_internal(uint32_t base, const uint32_t *indices, uint32_t count, AccessChainFlags flags,
|
||||
AccessChainMeta *meta);
|
||||
|
||||
std::string access_chain(uint32_t base, const uint32_t *indices, uint32_t count, const SPIRType &target_type,
|
||||
AccessChainMeta *meta = nullptr, bool ptr_chain = false);
|
||||
|
||||
std::string flattened_access_chain(uint32_t base, const uint32_t *indices, uint32_t count,
|
||||
const SPIRType &target_type, uint32_t offset, uint32_t matrix_stride,
|
||||
uint32_t array_stride, bool need_transpose);
|
||||
std::string flattened_access_chain_struct(uint32_t base, const uint32_t *indices, uint32_t count,
|
||||
const SPIRType &target_type, uint32_t offset);
|
||||
std::string flattened_access_chain_matrix(uint32_t base, const uint32_t *indices, uint32_t count,
|
||||
const SPIRType &target_type, uint32_t offset, uint32_t matrix_stride,
|
||||
bool need_transpose);
|
||||
std::string flattened_access_chain_vector(uint32_t base, const uint32_t *indices, uint32_t count,
|
||||
const SPIRType &target_type, uint32_t offset, uint32_t matrix_stride,
|
||||
bool need_transpose);
|
||||
std::pair<std::string, uint32_t> flattened_access_chain_offset(const SPIRType &basetype, const uint32_t *indices,
|
||||
uint32_t count, uint32_t offset,
|
||||
uint32_t word_stride, bool *need_transpose = nullptr,
|
||||
uint32_t *matrix_stride = nullptr,
|
||||
uint32_t *array_stride = nullptr,
|
||||
bool ptr_chain = false);
|
||||
|
||||
const char *index_to_swizzle(uint32_t index);
|
||||
std::string remap_swizzle(const SPIRType &result_type, uint32_t input_components, const std::string &expr);
|
||||
std::string declare_temporary(uint32_t type, uint32_t id);
|
||||
void emit_uninitialized_temporary(uint32_t type, uint32_t id);
|
||||
SPIRExpression &emit_uninitialized_temporary_expression(uint32_t type, uint32_t id);
|
||||
void append_global_func_args(const SPIRFunction &func, uint32_t index, SmallVector<std::string> &arglist);
|
||||
std::string to_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_composite_constructor_expression(uint32_t id);
|
||||
std::string to_rerolled_array_expression(const std::string &expr, const SPIRType &type);
|
||||
std::string to_enclosed_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_unpacked_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_unpacked_row_major_matrix_expression(uint32_t id);
|
||||
std::string to_enclosed_unpacked_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_dereferenced_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_pointer_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_enclosed_pointer_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_extract_component_expression(uint32_t id, uint32_t index);
|
||||
std::string enclose_expression(const std::string &expr);
|
||||
std::string dereference_expression(const SPIRType &expression_type, const std::string &expr);
|
||||
std::string address_of_expression(const std::string &expr);
|
||||
void strip_enclosed_expression(std::string &expr);
|
||||
std::string to_member_name(const SPIRType &type, uint32_t index);
|
||||
virtual std::string to_member_reference(uint32_t base, const SPIRType &type, uint32_t index, bool ptr_chain);
|
||||
std::string type_to_glsl_constructor(const SPIRType &type);
|
||||
std::string argument_decl(const SPIRFunction::Parameter &arg);
|
||||
virtual std::string to_qualifiers_glsl(uint32_t id);
|
||||
const char *to_precision_qualifiers_glsl(uint32_t id);
|
||||
virtual const char *to_storage_qualifiers_glsl(const SPIRVariable &var);
|
||||
const char *flags_to_qualifiers_glsl(const SPIRType &type, const Bitset &flags);
|
||||
const char *format_to_glsl(spv::ImageFormat format);
|
||||
virtual std::string layout_for_member(const SPIRType &type, uint32_t index);
|
||||
virtual std::string to_interpolation_qualifiers(const Bitset &flags);
|
||||
std::string layout_for_variable(const SPIRVariable &variable);
|
||||
std::string to_combined_image_sampler(VariableID image_id, VariableID samp_id);
|
||||
virtual bool skip_argument(uint32_t id) const;
|
||||
virtual void emit_array_copy(const std::string &lhs, uint32_t rhs_id, spv::StorageClass lhs_storage,
|
||||
spv::StorageClass rhs_storage);
|
||||
virtual void emit_block_hints(const SPIRBlock &block);
|
||||
virtual std::string to_initializer_expression(const SPIRVariable &var);
|
||||
virtual std::string to_zero_initialized_expression(uint32_t type_id);
|
||||
bool type_can_zero_initialize(const SPIRType &type) const;
|
||||
|
||||
bool buffer_is_packing_standard(const SPIRType &type, BufferPackingStandard packing,
|
||||
uint32_t *failed_index = nullptr, uint32_t start_offset = 0,
|
||||
uint32_t end_offset = ~(0u));
|
||||
std::string buffer_to_packing_standard(const SPIRType &type, bool support_std430_without_scalar_layout);
|
||||
|
||||
uint32_t type_to_packed_base_size(const SPIRType &type, BufferPackingStandard packing);
|
||||
uint32_t type_to_packed_alignment(const SPIRType &type, const Bitset &flags, BufferPackingStandard packing);
|
||||
uint32_t type_to_packed_array_stride(const SPIRType &type, const Bitset &flags, BufferPackingStandard packing);
|
||||
uint32_t type_to_packed_size(const SPIRType &type, const Bitset &flags, BufferPackingStandard packing);
|
||||
|
||||
std::string bitcast_glsl(const SPIRType &result_type, uint32_t arg);
|
||||
virtual std::string bitcast_glsl_op(const SPIRType &result_type, const SPIRType &argument_type);
|
||||
|
||||
std::string bitcast_expression(SPIRType::BaseType target_type, uint32_t arg);
|
||||
std::string bitcast_expression(const SPIRType &target_type, SPIRType::BaseType expr_type, const std::string &expr);
|
||||
|
||||
std::string build_composite_combiner(uint32_t result_type, const uint32_t *elems, uint32_t length);
|
||||
bool remove_duplicate_swizzle(std::string &op);
|
||||
bool remove_unity_swizzle(uint32_t base, std::string &op);
|
||||
|
||||
// Can modify flags to remote readonly/writeonly if image type
|
||||
// and force recompile.
|
||||
bool check_atomic_image(uint32_t id);
|
||||
|
||||
virtual void replace_illegal_names();
|
||||
void replace_illegal_names(const std::unordered_set<std::string> &keywords);
|
||||
virtual void emit_entry_point_declarations();
|
||||
|
||||
void replace_fragment_output(SPIRVariable &var);
|
||||
void replace_fragment_outputs();
|
||||
bool check_explicit_lod_allowed(uint32_t lod);
|
||||
std::string legacy_tex_op(const std::string &op, const SPIRType &imgtype, uint32_t lod, uint32_t id);
|
||||
|
||||
uint32_t indent = 0;
|
||||
|
||||
std::unordered_set<uint32_t> emitted_functions;
|
||||
|
||||
// Ensure that we declare phi-variable copies even if the original declaration isn't deferred
|
||||
std::unordered_set<uint32_t> flushed_phi_variables;
|
||||
|
||||
std::unordered_set<uint32_t> flattened_buffer_blocks;
|
||||
std::unordered_set<uint32_t> flattened_structs;
|
||||
|
||||
std::string load_flattened_struct(SPIRVariable &var);
|
||||
std::string to_flattened_struct_member(const SPIRVariable &var, uint32_t index);
|
||||
void store_flattened_struct(SPIRVariable &var, uint32_t value);
|
||||
|
||||
// Usage tracking. If a temporary is used more than once, use the temporary instead to
|
||||
// avoid AST explosion when SPIRV is generated with pure SSA and doesn't write stuff to variables.
|
||||
std::unordered_map<uint32_t, uint32_t> expression_usage_counts;
|
||||
void track_expression_read(uint32_t id);
|
||||
|
||||
SmallVector<std::string> forced_extensions;
|
||||
SmallVector<std::string> header_lines;
|
||||
|
||||
// Used when expressions emit extra opcodes with their own unique IDs,
|
||||
// and we need to reuse the IDs across recompilation loops.
|
||||
// Currently used by NMin/Max/Clamp implementations.
|
||||
std::unordered_map<uint32_t, uint32_t> extra_sub_expressions;
|
||||
|
||||
uint32_t statement_count = 0;
|
||||
|
||||
inline bool is_legacy() const
|
||||
{
|
||||
return (options.es && options.version < 300) || (!options.es && options.version < 130);
|
||||
}
|
||||
|
||||
inline bool is_legacy_es() const
|
||||
{
|
||||
return options.es && options.version < 300;
|
||||
}
|
||||
|
||||
inline bool is_legacy_desktop() const
|
||||
{
|
||||
return !options.es && options.version < 130;
|
||||
}
|
||||
|
||||
bool args_will_forward(uint32_t id, const uint32_t *args, uint32_t num_args, bool pure);
|
||||
void register_call_out_argument(uint32_t id);
|
||||
void register_impure_function_call();
|
||||
void register_control_dependent_expression(uint32_t expr);
|
||||
|
||||
// GL_EXT_shader_pixel_local_storage support.
|
||||
std::vector<PlsRemap> pls_inputs;
|
||||
std::vector<PlsRemap> pls_outputs;
|
||||
std::string pls_decl(const PlsRemap &variable);
|
||||
const char *to_pls_qualifiers_glsl(const SPIRVariable &variable);
|
||||
void emit_pls();
|
||||
void remap_pls_variables();
|
||||
|
||||
// GL_EXT_shader_framebuffer_fetch support.
|
||||
std::vector<std::pair<uint32_t, uint32_t>> subpass_to_framebuffer_fetch_attachment;
|
||||
std::unordered_set<uint32_t> inout_color_attachments;
|
||||
bool subpass_input_is_framebuffer_fetch(uint32_t id) const;
|
||||
void emit_inout_fragment_outputs_copy_to_subpass_inputs();
|
||||
const SPIRVariable *find_subpass_input_by_attachment_index(uint32_t index) const;
|
||||
const SPIRVariable *find_color_output_by_location(uint32_t location) const;
|
||||
|
||||
// A variant which takes two sets of name. The secondary is only used to verify there are no collisions,
|
||||
// but the set is not updated when we have found a new name.
|
||||
// Used primarily when adding block interface names.
|
||||
void add_variable(std::unordered_set<std::string> &variables_primary,
|
||||
const std::unordered_set<std::string> &variables_secondary, std::string &name);
|
||||
|
||||
void check_function_call_constraints(const uint32_t *args, uint32_t length);
|
||||
void handle_invalid_expression(uint32_t id);
|
||||
void find_static_extensions();
|
||||
|
||||
std::string emit_for_loop_initializers(const SPIRBlock &block);
|
||||
void emit_while_loop_initializers(const SPIRBlock &block);
|
||||
bool for_loop_initializers_are_same_type(const SPIRBlock &block);
|
||||
bool optimize_read_modify_write(const SPIRType &type, const std::string &lhs, const std::string &rhs);
|
||||
void fixup_image_load_store_access();
|
||||
|
||||
bool type_is_empty(const SPIRType &type);
|
||||
|
||||
virtual void declare_undefined_values();
|
||||
|
||||
static std::string sanitize_underscores(const std::string &str);
|
||||
|
||||
bool can_use_io_location(spv::StorageClass storage, bool block);
|
||||
const Instruction *get_next_instruction_in_block(const Instruction &instr);
|
||||
static uint32_t mask_relevant_memory_semantics(uint32_t semantics);
|
||||
|
||||
std::string convert_half_to_string(const SPIRConstant &value, uint32_t col, uint32_t row);
|
||||
std::string convert_float_to_string(const SPIRConstant &value, uint32_t col, uint32_t row);
|
||||
std::string convert_double_to_string(const SPIRConstant &value, uint32_t col, uint32_t row);
|
||||
|
||||
std::string convert_separate_image_to_expression(uint32_t id);
|
||||
|
||||
// Builtins in GLSL are always specific signedness, but the SPIR-V can declare them
|
||||
// as either unsigned or signed.
|
||||
// Sometimes we will need to automatically perform bitcasts on load and store to make this work.
|
||||
virtual void bitcast_to_builtin_store(uint32_t target_id, std::string &expr, const SPIRType &expr_type);
|
||||
virtual void bitcast_from_builtin_load(uint32_t source_id, std::string &expr, const SPIRType &expr_type);
|
||||
void unroll_array_from_complex_load(uint32_t target_id, uint32_t source_id, std::string &expr);
|
||||
void convert_non_uniform_expression(const SPIRType &type, std::string &expr);
|
||||
|
||||
void handle_store_to_invariant_variable(uint32_t store_id, uint32_t value_id);
|
||||
void disallow_forwarding_in_expression_chain(const SPIRExpression &expr);
|
||||
|
||||
bool expression_is_constant_null(uint32_t id) const;
|
||||
virtual void emit_store_statement(uint32_t lhs_expression, uint32_t rhs_expression);
|
||||
|
||||
uint32_t get_integer_width_for_instruction(const Instruction &instr) const;
|
||||
uint32_t get_integer_width_for_glsl_instruction(GLSLstd450 op, const uint32_t *arguments, uint32_t length) const;
|
||||
|
||||
bool variable_is_lut(const SPIRVariable &var) const;
|
||||
|
||||
char current_locale_radix_character = '.';
|
||||
|
||||
void fixup_type_alias();
|
||||
void reorder_type_alias();
|
||||
|
||||
void propagate_nonuniform_qualifier(uint32_t id);
|
||||
|
||||
static const char *vector_swizzle(int vecsize, int index);
|
||||
|
||||
private:
|
||||
void init();
|
||||
};
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,329 @@
|
|||
/*
|
||||
* Copyright 2016-2020 Robert Konrad
|
||||
*
|
||||
* 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 SPIRV_HLSL_HPP
|
||||
#define SPIRV_HLSL_HPP
|
||||
|
||||
#include "spirv_glsl.hpp"
|
||||
#include <utility>
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
// Interface which remaps vertex inputs to a fixed semantic name to make linking easier.
|
||||
struct HLSLVertexAttributeRemap
|
||||
{
|
||||
uint32_t location;
|
||||
std::string semantic;
|
||||
};
|
||||
// Specifying a root constant (d3d12) or push constant range (vulkan).
|
||||
//
|
||||
// `start` and `end` denotes the range of the root constant in bytes.
|
||||
// Both values need to be multiple of 4.
|
||||
struct RootConstants
|
||||
{
|
||||
uint32_t start;
|
||||
uint32_t end;
|
||||
|
||||
uint32_t binding;
|
||||
uint32_t space;
|
||||
};
|
||||
|
||||
// For finer control, decorations may be removed from specific resources instead with unset_decoration().
|
||||
enum HLSLBindingFlagBits
|
||||
{
|
||||
HLSL_BINDING_AUTO_NONE_BIT = 0,
|
||||
|
||||
// Push constant (root constant) resources will be declared as CBVs (b-space) without a register() declaration.
|
||||
// A register will be automatically assigned by the D3D compiler, but must therefore be reflected in D3D-land.
|
||||
// Push constants do not normally have a DecorationBinding set, but if they do, this can be used to ignore it.
|
||||
HLSL_BINDING_AUTO_PUSH_CONSTANT_BIT = 1 << 0,
|
||||
|
||||
// cbuffer resources will be declared as CBVs (b-space) without a register() declaration.
|
||||
// A register will be automatically assigned, but must be reflected in D3D-land.
|
||||
HLSL_BINDING_AUTO_CBV_BIT = 1 << 1,
|
||||
|
||||
// All SRVs (t-space) will be declared without a register() declaration.
|
||||
HLSL_BINDING_AUTO_SRV_BIT = 1 << 2,
|
||||
|
||||
// All UAVs (u-space) will be declared without a register() declaration.
|
||||
HLSL_BINDING_AUTO_UAV_BIT = 1 << 3,
|
||||
|
||||
// All samplers (s-space) will be declared without a register() declaration.
|
||||
HLSL_BINDING_AUTO_SAMPLER_BIT = 1 << 4,
|
||||
|
||||
// No resources will be declared with register().
|
||||
HLSL_BINDING_AUTO_ALL = 0x7fffffff
|
||||
};
|
||||
using HLSLBindingFlags = uint32_t;
|
||||
|
||||
// By matching stage, desc_set and binding for a SPIR-V resource,
|
||||
// register bindings are set based on whether the HLSL resource is a
|
||||
// CBV, UAV, SRV or Sampler. A single binding in SPIR-V might contain multiple
|
||||
// resource types, e.g. COMBINED_IMAGE_SAMPLER, and SRV/Sampler bindings will be used respectively.
|
||||
// On SM 5.0 and lower, register_space is ignored.
|
||||
//
|
||||
// To remap a push constant block which does not have any desc_set/binding associated with it,
|
||||
// use ResourceBindingPushConstant{DescriptorSet,Binding} as values for desc_set/binding.
|
||||
// For deeper control of push constants, set_root_constant_layouts() can be used instead.
|
||||
struct HLSLResourceBinding
|
||||
{
|
||||
spv::ExecutionModel stage = spv::ExecutionModelMax;
|
||||
uint32_t desc_set = 0;
|
||||
uint32_t binding = 0;
|
||||
|
||||
struct Binding
|
||||
{
|
||||
uint32_t register_space = 0;
|
||||
uint32_t register_binding = 0;
|
||||
} cbv, uav, srv, sampler;
|
||||
};
|
||||
|
||||
class CompilerHLSL : public CompilerGLSL
|
||||
{
|
||||
public:
|
||||
struct Options
|
||||
{
|
||||
uint32_t shader_model = 30; // TODO: map ps_4_0_level_9_0,... somehow
|
||||
|
||||
// Allows the PointSize builtin, and ignores it, as PointSize is not supported in HLSL.
|
||||
bool point_size_compat = false;
|
||||
|
||||
// Allows the PointCoord builtin, returns float2(0.5, 0.5), as PointCoord is not supported in HLSL.
|
||||
bool point_coord_compat = false;
|
||||
|
||||
// If true, the backend will assume that VertexIndex and InstanceIndex will need to apply
|
||||
// a base offset, and you will need to fill in a cbuffer with offsets.
|
||||
// Set to false if you know you will never use base instance or base vertex
|
||||
// functionality as it might remove an internal cbuffer.
|
||||
bool support_nonzero_base_vertex_base_instance = false;
|
||||
|
||||
// Forces a storage buffer to always be declared as UAV, even if the readonly decoration is used.
|
||||
// By default, a readonly storage buffer will be declared as ByteAddressBuffer (SRV) instead.
|
||||
bool force_storage_buffer_as_uav = false;
|
||||
|
||||
// Forces any storage image type marked as NonWritable to be considered an SRV instead.
|
||||
// For this to work with function call parameters, NonWritable must be considered to be part of the type system
|
||||
// so that NonWritable image arguments are also translated to Texture rather than RWTexture.
|
||||
bool nonwritable_uav_texture_as_srv = false;
|
||||
};
|
||||
|
||||
explicit CompilerHLSL(std::vector<uint32_t> spirv_)
|
||||
: CompilerGLSL(std::move(spirv_))
|
||||
{
|
||||
}
|
||||
|
||||
CompilerHLSL(const uint32_t *ir_, size_t size)
|
||||
: CompilerGLSL(ir_, size)
|
||||
{
|
||||
}
|
||||
|
||||
explicit CompilerHLSL(const ParsedIR &ir_)
|
||||
: CompilerGLSL(ir_)
|
||||
{
|
||||
}
|
||||
|
||||
explicit CompilerHLSL(ParsedIR &&ir_)
|
||||
: CompilerGLSL(std::move(ir_))
|
||||
{
|
||||
}
|
||||
|
||||
const Options &get_hlsl_options() const
|
||||
{
|
||||
return hlsl_options;
|
||||
}
|
||||
|
||||
void set_hlsl_options(const Options &opts)
|
||||
{
|
||||
hlsl_options = opts;
|
||||
}
|
||||
|
||||
// Optionally specify a custom root constant layout.
|
||||
//
|
||||
// Push constants ranges will be split up according to the
|
||||
// layout specified.
|
||||
void set_root_constant_layouts(std::vector<RootConstants> layout);
|
||||
|
||||
// Compiles and remaps vertex attributes at specific locations to a fixed semantic.
|
||||
// The default is TEXCOORD# where # denotes location.
|
||||
// Matrices are unrolled to vectors with notation ${SEMANTIC}_#, where # denotes row.
|
||||
// $SEMANTIC is either TEXCOORD# or a semantic name specified here.
|
||||
void add_vertex_attribute_remap(const HLSLVertexAttributeRemap &vertex_attributes);
|
||||
std::string compile() override;
|
||||
|
||||
// This is a special HLSL workaround for the NumWorkGroups builtin.
|
||||
// This does not exist in HLSL, so the calling application must create a dummy cbuffer in
|
||||
// which the application will store this builtin.
|
||||
// The cbuffer layout will be:
|
||||
// cbuffer SPIRV_Cross_NumWorkgroups : register(b#, space#) { uint3 SPIRV_Cross_NumWorkgroups_count; };
|
||||
// This must be called before compile().
|
||||
// The function returns 0 if NumWorkGroups builtin is not statically used in the shader from the current entry point.
|
||||
// If non-zero, this returns the variable ID of a cbuffer which corresponds to
|
||||
// the cbuffer declared above. By default, no binding or descriptor set decoration is set,
|
||||
// so the calling application should declare explicit bindings on this ID before calling compile().
|
||||
VariableID remap_num_workgroups_builtin();
|
||||
|
||||
// Controls how resource bindings are declared in the output HLSL.
|
||||
void set_resource_binding_flags(HLSLBindingFlags flags);
|
||||
|
||||
// resource is a resource binding to indicate the HLSL CBV, SRV, UAV or sampler binding
|
||||
// to use for a particular SPIR-V description set
|
||||
// and binding. If resource bindings are provided,
|
||||
// is_hlsl_resource_binding_used() will return true after calling ::compile() if
|
||||
// the set/binding combination was used by the HLSL code.
|
||||
void add_hlsl_resource_binding(const HLSLResourceBinding &resource);
|
||||
bool is_hlsl_resource_binding_used(spv::ExecutionModel model, uint32_t set, uint32_t binding) const;
|
||||
|
||||
private:
|
||||
std::string type_to_glsl(const SPIRType &type, uint32_t id = 0) override;
|
||||
std::string image_type_hlsl(const SPIRType &type, uint32_t id);
|
||||
std::string image_type_hlsl_modern(const SPIRType &type, uint32_t id);
|
||||
std::string image_type_hlsl_legacy(const SPIRType &type, uint32_t id);
|
||||
void emit_function_prototype(SPIRFunction &func, const Bitset &return_flags) override;
|
||||
void emit_hlsl_entry_point();
|
||||
void emit_header() override;
|
||||
void emit_resources();
|
||||
void declare_undefined_values() override;
|
||||
void emit_interface_block_globally(const SPIRVariable &type);
|
||||
void emit_interface_block_in_struct(const SPIRVariable &type, std::unordered_set<uint32_t> &active_locations);
|
||||
void emit_builtin_inputs_in_struct();
|
||||
void emit_builtin_outputs_in_struct();
|
||||
void emit_texture_op(const Instruction &i) override;
|
||||
void emit_instruction(const Instruction &instruction) override;
|
||||
void emit_glsl_op(uint32_t result_type, uint32_t result_id, uint32_t op, const uint32_t *args,
|
||||
uint32_t count) override;
|
||||
void emit_buffer_block(const SPIRVariable &type) override;
|
||||
void emit_push_constant_block(const SPIRVariable &var) override;
|
||||
void emit_uniform(const SPIRVariable &var) override;
|
||||
void emit_modern_uniform(const SPIRVariable &var);
|
||||
void emit_legacy_uniform(const SPIRVariable &var);
|
||||
void emit_specialization_constants_and_structs();
|
||||
void emit_composite_constants();
|
||||
void emit_fixup() override;
|
||||
std::string builtin_to_glsl(spv::BuiltIn builtin, spv::StorageClass storage) override;
|
||||
std::string layout_for_member(const SPIRType &type, uint32_t index) override;
|
||||
std::string to_interpolation_qualifiers(const Bitset &flags) override;
|
||||
std::string bitcast_glsl_op(const SPIRType &result_type, const SPIRType &argument_type) override;
|
||||
bool emit_complex_bitcast(uint32_t result_type, uint32_t id, uint32_t op0) override;
|
||||
std::string to_func_call_arg(const SPIRFunction::Parameter &arg, uint32_t id) override;
|
||||
std::string to_sampler_expression(uint32_t id);
|
||||
std::string to_resource_binding(const SPIRVariable &var);
|
||||
std::string to_resource_binding_sampler(const SPIRVariable &var);
|
||||
std::string to_resource_register(HLSLBindingFlagBits flag, char space, uint32_t binding, uint32_t set);
|
||||
void emit_sampled_image_op(uint32_t result_type, uint32_t result_id, uint32_t image_id, uint32_t samp_id) override;
|
||||
void emit_access_chain(const Instruction &instruction);
|
||||
void emit_load(const Instruction &instruction);
|
||||
void read_access_chain(std::string *expr, const std::string &lhs, const SPIRAccessChain &chain);
|
||||
void read_access_chain_struct(const std::string &lhs, const SPIRAccessChain &chain);
|
||||
void read_access_chain_array(const std::string &lhs, const SPIRAccessChain &chain);
|
||||
void write_access_chain(const SPIRAccessChain &chain, uint32_t value, const SmallVector<uint32_t> &composite_chain);
|
||||
void write_access_chain_struct(const SPIRAccessChain &chain, uint32_t value,
|
||||
const SmallVector<uint32_t> &composite_chain);
|
||||
void write_access_chain_array(const SPIRAccessChain &chain, uint32_t value,
|
||||
const SmallVector<uint32_t> &composite_chain);
|
||||
std::string write_access_chain_value(uint32_t value, const SmallVector<uint32_t> &composite_chain, bool enclose);
|
||||
void emit_store(const Instruction &instruction);
|
||||
void emit_atomic(const uint32_t *ops, uint32_t length, spv::Op op);
|
||||
void emit_subgroup_op(const Instruction &i) override;
|
||||
void emit_block_hints(const SPIRBlock &block) override;
|
||||
|
||||
void emit_struct_member(const SPIRType &type, uint32_t member_type_id, uint32_t index, const std::string &qualifier,
|
||||
uint32_t base_offset = 0) override;
|
||||
|
||||
const char *to_storage_qualifiers_glsl(const SPIRVariable &var) override;
|
||||
void replace_illegal_names() override;
|
||||
|
||||
Options hlsl_options;
|
||||
|
||||
// TODO: Refactor this to be more similar to MSL, maybe have some common system in place?
|
||||
bool requires_op_fmod = false;
|
||||
bool requires_fp16_packing = false;
|
||||
bool requires_uint2_packing = false;
|
||||
bool requires_explicit_fp16_packing = false;
|
||||
bool requires_unorm8_packing = false;
|
||||
bool requires_snorm8_packing = false;
|
||||
bool requires_unorm16_packing = false;
|
||||
bool requires_snorm16_packing = false;
|
||||
bool requires_bitfield_insert = false;
|
||||
bool requires_bitfield_extract = false;
|
||||
bool requires_inverse_2x2 = false;
|
||||
bool requires_inverse_3x3 = false;
|
||||
bool requires_inverse_4x4 = false;
|
||||
bool requires_scalar_reflect = false;
|
||||
bool requires_scalar_refract = false;
|
||||
bool requires_scalar_faceforward = false;
|
||||
uint64_t required_textureSizeVariants = 0;
|
||||
void require_texture_query_variant(const SPIRType &type);
|
||||
|
||||
enum TextureQueryVariantDim
|
||||
{
|
||||
Query1D = 0,
|
||||
Query1DArray,
|
||||
Query2D,
|
||||
Query2DArray,
|
||||
Query3D,
|
||||
QueryBuffer,
|
||||
QueryCube,
|
||||
QueryCubeArray,
|
||||
Query2DMS,
|
||||
Query2DMSArray,
|
||||
QueryDimCount
|
||||
};
|
||||
|
||||
enum TextureQueryVariantType
|
||||
{
|
||||
QueryTypeFloat = 0,
|
||||
QueryTypeInt = 16,
|
||||
QueryTypeUInt = 32,
|
||||
QueryTypeCount = 3
|
||||
};
|
||||
|
||||
enum BitcastType
|
||||
{
|
||||
TypeNormal,
|
||||
TypePackUint2x32,
|
||||
TypeUnpackUint64
|
||||
};
|
||||
|
||||
BitcastType get_bitcast_type(uint32_t result_type, uint32_t op0);
|
||||
|
||||
void emit_builtin_variables();
|
||||
bool require_output = false;
|
||||
bool require_input = false;
|
||||
SmallVector<HLSLVertexAttributeRemap> remap_vertex_attributes;
|
||||
|
||||
uint32_t type_to_consumed_locations(const SPIRType &type) const;
|
||||
|
||||
void emit_io_block(const SPIRVariable &var);
|
||||
std::string to_semantic(uint32_t location, spv::ExecutionModel em, spv::StorageClass sc);
|
||||
|
||||
uint32_t num_workgroups_builtin = 0;
|
||||
HLSLBindingFlags resource_binding_flags = 0;
|
||||
|
||||
// Custom root constant layout, which should be emitted
|
||||
// when translating push constant ranges.
|
||||
std::vector<RootConstants> root_constants_layout;
|
||||
|
||||
void validate_shader_model();
|
||||
|
||||
std::string get_unique_identifier();
|
||||
uint32_t unique_identifier_count = 0;
|
||||
|
||||
std::unordered_map<StageSetBinding, std::pair<HLSLResourceBinding, bool>, InternalHasher> resource_bindings;
|
||||
void remap_hlsl_resource_binding(HLSLBindingFlagBits type, uint32_t &desc_set, uint32_t &binding);
|
||||
};
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,962 @@
|
|||
/*
|
||||
* Copyright 2016-2020 The Brenwill Workshop Ltd.
|
||||
*
|
||||
* 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 SPIRV_CROSS_MSL_HPP
|
||||
#define SPIRV_CROSS_MSL_HPP
|
||||
|
||||
#include "spirv_glsl.hpp"
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <stddef.h>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
|
||||
// Indicates the format of the vertex attribute. Currently limited to specifying
|
||||
// if the attribute is an 8-bit unsigned integer, 16-bit unsigned integer, or
|
||||
// some other format.
|
||||
enum MSLVertexFormat
|
||||
{
|
||||
MSL_VERTEX_FORMAT_OTHER = 0,
|
||||
MSL_VERTEX_FORMAT_UINT8 = 1,
|
||||
MSL_VERTEX_FORMAT_UINT16 = 2,
|
||||
MSL_VERTEX_FORMAT_INT_MAX = 0x7fffffff
|
||||
};
|
||||
|
||||
// Defines MSL characteristics of a vertex attribute at a particular location.
|
||||
// After compilation, it is possible to query whether or not this location was used.
|
||||
struct MSLVertexAttr
|
||||
{
|
||||
uint32_t location = 0;
|
||||
uint32_t msl_buffer = 0;
|
||||
uint32_t msl_offset = 0;
|
||||
uint32_t msl_stride = 0;
|
||||
bool per_instance = false;
|
||||
MSLVertexFormat format = MSL_VERTEX_FORMAT_OTHER;
|
||||
spv::BuiltIn builtin = spv::BuiltInMax;
|
||||
};
|
||||
|
||||
// Matches the binding index of a MSL resource for a binding within a descriptor set.
|
||||
// Taken together, the stage, desc_set and binding combine to form a reference to a resource
|
||||
// descriptor used in a particular shading stage.
|
||||
// If using MSL 2.0 argument buffers, the descriptor set is not marked as a discrete descriptor set,
|
||||
// and (for iOS only) the resource is not a storage image (sampled != 2), the binding reference we
|
||||
// remap to will become an [[id(N)]] attribute within the "descriptor set" argument buffer structure.
|
||||
// For resources which are bound in the "classic" MSL 1.0 way or discrete descriptors, the remap will become a
|
||||
// [[buffer(N)]], [[texture(N)]] or [[sampler(N)]] depending on the resource types used.
|
||||
struct MSLResourceBinding
|
||||
{
|
||||
spv::ExecutionModel stage = spv::ExecutionModelMax;
|
||||
uint32_t desc_set = 0;
|
||||
uint32_t binding = 0;
|
||||
uint32_t msl_buffer = 0;
|
||||
uint32_t msl_texture = 0;
|
||||
uint32_t msl_sampler = 0;
|
||||
};
|
||||
|
||||
enum MSLSamplerCoord
|
||||
{
|
||||
MSL_SAMPLER_COORD_NORMALIZED = 0,
|
||||
MSL_SAMPLER_COORD_PIXEL = 1,
|
||||
MSL_SAMPLER_INT_MAX = 0x7fffffff
|
||||
};
|
||||
|
||||
enum MSLSamplerFilter
|
||||
{
|
||||
MSL_SAMPLER_FILTER_NEAREST = 0,
|
||||
MSL_SAMPLER_FILTER_LINEAR = 1,
|
||||
MSL_SAMPLER_FILTER_INT_MAX = 0x7fffffff
|
||||
};
|
||||
|
||||
enum MSLSamplerMipFilter
|
||||
{
|
||||
MSL_SAMPLER_MIP_FILTER_NONE = 0,
|
||||
MSL_SAMPLER_MIP_FILTER_NEAREST = 1,
|
||||
MSL_SAMPLER_MIP_FILTER_LINEAR = 2,
|
||||
MSL_SAMPLER_MIP_FILTER_INT_MAX = 0x7fffffff
|
||||
};
|
||||
|
||||
enum MSLSamplerAddress
|
||||
{
|
||||
MSL_SAMPLER_ADDRESS_CLAMP_TO_ZERO = 0,
|
||||
MSL_SAMPLER_ADDRESS_CLAMP_TO_EDGE = 1,
|
||||
MSL_SAMPLER_ADDRESS_CLAMP_TO_BORDER = 2,
|
||||
MSL_SAMPLER_ADDRESS_REPEAT = 3,
|
||||
MSL_SAMPLER_ADDRESS_MIRRORED_REPEAT = 4,
|
||||
MSL_SAMPLER_ADDRESS_INT_MAX = 0x7fffffff
|
||||
};
|
||||
|
||||
enum MSLSamplerCompareFunc
|
||||
{
|
||||
MSL_SAMPLER_COMPARE_FUNC_NEVER = 0,
|
||||
MSL_SAMPLER_COMPARE_FUNC_LESS = 1,
|
||||
MSL_SAMPLER_COMPARE_FUNC_LESS_EQUAL = 2,
|
||||
MSL_SAMPLER_COMPARE_FUNC_GREATER = 3,
|
||||
MSL_SAMPLER_COMPARE_FUNC_GREATER_EQUAL = 4,
|
||||
MSL_SAMPLER_COMPARE_FUNC_EQUAL = 5,
|
||||
MSL_SAMPLER_COMPARE_FUNC_NOT_EQUAL = 6,
|
||||
MSL_SAMPLER_COMPARE_FUNC_ALWAYS = 7,
|
||||
MSL_SAMPLER_COMPARE_FUNC_INT_MAX = 0x7fffffff
|
||||
};
|
||||
|
||||
enum MSLSamplerBorderColor
|
||||
{
|
||||
MSL_SAMPLER_BORDER_COLOR_TRANSPARENT_BLACK = 0,
|
||||
MSL_SAMPLER_BORDER_COLOR_OPAQUE_BLACK = 1,
|
||||
MSL_SAMPLER_BORDER_COLOR_OPAQUE_WHITE = 2,
|
||||
MSL_SAMPLER_BORDER_COLOR_INT_MAX = 0x7fffffff
|
||||
};
|
||||
|
||||
enum MSLFormatResolution
|
||||
{
|
||||
MSL_FORMAT_RESOLUTION_444 = 0,
|
||||
MSL_FORMAT_RESOLUTION_422,
|
||||
MSL_FORMAT_RESOLUTION_420,
|
||||
MSL_FORMAT_RESOLUTION_INT_MAX = 0x7fffffff
|
||||
};
|
||||
|
||||
enum MSLChromaLocation
|
||||
{
|
||||
MSL_CHROMA_LOCATION_COSITED_EVEN = 0,
|
||||
MSL_CHROMA_LOCATION_MIDPOINT,
|
||||
MSL_CHROMA_LOCATION_INT_MAX = 0x7fffffff
|
||||
};
|
||||
|
||||
enum MSLComponentSwizzle
|
||||
{
|
||||
MSL_COMPONENT_SWIZZLE_IDENTITY = 0,
|
||||
MSL_COMPONENT_SWIZZLE_ZERO,
|
||||
MSL_COMPONENT_SWIZZLE_ONE,
|
||||
MSL_COMPONENT_SWIZZLE_R,
|
||||
MSL_COMPONENT_SWIZZLE_G,
|
||||
MSL_COMPONENT_SWIZZLE_B,
|
||||
MSL_COMPONENT_SWIZZLE_A,
|
||||
MSL_COMPONENT_SWIZZLE_INT_MAX = 0x7fffffff
|
||||
};
|
||||
|
||||
enum MSLSamplerYCbCrModelConversion
|
||||
{
|
||||
MSL_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY = 0,
|
||||
MSL_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_IDENTITY,
|
||||
MSL_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_BT_709,
|
||||
MSL_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_BT_601,
|
||||
MSL_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_BT_2020,
|
||||
MSL_SAMPLER_YCBCR_MODEL_CONVERSION_INT_MAX = 0x7fffffff
|
||||
};
|
||||
|
||||
enum MSLSamplerYCbCrRange
|
||||
{
|
||||
MSL_SAMPLER_YCBCR_RANGE_ITU_FULL = 0,
|
||||
MSL_SAMPLER_YCBCR_RANGE_ITU_NARROW,
|
||||
MSL_SAMPLER_YCBCR_RANGE_INT_MAX = 0x7fffffff
|
||||
};
|
||||
|
||||
struct MSLConstexprSampler
|
||||
{
|
||||
MSLSamplerCoord coord = MSL_SAMPLER_COORD_NORMALIZED;
|
||||
MSLSamplerFilter min_filter = MSL_SAMPLER_FILTER_NEAREST;
|
||||
MSLSamplerFilter mag_filter = MSL_SAMPLER_FILTER_NEAREST;
|
||||
MSLSamplerMipFilter mip_filter = MSL_SAMPLER_MIP_FILTER_NONE;
|
||||
MSLSamplerAddress s_address = MSL_SAMPLER_ADDRESS_CLAMP_TO_EDGE;
|
||||
MSLSamplerAddress t_address = MSL_SAMPLER_ADDRESS_CLAMP_TO_EDGE;
|
||||
MSLSamplerAddress r_address = MSL_SAMPLER_ADDRESS_CLAMP_TO_EDGE;
|
||||
MSLSamplerCompareFunc compare_func = MSL_SAMPLER_COMPARE_FUNC_NEVER;
|
||||
MSLSamplerBorderColor border_color = MSL_SAMPLER_BORDER_COLOR_TRANSPARENT_BLACK;
|
||||
float lod_clamp_min = 0.0f;
|
||||
float lod_clamp_max = 1000.0f;
|
||||
int max_anisotropy = 1;
|
||||
|
||||
// Sampler Y'CbCr conversion parameters
|
||||
uint32_t planes = 0;
|
||||
MSLFormatResolution resolution = MSL_FORMAT_RESOLUTION_444;
|
||||
MSLSamplerFilter chroma_filter = MSL_SAMPLER_FILTER_NEAREST;
|
||||
MSLChromaLocation x_chroma_offset = MSL_CHROMA_LOCATION_COSITED_EVEN;
|
||||
MSLChromaLocation y_chroma_offset = MSL_CHROMA_LOCATION_COSITED_EVEN;
|
||||
MSLComponentSwizzle swizzle[4]; // IDENTITY, IDENTITY, IDENTITY, IDENTITY
|
||||
MSLSamplerYCbCrModelConversion ycbcr_model = MSL_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY;
|
||||
MSLSamplerYCbCrRange ycbcr_range = MSL_SAMPLER_YCBCR_RANGE_ITU_FULL;
|
||||
uint32_t bpc = 8;
|
||||
|
||||
bool compare_enable = false;
|
||||
bool lod_clamp_enable = false;
|
||||
bool anisotropy_enable = false;
|
||||
bool ycbcr_conversion_enable = false;
|
||||
|
||||
MSLConstexprSampler()
|
||||
{
|
||||
for (uint32_t i = 0; i < 4; i++)
|
||||
swizzle[i] = MSL_COMPONENT_SWIZZLE_IDENTITY;
|
||||
}
|
||||
bool swizzle_is_identity() const
|
||||
{
|
||||
return (swizzle[0] == MSL_COMPONENT_SWIZZLE_IDENTITY && swizzle[1] == MSL_COMPONENT_SWIZZLE_IDENTITY &&
|
||||
swizzle[2] == MSL_COMPONENT_SWIZZLE_IDENTITY && swizzle[3] == MSL_COMPONENT_SWIZZLE_IDENTITY);
|
||||
}
|
||||
bool swizzle_has_one_or_zero() const
|
||||
{
|
||||
return (swizzle[0] == MSL_COMPONENT_SWIZZLE_ZERO || swizzle[0] == MSL_COMPONENT_SWIZZLE_ONE ||
|
||||
swizzle[1] == MSL_COMPONENT_SWIZZLE_ZERO || swizzle[1] == MSL_COMPONENT_SWIZZLE_ONE ||
|
||||
swizzle[2] == MSL_COMPONENT_SWIZZLE_ZERO || swizzle[2] == MSL_COMPONENT_SWIZZLE_ONE ||
|
||||
swizzle[3] == MSL_COMPONENT_SWIZZLE_ZERO || swizzle[3] == MSL_COMPONENT_SWIZZLE_ONE);
|
||||
}
|
||||
};
|
||||
|
||||
// Special constant used in a MSLResourceBinding desc_set
|
||||
// element to indicate the bindings for the push constants.
|
||||
// Kinda deprecated. Just use ResourceBindingPushConstant{DescriptorSet,Binding} directly.
|
||||
static const uint32_t kPushConstDescSet = ResourceBindingPushConstantDescriptorSet;
|
||||
|
||||
// Special constant used in a MSLResourceBinding binding
|
||||
// element to indicate the bindings for the push constants.
|
||||
// Kinda deprecated. Just use ResourceBindingPushConstant{DescriptorSet,Binding} directly.
|
||||
static const uint32_t kPushConstBinding = ResourceBindingPushConstantBinding;
|
||||
|
||||
// Special constant used in a MSLResourceBinding binding
|
||||
// element to indicate the buffer binding for swizzle buffers.
|
||||
static const uint32_t kSwizzleBufferBinding = ~(1u);
|
||||
|
||||
// Special constant used in a MSLResourceBinding binding
|
||||
// element to indicate the buffer binding for buffer size buffers to support OpArrayLength.
|
||||
static const uint32_t kBufferSizeBufferBinding = ~(2u);
|
||||
|
||||
// Special constant used in a MSLResourceBinding binding
|
||||
// element to indicate the buffer binding used for the argument buffer itself.
|
||||
// This buffer binding should be kept as small as possible as all automatic bindings for buffers
|
||||
// will start at max(kArgumentBufferBinding) + 1.
|
||||
static const uint32_t kArgumentBufferBinding = ~(3u);
|
||||
|
||||
static const uint32_t kMaxArgumentBuffers = 8;
|
||||
|
||||
// Decompiles SPIR-V to Metal Shading Language
|
||||
class CompilerMSL : public CompilerGLSL
|
||||
{
|
||||
public:
|
||||
// Options for compiling to Metal Shading Language
|
||||
struct Options
|
||||
{
|
||||
typedef enum
|
||||
{
|
||||
iOS = 0,
|
||||
macOS = 1
|
||||
} Platform;
|
||||
|
||||
Platform platform = macOS;
|
||||
uint32_t msl_version = make_msl_version(1, 2);
|
||||
uint32_t texel_buffer_texture_width = 4096; // Width of 2D Metal textures used as 1D texel buffers
|
||||
uint32_t swizzle_buffer_index = 30;
|
||||
uint32_t indirect_params_buffer_index = 29;
|
||||
uint32_t shader_output_buffer_index = 28;
|
||||
uint32_t shader_patch_output_buffer_index = 27;
|
||||
uint32_t shader_tess_factor_buffer_index = 26;
|
||||
uint32_t buffer_size_buffer_index = 25;
|
||||
uint32_t view_mask_buffer_index = 24;
|
||||
uint32_t dynamic_offsets_buffer_index = 23;
|
||||
uint32_t shader_input_wg_index = 0;
|
||||
uint32_t device_index = 0;
|
||||
uint32_t enable_frag_output_mask = 0xffffffff;
|
||||
bool enable_point_size_builtin = true;
|
||||
bool enable_frag_depth_builtin = true;
|
||||
bool enable_frag_stencil_ref_builtin = true;
|
||||
bool disable_rasterization = false;
|
||||
bool capture_output_to_buffer = false;
|
||||
bool swizzle_texture_samples = false;
|
||||
bool tess_domain_origin_lower_left = false;
|
||||
bool multiview = false;
|
||||
bool view_index_from_device_index = false;
|
||||
bool dispatch_base = false;
|
||||
bool texture_1D_as_2D = false;
|
||||
|
||||
// Enable use of MSL 2.0 indirect argument buffers.
|
||||
// MSL 2.0 must also be enabled.
|
||||
bool argument_buffers = false;
|
||||
|
||||
// Ensures vertex and instance indices start at zero. This reflects the behavior of HLSL with SV_VertexID and SV_InstanceID.
|
||||
bool enable_base_index_zero = false;
|
||||
|
||||
// Fragment output in MSL must have at least as many components as the render pass.
|
||||
// Add support to explicit pad out components.
|
||||
bool pad_fragment_output_components = false;
|
||||
|
||||
// Specifies whether the iOS target version supports the [[base_vertex]] and [[base_instance]] attributes.
|
||||
bool ios_support_base_vertex_instance = false;
|
||||
|
||||
// Use Metal's native frame-buffer fetch API for subpass inputs.
|
||||
bool ios_use_framebuffer_fetch_subpasses = false;
|
||||
|
||||
// Enables use of "fma" intrinsic for invariant float math
|
||||
bool invariant_float_math = false;
|
||||
|
||||
// Emulate texturecube_array with texture2d_array for iOS where this type is not available
|
||||
bool emulate_cube_array = false;
|
||||
|
||||
// Allow user to enable decoration binding
|
||||
bool enable_decoration_binding = false;
|
||||
|
||||
// Requires MSL 2.1, use the native support for texel buffers.
|
||||
bool texture_buffer_native = false;
|
||||
|
||||
// Forces all resources which are part of an argument buffer to be considered active.
|
||||
// This ensures ABI compatibility between shaders where some resources might be unused,
|
||||
// and would otherwise declare a different IAB.
|
||||
bool force_active_argument_buffer_resources = false;
|
||||
|
||||
// Forces the use of plain arrays, which works around certain driver bugs on certain versions
|
||||
// of Intel Macbooks. See https://github.com/KhronosGroup/SPIRV-Cross/issues/1210.
|
||||
// May reduce performance in scenarios where arrays are copied around as value-types.
|
||||
bool force_native_arrays = false;
|
||||
|
||||
// If a shader writes clip distance, also emit user varyings which
|
||||
// can be read in subsequent stages.
|
||||
bool enable_clip_distance_user_varying = true;
|
||||
|
||||
bool is_ios() const
|
||||
{
|
||||
return platform == iOS;
|
||||
}
|
||||
|
||||
bool is_macos() const
|
||||
{
|
||||
return platform == macOS;
|
||||
}
|
||||
|
||||
void set_msl_version(uint32_t major, uint32_t minor = 0, uint32_t patch = 0)
|
||||
{
|
||||
msl_version = make_msl_version(major, minor, patch);
|
||||
}
|
||||
|
||||
bool supports_msl_version(uint32_t major, uint32_t minor = 0, uint32_t patch = 0) const
|
||||
{
|
||||
return msl_version >= make_msl_version(major, minor, patch);
|
||||
}
|
||||
|
||||
static uint32_t make_msl_version(uint32_t major, uint32_t minor = 0, uint32_t patch = 0)
|
||||
{
|
||||
return (major * 10000) + (minor * 100) + patch;
|
||||
}
|
||||
};
|
||||
|
||||
const Options &get_msl_options() const
|
||||
{
|
||||
return msl_options;
|
||||
}
|
||||
|
||||
void set_msl_options(const Options &opts)
|
||||
{
|
||||
msl_options = opts;
|
||||
}
|
||||
|
||||
// Provide feedback to calling API to allow runtime to disable pipeline
|
||||
// rasterization if vertex shader requires rasterization to be disabled.
|
||||
bool get_is_rasterization_disabled() const
|
||||
{
|
||||
return is_rasterization_disabled && (get_entry_point().model == spv::ExecutionModelVertex ||
|
||||
get_entry_point().model == spv::ExecutionModelTessellationControl ||
|
||||
get_entry_point().model == spv::ExecutionModelTessellationEvaluation);
|
||||
}
|
||||
|
||||
// Provide feedback to calling API to allow it to pass an auxiliary
|
||||
// swizzle buffer if the shader needs it.
|
||||
bool needs_swizzle_buffer() const
|
||||
{
|
||||
return used_swizzle_buffer;
|
||||
}
|
||||
|
||||
// Provide feedback to calling API to allow it to pass a buffer
|
||||
// containing STORAGE_BUFFER buffer sizes to support OpArrayLength.
|
||||
bool needs_buffer_size_buffer() const
|
||||
{
|
||||
return !buffers_requiring_array_length.empty();
|
||||
}
|
||||
|
||||
// Provide feedback to calling API to allow it to pass a buffer
|
||||
// containing the view mask for the current multiview subpass.
|
||||
bool needs_view_mask_buffer() const
|
||||
{
|
||||
return msl_options.multiview && !msl_options.view_index_from_device_index;
|
||||
}
|
||||
|
||||
// Provide feedback to calling API to allow it to pass a buffer
|
||||
// containing the dispatch base workgroup ID.
|
||||
bool needs_dispatch_base_buffer() const
|
||||
{
|
||||
return msl_options.dispatch_base && !msl_options.supports_msl_version(1, 2);
|
||||
}
|
||||
|
||||
// Provide feedback to calling API to allow it to pass an output
|
||||
// buffer if the shader needs it.
|
||||
bool needs_output_buffer() const
|
||||
{
|
||||
return capture_output_to_buffer && stage_out_var_id != ID(0);
|
||||
}
|
||||
|
||||
// Provide feedback to calling API to allow it to pass a patch output
|
||||
// buffer if the shader needs it.
|
||||
bool needs_patch_output_buffer() const
|
||||
{
|
||||
return capture_output_to_buffer && patch_stage_out_var_id != ID(0);
|
||||
}
|
||||
|
||||
// Provide feedback to calling API to allow it to pass an input threadgroup
|
||||
// buffer if the shader needs it.
|
||||
bool needs_input_threadgroup_mem() const
|
||||
{
|
||||
return capture_output_to_buffer && stage_in_var_id != ID(0);
|
||||
}
|
||||
|
||||
explicit CompilerMSL(std::vector<uint32_t> spirv);
|
||||
CompilerMSL(const uint32_t *ir, size_t word_count);
|
||||
explicit CompilerMSL(const ParsedIR &ir);
|
||||
explicit CompilerMSL(ParsedIR &&ir);
|
||||
|
||||
// attr is a vertex attribute binding used to match
|
||||
// vertex content locations to MSL attributes. If vertex attributes are provided,
|
||||
// is_msl_vertex_attribute_used() will return true after calling ::compile() if
|
||||
// the location was used by the MSL code.
|
||||
void add_msl_vertex_attribute(const MSLVertexAttr &attr);
|
||||
|
||||
// resource is a resource binding to indicate the MSL buffer,
|
||||
// texture or sampler index to use for a particular SPIR-V description set
|
||||
// and binding. If resource bindings are provided,
|
||||
// is_msl_resource_binding_used() will return true after calling ::compile() if
|
||||
// the set/binding combination was used by the MSL code.
|
||||
void add_msl_resource_binding(const MSLResourceBinding &resource);
|
||||
|
||||
// desc_set and binding are the SPIR-V descriptor set and binding of a buffer resource
|
||||
// in this shader. index is the index within the dynamic offset buffer to use. This
|
||||
// function marks that resource as using a dynamic offset (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
|
||||
// or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC). This function only has any effect if argument buffers
|
||||
// are enabled. If so, the buffer will have its address adjusted at the beginning of the shader with
|
||||
// an offset taken from the dynamic offset buffer.
|
||||
void add_dynamic_buffer(uint32_t desc_set, uint32_t binding, uint32_t index);
|
||||
|
||||
// desc_set and binding are the SPIR-V descriptor set and binding of a buffer resource
|
||||
// in this shader. This function marks that resource as an inline uniform block
|
||||
// (VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT). This function only has any effect if argument buffers
|
||||
// are enabled. If so, the buffer block will be directly embedded into the argument
|
||||
// buffer, instead of being referenced indirectly via pointer.
|
||||
void add_inline_uniform_block(uint32_t desc_set, uint32_t binding);
|
||||
|
||||
// When using MSL argument buffers, we can force "classic" MSL 1.0 binding schemes for certain descriptor sets.
|
||||
// This corresponds to VK_KHR_push_descriptor in Vulkan.
|
||||
void add_discrete_descriptor_set(uint32_t desc_set);
|
||||
|
||||
// If an argument buffer is large enough, it may need to be in the device storage space rather than
|
||||
// constant. Opt-in to this behavior here on a per set basis.
|
||||
void set_argument_buffer_device_address_space(uint32_t desc_set, bool device_storage);
|
||||
|
||||
// Query after compilation is done. This allows you to check if a location or set/binding combination was used by the shader.
|
||||
bool is_msl_vertex_attribute_used(uint32_t location);
|
||||
|
||||
// NOTE: Only resources which are remapped using add_msl_resource_binding will be reported here.
|
||||
// Constexpr samplers are always assumed to be emitted.
|
||||
// No specific MSLResourceBinding remapping is required for constexpr samplers as long as they are remapped
|
||||
// by remap_constexpr_sampler(_by_binding).
|
||||
bool is_msl_resource_binding_used(spv::ExecutionModel model, uint32_t set, uint32_t binding) const;
|
||||
|
||||
// This must only be called after a successful call to CompilerMSL::compile().
|
||||
// For a variable resource ID obtained through reflection API, report the automatically assigned resource index.
|
||||
// If the descriptor set was part of an argument buffer, report the [[id(N)]],
|
||||
// or [[buffer/texture/sampler]] binding for other resources.
|
||||
// If the resource was a combined image sampler, report the image binding here,
|
||||
// use the _secondary version of this call to query the sampler half of the resource.
|
||||
// If no binding exists, uint32_t(-1) is returned.
|
||||
uint32_t get_automatic_msl_resource_binding(uint32_t id) const;
|
||||
|
||||
// Same as get_automatic_msl_resource_binding, but should only be used for combined image samplers, in which case the
|
||||
// sampler's binding is returned instead. For any other resource type, -1 is returned.
|
||||
uint32_t get_automatic_msl_resource_binding_secondary(uint32_t id) const;
|
||||
|
||||
// Same as get_automatic_msl_resource_binding, but should only be used for combined image samplers for multiplanar images,
|
||||
// in which case the second plane's binding is returned instead. For any other resource type, -1 is returned.
|
||||
uint32_t get_automatic_msl_resource_binding_tertiary(uint32_t id) const;
|
||||
|
||||
// Same as get_automatic_msl_resource_binding, but should only be used for combined image samplers for triplanar images,
|
||||
// in which case the third plane's binding is returned instead. For any other resource type, -1 is returned.
|
||||
uint32_t get_automatic_msl_resource_binding_quaternary(uint32_t id) const;
|
||||
|
||||
// Compiles the SPIR-V code into Metal Shading Language.
|
||||
std::string compile() override;
|
||||
|
||||
// Remap a sampler with ID to a constexpr sampler.
|
||||
// Older iOS targets must use constexpr samplers in certain cases (PCF),
|
||||
// so a static sampler must be used.
|
||||
// The sampler will not consume a binding, but be declared in the entry point as a constexpr sampler.
|
||||
// This can be used on both combined image/samplers (sampler2D) or standalone samplers.
|
||||
// The remapped sampler must not be an array of samplers.
|
||||
// Prefer remap_constexpr_sampler_by_binding unless you're also doing reflection anyways.
|
||||
void remap_constexpr_sampler(VariableID id, const MSLConstexprSampler &sampler);
|
||||
|
||||
// Same as remap_constexpr_sampler, except you provide set/binding, rather than variable ID.
|
||||
// Remaps based on ID take priority over set/binding remaps.
|
||||
void remap_constexpr_sampler_by_binding(uint32_t desc_set, uint32_t binding, const MSLConstexprSampler &sampler);
|
||||
|
||||
// If using CompilerMSL::Options::pad_fragment_output_components, override the number of components we expect
|
||||
// to use for a particular location. The default is 4 if number of components is not overridden.
|
||||
void set_fragment_output_components(uint32_t location, uint32_t components);
|
||||
|
||||
protected:
|
||||
// An enum of SPIR-V functions that are implemented in additional
|
||||
// source code that is added to the shader if necessary.
|
||||
enum SPVFuncImpl
|
||||
{
|
||||
SPVFuncImplNone,
|
||||
SPVFuncImplMod,
|
||||
SPVFuncImplRadians,
|
||||
SPVFuncImplDegrees,
|
||||
SPVFuncImplFindILsb,
|
||||
SPVFuncImplFindSMsb,
|
||||
SPVFuncImplFindUMsb,
|
||||
SPVFuncImplSSign,
|
||||
SPVFuncImplArrayCopyMultidimBase,
|
||||
// Unfortunately, we cannot use recursive templates in the MSL compiler properly,
|
||||
// so stamp out variants up to some arbitrary maximum.
|
||||
SPVFuncImplArrayCopy = SPVFuncImplArrayCopyMultidimBase + 1,
|
||||
SPVFuncImplArrayOfArrayCopy2Dim = SPVFuncImplArrayCopyMultidimBase + 2,
|
||||
SPVFuncImplArrayOfArrayCopy3Dim = SPVFuncImplArrayCopyMultidimBase + 3,
|
||||
SPVFuncImplArrayOfArrayCopy4Dim = SPVFuncImplArrayCopyMultidimBase + 4,
|
||||
SPVFuncImplArrayOfArrayCopy5Dim = SPVFuncImplArrayCopyMultidimBase + 5,
|
||||
SPVFuncImplArrayOfArrayCopy6Dim = SPVFuncImplArrayCopyMultidimBase + 6,
|
||||
SPVFuncImplTexelBufferCoords,
|
||||
SPVFuncImplImage2DAtomicCoords, // Emulate texture2D atomic operations
|
||||
SPVFuncImplFMul,
|
||||
SPVFuncImplFAdd,
|
||||
SPVFuncImplCubemapTo2DArrayFace,
|
||||
SPVFuncImplUnsafeArray, // Allow Metal to use the array<T> template to make arrays a value type
|
||||
SPVFuncImplInverse4x4,
|
||||
SPVFuncImplInverse3x3,
|
||||
SPVFuncImplInverse2x2,
|
||||
// It is very important that this come before *Swizzle and ChromaReconstruct*, to ensure it's
|
||||
// emitted before them.
|
||||
SPVFuncImplForwardArgs,
|
||||
// Likewise, this must come before *Swizzle.
|
||||
SPVFuncImplGetSwizzle,
|
||||
SPVFuncImplTextureSwizzle,
|
||||
SPVFuncImplGatherSwizzle,
|
||||
SPVFuncImplGatherCompareSwizzle,
|
||||
SPVFuncImplSubgroupBallot,
|
||||
SPVFuncImplSubgroupBallotBitExtract,
|
||||
SPVFuncImplSubgroupBallotFindLSB,
|
||||
SPVFuncImplSubgroupBallotFindMSB,
|
||||
SPVFuncImplSubgroupBallotBitCount,
|
||||
SPVFuncImplSubgroupAllEqual,
|
||||
SPVFuncImplReflectScalar,
|
||||
SPVFuncImplRefractScalar,
|
||||
SPVFuncImplFaceForwardScalar,
|
||||
SPVFuncImplChromaReconstructNearest2Plane,
|
||||
SPVFuncImplChromaReconstructNearest3Plane,
|
||||
SPVFuncImplChromaReconstructLinear422CositedEven2Plane,
|
||||
SPVFuncImplChromaReconstructLinear422CositedEven3Plane,
|
||||
SPVFuncImplChromaReconstructLinear422Midpoint2Plane,
|
||||
SPVFuncImplChromaReconstructLinear422Midpoint3Plane,
|
||||
SPVFuncImplChromaReconstructLinear420XCositedEvenYCositedEven2Plane,
|
||||
SPVFuncImplChromaReconstructLinear420XCositedEvenYCositedEven3Plane,
|
||||
SPVFuncImplChromaReconstructLinear420XMidpointYCositedEven2Plane,
|
||||
SPVFuncImplChromaReconstructLinear420XMidpointYCositedEven3Plane,
|
||||
SPVFuncImplChromaReconstructLinear420XCositedEvenYMidpoint2Plane,
|
||||
SPVFuncImplChromaReconstructLinear420XCositedEvenYMidpoint3Plane,
|
||||
SPVFuncImplChromaReconstructLinear420XMidpointYMidpoint2Plane,
|
||||
SPVFuncImplChromaReconstructLinear420XMidpointYMidpoint3Plane,
|
||||
SPVFuncImplExpandITUFullRange,
|
||||
SPVFuncImplExpandITUNarrowRange,
|
||||
SPVFuncImplConvertYCbCrBT709,
|
||||
SPVFuncImplConvertYCbCrBT601,
|
||||
SPVFuncImplConvertYCbCrBT2020,
|
||||
SPVFuncImplDynamicImageSampler,
|
||||
|
||||
SPVFuncImplArrayCopyMultidimMax = 6
|
||||
};
|
||||
|
||||
// If the underlying resource has been used for comparison then duplicate loads of that resource must be too
|
||||
// Use Metal's native frame-buffer fetch API for subpass inputs.
|
||||
void emit_texture_op(const Instruction &i) override;
|
||||
void emit_binary_unord_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op);
|
||||
void emit_instruction(const Instruction &instr) override;
|
||||
void emit_glsl_op(uint32_t result_type, uint32_t result_id, uint32_t op, const uint32_t *args,
|
||||
uint32_t count) override;
|
||||
void emit_spv_amd_shader_trinary_minmax_op(uint32_t result_type, uint32_t result_id, uint32_t op,
|
||||
const uint32_t *args, uint32_t count) override;
|
||||
void emit_header() override;
|
||||
void emit_function_prototype(SPIRFunction &func, const Bitset &return_flags) override;
|
||||
void emit_sampled_image_op(uint32_t result_type, uint32_t result_id, uint32_t image_id, uint32_t samp_id) override;
|
||||
void emit_subgroup_op(const Instruction &i) override;
|
||||
std::string to_texture_op(const Instruction &i, bool *forward,
|
||||
SmallVector<uint32_t> &inherited_expressions) override;
|
||||
void emit_fixup() override;
|
||||
std::string to_struct_member(const SPIRType &type, uint32_t member_type_id, uint32_t index,
|
||||
const std::string &qualifier = "");
|
||||
void emit_struct_member(const SPIRType &type, uint32_t member_type_id, uint32_t index,
|
||||
const std::string &qualifier = "", uint32_t base_offset = 0) override;
|
||||
void emit_struct_padding_target(const SPIRType &type) override;
|
||||
std::string type_to_glsl(const SPIRType &type, uint32_t id = 0) override;
|
||||
|
||||
// Allow Metal to use the array<T> template to make arrays a value type
|
||||
std::string type_to_array_glsl(const SPIRType &type) override;
|
||||
|
||||
// Threadgroup arrays can't have a wrapper type
|
||||
std::string variable_decl(const SPIRVariable &variable) override;
|
||||
|
||||
// GCC workaround of lambdas calling protected functions (for older GCC versions)
|
||||
std::string variable_decl(const SPIRType &type, const std::string &name, uint32_t id = 0) override;
|
||||
|
||||
std::string image_type_glsl(const SPIRType &type, uint32_t id = 0) override;
|
||||
std::string sampler_type(const SPIRType &type);
|
||||
std::string builtin_to_glsl(spv::BuiltIn builtin, spv::StorageClass storage) override;
|
||||
std::string to_func_call_arg(const SPIRFunction::Parameter &arg, uint32_t id) override;
|
||||
std::string to_name(uint32_t id, bool allow_alias = true) const override;
|
||||
std::string to_function_name(VariableID img, const SPIRType &imgtype, bool is_fetch, bool is_gather, bool is_proj,
|
||||
bool has_array_offsets, bool has_offset, bool has_grad, bool has_dref, uint32_t lod,
|
||||
uint32_t minlod) override;
|
||||
std::string to_function_args(VariableID img, const SPIRType &imgtype, bool is_fetch, bool is_gather, bool is_proj,
|
||||
uint32_t coord, uint32_t coord_components, uint32_t dref, uint32_t grad_x,
|
||||
uint32_t grad_y, uint32_t lod, uint32_t coffset, uint32_t offset, uint32_t bias,
|
||||
uint32_t comp, uint32_t sample, uint32_t minlod, bool *p_forward) override;
|
||||
std::string to_initializer_expression(const SPIRVariable &var) override;
|
||||
std::string to_zero_initialized_expression(uint32_t type_id) override;
|
||||
|
||||
std::string unpack_expression_type(std::string expr_str, const SPIRType &type, uint32_t physical_type_id,
|
||||
bool is_packed, bool row_major) override;
|
||||
|
||||
// Returns true for BuiltInSampleMask because gl_SampleMask[] is an array in SPIR-V, but [[sample_mask]] is a scalar in Metal.
|
||||
bool builtin_translates_to_nonarray(spv::BuiltIn builtin) const override;
|
||||
|
||||
std::string bitcast_glsl_op(const SPIRType &result_type, const SPIRType &argument_type) override;
|
||||
bool emit_complex_bitcast(uint32_t result_id, uint32_t id, uint32_t op0) override;
|
||||
bool skip_argument(uint32_t id) const override;
|
||||
std::string to_member_reference(uint32_t base, const SPIRType &type, uint32_t index, bool ptr_chain) override;
|
||||
std::string to_qualifiers_glsl(uint32_t id) override;
|
||||
void replace_illegal_names() override;
|
||||
void declare_undefined_values() override;
|
||||
void declare_constant_arrays();
|
||||
|
||||
// Constant arrays of non-primitive types (i.e. matrices) won't link properly into Metal libraries
|
||||
void declare_complex_constant_arrays();
|
||||
|
||||
bool is_patch_block(const SPIRType &type);
|
||||
bool is_non_native_row_major_matrix(uint32_t id) override;
|
||||
bool member_is_non_native_row_major_matrix(const SPIRType &type, uint32_t index) override;
|
||||
std::string convert_row_major_matrix(std::string exp_str, const SPIRType &exp_type, uint32_t physical_type_id,
|
||||
bool is_packed) override;
|
||||
|
||||
void preprocess_op_codes();
|
||||
void localize_global_variables();
|
||||
void extract_global_variables_from_functions();
|
||||
void mark_packable_structs();
|
||||
void mark_as_packable(SPIRType &type);
|
||||
|
||||
std::unordered_map<uint32_t, std::set<uint32_t>> function_global_vars;
|
||||
void extract_global_variables_from_function(uint32_t func_id, std::set<uint32_t> &added_arg_ids,
|
||||
std::unordered_set<uint32_t> &global_var_ids,
|
||||
std::unordered_set<uint32_t> &processed_func_ids);
|
||||
uint32_t add_interface_block(spv::StorageClass storage, bool patch = false);
|
||||
uint32_t add_interface_block_pointer(uint32_t ib_var_id, spv::StorageClass storage);
|
||||
|
||||
struct InterfaceBlockMeta
|
||||
{
|
||||
struct LocationMeta
|
||||
{
|
||||
uint32_t num_components = 0;
|
||||
uint32_t ib_index = ~0u;
|
||||
};
|
||||
std::unordered_map<uint32_t, LocationMeta> location_meta;
|
||||
bool strip_array = false;
|
||||
};
|
||||
|
||||
void add_variable_to_interface_block(spv::StorageClass storage, const std::string &ib_var_ref, SPIRType &ib_type,
|
||||
SPIRVariable &var, InterfaceBlockMeta &meta);
|
||||
void add_composite_variable_to_interface_block(spv::StorageClass storage, const std::string &ib_var_ref,
|
||||
SPIRType &ib_type, SPIRVariable &var, InterfaceBlockMeta &meta);
|
||||
void add_plain_variable_to_interface_block(spv::StorageClass storage, const std::string &ib_var_ref,
|
||||
SPIRType &ib_type, SPIRVariable &var, InterfaceBlockMeta &meta);
|
||||
void add_plain_member_variable_to_interface_block(spv::StorageClass storage, const std::string &ib_var_ref,
|
||||
SPIRType &ib_type, SPIRVariable &var, uint32_t index,
|
||||
InterfaceBlockMeta &meta);
|
||||
void add_composite_member_variable_to_interface_block(spv::StorageClass storage, const std::string &ib_var_ref,
|
||||
SPIRType &ib_type, SPIRVariable &var, uint32_t index,
|
||||
InterfaceBlockMeta &meta);
|
||||
uint32_t get_accumulated_member_location(const SPIRVariable &var, uint32_t mbr_idx, bool strip_array);
|
||||
void add_tess_level_input_to_interface_block(const std::string &ib_var_ref, SPIRType &ib_type, SPIRVariable &var);
|
||||
|
||||
void fix_up_interface_member_indices(spv::StorageClass storage, uint32_t ib_type_id);
|
||||
|
||||
void mark_location_as_used_by_shader(uint32_t location, spv::StorageClass storage);
|
||||
uint32_t ensure_correct_builtin_type(uint32_t type_id, spv::BuiltIn builtin);
|
||||
uint32_t ensure_correct_attribute_type(uint32_t type_id, uint32_t location, uint32_t num_components = 0);
|
||||
|
||||
void emit_custom_templates();
|
||||
void emit_custom_functions();
|
||||
void emit_resources();
|
||||
void emit_specialization_constants_and_structs();
|
||||
void emit_interface_block(uint32_t ib_var_id);
|
||||
bool maybe_emit_array_assignment(uint32_t id_lhs, uint32_t id_rhs);
|
||||
|
||||
void fix_up_shader_inputs_outputs();
|
||||
|
||||
std::string func_type_decl(SPIRType &type);
|
||||
std::string entry_point_args_classic(bool append_comma);
|
||||
std::string entry_point_args_argument_buffer(bool append_comma);
|
||||
std::string entry_point_arg_stage_in();
|
||||
void entry_point_args_builtin(std::string &args);
|
||||
void entry_point_args_discrete_descriptors(std::string &args);
|
||||
std::string to_qualified_member_name(const SPIRType &type, uint32_t index);
|
||||
std::string ensure_valid_name(std::string name, std::string pfx);
|
||||
std::string to_sampler_expression(uint32_t id);
|
||||
std::string to_swizzle_expression(uint32_t id);
|
||||
std::string to_buffer_size_expression(uint32_t id);
|
||||
std::string builtin_qualifier(spv::BuiltIn builtin);
|
||||
std::string builtin_type_decl(spv::BuiltIn builtin, uint32_t id = 0);
|
||||
std::string built_in_func_arg(spv::BuiltIn builtin, bool prefix_comma);
|
||||
std::string member_attribute_qualifier(const SPIRType &type, uint32_t index);
|
||||
std::string argument_decl(const SPIRFunction::Parameter &arg);
|
||||
std::string round_fp_tex_coords(std::string tex_coords, bool coord_is_fp);
|
||||
uint32_t get_metal_resource_index(SPIRVariable &var, SPIRType::BaseType basetype, uint32_t plane = 0);
|
||||
uint32_t get_ordered_member_location(uint32_t type_id, uint32_t index, uint32_t *comp = nullptr);
|
||||
|
||||
// MSL packing rules. These compute the effective packing rules as observed by the MSL compiler in the MSL output.
|
||||
// These values can change depending on various extended decorations which control packing rules.
|
||||
// We need to make these rules match up with SPIR-V declared rules.
|
||||
uint32_t get_declared_type_size_msl(const SPIRType &type, bool packed, bool row_major) const;
|
||||
uint32_t get_declared_type_array_stride_msl(const SPIRType &type, bool packed, bool row_major) const;
|
||||
uint32_t get_declared_type_matrix_stride_msl(const SPIRType &type, bool packed, bool row_major) const;
|
||||
uint32_t get_declared_type_alignment_msl(const SPIRType &type, bool packed, bool row_major) const;
|
||||
|
||||
uint32_t get_declared_struct_member_size_msl(const SPIRType &struct_type, uint32_t index) const;
|
||||
uint32_t get_declared_struct_member_array_stride_msl(const SPIRType &struct_type, uint32_t index) const;
|
||||
uint32_t get_declared_struct_member_matrix_stride_msl(const SPIRType &struct_type, uint32_t index) const;
|
||||
uint32_t get_declared_struct_member_alignment_msl(const SPIRType &struct_type, uint32_t index) const;
|
||||
|
||||
const SPIRType &get_physical_member_type(const SPIRType &struct_type, uint32_t index) const;
|
||||
|
||||
uint32_t get_declared_struct_size_msl(const SPIRType &struct_type, bool ignore_alignment = false,
|
||||
bool ignore_padding = false) const;
|
||||
|
||||
std::string to_component_argument(uint32_t id);
|
||||
void align_struct(SPIRType &ib_type, std::unordered_set<uint32_t> &aligned_structs);
|
||||
void mark_scalar_layout_structs(const SPIRType &ib_type);
|
||||
void mark_struct_members_packed(const SPIRType &type);
|
||||
void ensure_member_packing_rules_msl(SPIRType &ib_type, uint32_t index);
|
||||
bool validate_member_packing_rules_msl(const SPIRType &type, uint32_t index) const;
|
||||
std::string get_argument_address_space(const SPIRVariable &argument);
|
||||
std::string get_type_address_space(const SPIRType &type, uint32_t id, bool argument = false);
|
||||
const char *to_restrict(uint32_t id, bool space = true);
|
||||
SPIRType &get_stage_in_struct_type();
|
||||
SPIRType &get_stage_out_struct_type();
|
||||
SPIRType &get_patch_stage_in_struct_type();
|
||||
SPIRType &get_patch_stage_out_struct_type();
|
||||
std::string get_tess_factor_struct_name();
|
||||
void emit_atomic_func_op(uint32_t result_type, uint32_t result_id, const char *op, uint32_t mem_order_1,
|
||||
uint32_t mem_order_2, bool has_mem_order_2, uint32_t op0, uint32_t op1 = 0,
|
||||
bool op1_is_pointer = false, bool op1_is_literal = false, uint32_t op2 = 0);
|
||||
const char *get_memory_order(uint32_t spv_mem_sem);
|
||||
void add_pragma_line(const std::string &line);
|
||||
void add_typedef_line(const std::string &line);
|
||||
void emit_barrier(uint32_t id_exe_scope, uint32_t id_mem_scope, uint32_t id_mem_sem);
|
||||
void emit_array_copy(const std::string &lhs, uint32_t rhs_id, spv::StorageClass lhs_storage,
|
||||
spv::StorageClass rhs_storage) override;
|
||||
void build_implicit_builtins();
|
||||
uint32_t build_constant_uint_array_pointer();
|
||||
void emit_entry_point_declarations() override;
|
||||
uint32_t builtin_frag_coord_id = 0;
|
||||
uint32_t builtin_sample_id_id = 0;
|
||||
uint32_t builtin_vertex_idx_id = 0;
|
||||
uint32_t builtin_base_vertex_id = 0;
|
||||
uint32_t builtin_instance_idx_id = 0;
|
||||
uint32_t builtin_base_instance_id = 0;
|
||||
uint32_t builtin_view_idx_id = 0;
|
||||
uint32_t builtin_layer_id = 0;
|
||||
uint32_t builtin_invocation_id_id = 0;
|
||||
uint32_t builtin_primitive_id_id = 0;
|
||||
uint32_t builtin_subgroup_invocation_id_id = 0;
|
||||
uint32_t builtin_subgroup_size_id = 0;
|
||||
uint32_t builtin_dispatch_base_id = 0;
|
||||
uint32_t swizzle_buffer_id = 0;
|
||||
uint32_t buffer_size_buffer_id = 0;
|
||||
uint32_t view_mask_buffer_id = 0;
|
||||
uint32_t dynamic_offsets_buffer_id = 0;
|
||||
|
||||
void bitcast_to_builtin_store(uint32_t target_id, std::string &expr, const SPIRType &expr_type) override;
|
||||
void bitcast_from_builtin_load(uint32_t source_id, std::string &expr, const SPIRType &expr_type) override;
|
||||
void emit_store_statement(uint32_t lhs_expression, uint32_t rhs_expression) override;
|
||||
|
||||
void analyze_sampled_image_usage();
|
||||
|
||||
bool emit_tessellation_access_chain(const uint32_t *ops, uint32_t length);
|
||||
bool emit_tessellation_io_load(uint32_t result_type, uint32_t id, uint32_t ptr);
|
||||
bool is_out_of_bounds_tessellation_level(uint32_t id_lhs);
|
||||
|
||||
void ensure_builtin(spv::StorageClass storage, spv::BuiltIn builtin);
|
||||
|
||||
void mark_implicit_builtin(spv::StorageClass storage, spv::BuiltIn builtin, uint32_t id);
|
||||
|
||||
std::string convert_to_f32(const std::string &expr, uint32_t components);
|
||||
|
||||
Options msl_options;
|
||||
std::set<SPVFuncImpl> spv_function_implementations;
|
||||
std::unordered_map<uint32_t, MSLVertexAttr> vtx_attrs_by_location;
|
||||
std::unordered_map<uint32_t, MSLVertexAttr> vtx_attrs_by_builtin;
|
||||
std::unordered_set<uint32_t> vtx_attrs_in_use;
|
||||
std::unordered_map<uint32_t, uint32_t> fragment_output_components;
|
||||
std::set<std::string> pragma_lines;
|
||||
std::set<std::string> typedef_lines;
|
||||
SmallVector<uint32_t> vars_needing_early_declaration;
|
||||
|
||||
std::unordered_map<StageSetBinding, std::pair<MSLResourceBinding, bool>, InternalHasher> resource_bindings;
|
||||
|
||||
uint32_t next_metal_resource_index_buffer = 0;
|
||||
uint32_t next_metal_resource_index_texture = 0;
|
||||
uint32_t next_metal_resource_index_sampler = 0;
|
||||
// Intentionally uninitialized, works around MSVC 2013 bug.
|
||||
uint32_t next_metal_resource_ids[kMaxArgumentBuffers];
|
||||
|
||||
VariableID stage_in_var_id = 0;
|
||||
VariableID stage_out_var_id = 0;
|
||||
VariableID patch_stage_in_var_id = 0;
|
||||
VariableID patch_stage_out_var_id = 0;
|
||||
VariableID stage_in_ptr_var_id = 0;
|
||||
VariableID stage_out_ptr_var_id = 0;
|
||||
|
||||
// Handle HLSL-style 0-based vertex/instance index.
|
||||
enum class TriState
|
||||
{
|
||||
Neutral,
|
||||
No,
|
||||
Yes
|
||||
};
|
||||
TriState needs_base_vertex_arg = TriState::Neutral;
|
||||
TriState needs_base_instance_arg = TriState::Neutral;
|
||||
|
||||
bool has_sampled_images = false;
|
||||
bool builtin_declaration = false; // Handle HLSL-style 0-based vertex/instance index.
|
||||
|
||||
bool is_using_builtin_array = false; // Force the use of C style array declaration.
|
||||
bool using_builtin_array() const;
|
||||
|
||||
bool is_rasterization_disabled = false;
|
||||
bool capture_output_to_buffer = false;
|
||||
bool needs_swizzle_buffer_def = false;
|
||||
bool used_swizzle_buffer = false;
|
||||
bool added_builtin_tess_level = false;
|
||||
bool needs_subgroup_invocation_id = false;
|
||||
std::string qual_pos_var_name;
|
||||
std::string stage_in_var_name = "in";
|
||||
std::string stage_out_var_name = "out";
|
||||
std::string patch_stage_in_var_name = "patchIn";
|
||||
std::string patch_stage_out_var_name = "patchOut";
|
||||
std::string sampler_name_suffix = "Smplr";
|
||||
std::string swizzle_name_suffix = "Swzl";
|
||||
std::string buffer_size_name_suffix = "BufferSize";
|
||||
std::string plane_name_suffix = "Plane";
|
||||
std::string input_wg_var_name = "gl_in";
|
||||
std::string output_buffer_var_name = "spvOut";
|
||||
std::string patch_output_buffer_var_name = "spvPatchOut";
|
||||
std::string tess_factor_buffer_var_name = "spvTessLevel";
|
||||
spv::Op previous_instruction_opcode = spv::OpNop;
|
||||
|
||||
// Must be ordered since declaration is in a specific order.
|
||||
std::map<uint32_t, MSLConstexprSampler> constexpr_samplers_by_id;
|
||||
std::unordered_map<SetBindingPair, MSLConstexprSampler, InternalHasher> constexpr_samplers_by_binding;
|
||||
const MSLConstexprSampler *find_constexpr_sampler(uint32_t id) const;
|
||||
|
||||
std::unordered_set<uint32_t> buffers_requiring_array_length;
|
||||
SmallVector<uint32_t> buffer_arrays;
|
||||
std::unordered_set<uint32_t> atomic_image_vars; // Emulate texture2D atomic operations
|
||||
|
||||
// Must be ordered since array is in a specific order.
|
||||
std::map<SetBindingPair, std::pair<uint32_t, uint32_t>> buffers_requiring_dynamic_offset;
|
||||
|
||||
SmallVector<uint32_t> disabled_frag_outputs;
|
||||
|
||||
std::unordered_set<SetBindingPair, InternalHasher> inline_uniform_blocks;
|
||||
|
||||
uint32_t argument_buffer_ids[kMaxArgumentBuffers];
|
||||
uint32_t argument_buffer_discrete_mask = 0;
|
||||
uint32_t argument_buffer_device_storage_mask = 0;
|
||||
|
||||
void analyze_argument_buffers();
|
||||
bool descriptor_set_is_argument_buffer(uint32_t desc_set) const;
|
||||
|
||||
uint32_t get_target_components_for_fragment_location(uint32_t location) const;
|
||||
uint32_t build_extended_vector_type(uint32_t type_id, uint32_t components);
|
||||
|
||||
bool suppress_missing_prototypes = false;
|
||||
|
||||
void add_spv_func_and_recompile(SPVFuncImpl spv_func);
|
||||
|
||||
void activate_argument_buffer_resources();
|
||||
|
||||
bool type_is_msl_framebuffer_fetch(const SPIRType &type) const;
|
||||
|
||||
// OpcodeHandler that handles several MSL preprocessing operations.
|
||||
struct OpCodePreprocessor : OpcodeHandler
|
||||
{
|
||||
OpCodePreprocessor(CompilerMSL &compiler_)
|
||||
: compiler(compiler_)
|
||||
{
|
||||
}
|
||||
|
||||
bool handle(spv::Op opcode, const uint32_t *args, uint32_t length) override;
|
||||
CompilerMSL::SPVFuncImpl get_spv_func_impl(spv::Op opcode, const uint32_t *args);
|
||||
void check_resource_write(uint32_t var_id);
|
||||
|
||||
CompilerMSL &compiler;
|
||||
std::unordered_map<uint32_t, uint32_t> result_types;
|
||||
std::unordered_map<uint32_t, uint32_t> image_pointers; // Emulate texture2D atomic operations
|
||||
bool suppress_missing_prototypes = false;
|
||||
bool uses_atomics = false;
|
||||
bool uses_resource_write = false;
|
||||
bool needs_subgroup_invocation_id = false;
|
||||
};
|
||||
|
||||
// OpcodeHandler that scans for uses of sampled images
|
||||
struct SampledImageScanner : OpcodeHandler
|
||||
{
|
||||
SampledImageScanner(CompilerMSL &compiler_)
|
||||
: compiler(compiler_)
|
||||
{
|
||||
}
|
||||
|
||||
bool handle(spv::Op opcode, const uint32_t *args, uint32_t) override;
|
||||
|
||||
CompilerMSL &compiler;
|
||||
};
|
||||
|
||||
// Sorts the members of a SPIRType and associated Meta info based on a settable sorting
|
||||
// aspect, which defines which aspect of the struct members will be used to sort them.
|
||||
// Regardless of the sorting aspect, built-in members always appear at the end of the struct.
|
||||
struct MemberSorter
|
||||
{
|
||||
enum SortAspect
|
||||
{
|
||||
Location,
|
||||
LocationReverse,
|
||||
Offset,
|
||||
OffsetThenLocationReverse,
|
||||
Alphabetical
|
||||
};
|
||||
|
||||
void sort();
|
||||
bool operator()(uint32_t mbr_idx1, uint32_t mbr_idx2);
|
||||
MemberSorter(SPIRType &t, Meta &m, SortAspect sa);
|
||||
|
||||
SPIRType &type;
|
||||
Meta &meta;
|
||||
SortAspect sort_aspect;
|
||||
};
|
||||
};
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright 2018-2020 Arm Limited
|
||||
*
|
||||
* 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 SPIRV_CROSS_PARSER_HPP
|
||||
#define SPIRV_CROSS_PARSER_HPP
|
||||
|
||||
#include "spirv_cross_parsed_ir.hpp"
|
||||
#include <stdint.h>
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
class Parser
|
||||
{
|
||||
public:
|
||||
Parser(const uint32_t *spirv_data, size_t word_count);
|
||||
Parser(std::vector<uint32_t> spirv);
|
||||
|
||||
void parse();
|
||||
|
||||
ParsedIR &get_parsed_ir()
|
||||
{
|
||||
return ir;
|
||||
}
|
||||
|
||||
private:
|
||||
ParsedIR ir;
|
||||
SPIRFunction *current_function = nullptr;
|
||||
SPIRBlock *current_block = nullptr;
|
||||
|
||||
void parse(const Instruction &instr);
|
||||
const uint32_t *stream(const Instruction &instr) const;
|
||||
|
||||
template <typename T, typename... P>
|
||||
T &set(uint32_t id, P &&... args)
|
||||
{
|
||||
ir.add_typed_id(static_cast<Types>(T::type), id);
|
||||
auto &var = variant_set<T>(ir.ids[id], std::forward<P>(args)...);
|
||||
var.self = id;
|
||||
return var;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &get(uint32_t id)
|
||||
{
|
||||
return variant_get<T>(ir.ids[id]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *maybe_get(uint32_t id)
|
||||
{
|
||||
if (ir.ids[id].get_type() == static_cast<Types>(T::type))
|
||||
return &get<T>(id);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T &get(uint32_t id) const
|
||||
{
|
||||
return variant_get<T>(ir.ids[id]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T *maybe_get(uint32_t id) const
|
||||
{
|
||||
if (ir.ids[id].get_type() == T::type)
|
||||
return &get<T>(id);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// This must be an ordered data structure so we always pick the same type aliases.
|
||||
SmallVector<uint32_t> global_struct_cache;
|
||||
|
||||
bool types_are_logically_equivalent(const SPIRType &a, const SPIRType &b) const;
|
||||
bool variable_storage_is_aliased(const SPIRVariable &v) const;
|
||||
};
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright 2018-2020 Bradley Austin Davis
|
||||
*
|
||||
* 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 SPIRV_CROSS_REFLECT_HPP
|
||||
#define SPIRV_CROSS_REFLECT_HPP
|
||||
|
||||
#include "spirv_glsl.hpp"
|
||||
#include <utility>
|
||||
|
||||
namespace simple_json
|
||||
{
|
||||
class Stream;
|
||||
}
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
class CompilerReflection : public CompilerGLSL
|
||||
{
|
||||
using Parent = CompilerGLSL;
|
||||
|
||||
public:
|
||||
explicit CompilerReflection(std::vector<uint32_t> spirv_)
|
||||
: Parent(std::move(spirv_))
|
||||
{
|
||||
options.vulkan_semantics = true;
|
||||
}
|
||||
|
||||
CompilerReflection(const uint32_t *ir_, size_t word_count)
|
||||
: Parent(ir_, word_count)
|
||||
{
|
||||
options.vulkan_semantics = true;
|
||||
}
|
||||
|
||||
explicit CompilerReflection(const ParsedIR &ir_)
|
||||
: CompilerGLSL(ir_)
|
||||
{
|
||||
options.vulkan_semantics = true;
|
||||
}
|
||||
|
||||
explicit CompilerReflection(ParsedIR &&ir_)
|
||||
: CompilerGLSL(std::move(ir_))
|
||||
{
|
||||
options.vulkan_semantics = true;
|
||||
}
|
||||
|
||||
void set_format(const std::string &format);
|
||||
std::string compile() override;
|
||||
|
||||
private:
|
||||
static std::string execution_model_to_str(spv::ExecutionModel model);
|
||||
|
||||
void emit_entry_points();
|
||||
void emit_types();
|
||||
void emit_resources();
|
||||
void emit_specialization_constants();
|
||||
|
||||
void emit_type(const SPIRType &type, bool &emitted_open_tag);
|
||||
void emit_type_member(const SPIRType &type, uint32_t index);
|
||||
void emit_type_member_qualifiers(const SPIRType &type, uint32_t index);
|
||||
void emit_type_array(const SPIRType &type);
|
||||
void emit_resources(const char *tag, const SmallVector<Resource> &resources);
|
||||
|
||||
std::string to_member_name(const SPIRType &type, uint32_t index) const;
|
||||
|
||||
std::shared_ptr<simple_json::Stream> json_stream;
|
||||
};
|
||||
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue