1 // 2 // Copyright 2014 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 // UtilsHLSL.h: 7 // Utility methods for GLSL to HLSL translation. 8 // 9 10 #ifndef COMPILER_TRANSLATOR_UTILSHLSL_H_ 11 #define COMPILER_TRANSLATOR_UTILSHLSL_H_ 12 13 #include <vector> 14 #include "compiler/translator/IntermNode.h" 15 #include "compiler/translator/Types.h" 16 17 #include "angle_gl.h" 18 19 namespace sh 20 { 21 22 class TFunction; 23 24 // HLSL Texture type for GLSL sampler type and readonly image type. 25 enum HLSLTextureGroup 26 { 27 // read resources 28 HLSL_TEXTURE_2D, 29 HLSL_TEXTURE_MIN = HLSL_TEXTURE_2D, 30 31 HLSL_TEXTURE_CUBE, 32 HLSL_TEXTURE_2D_ARRAY, 33 HLSL_TEXTURE_3D, 34 HLSL_TEXTURE_2D_UNORM, 35 HLSL_TEXTURE_CUBE_UNORM, 36 HLSL_TEXTURE_2D_ARRAY_UNORN, 37 HLSL_TEXTURE_3D_UNORM, 38 HLSL_TEXTURE_2D_SNORM, 39 HLSL_TEXTURE_CUBE_SNORM, 40 HLSL_TEXTURE_2D_ARRAY_SNORM, 41 HLSL_TEXTURE_3D_SNORM, 42 HLSL_TEXTURE_2D_MS, 43 HLSL_TEXTURE_2D_MS_ARRAY, 44 HLSL_TEXTURE_2D_INT4, 45 HLSL_TEXTURE_3D_INT4, 46 HLSL_TEXTURE_2D_ARRAY_INT4, 47 HLSL_TEXTURE_2D_MS_INT4, 48 HLSL_TEXTURE_2D_MS_ARRAY_INT4, 49 HLSL_TEXTURE_2D_UINT4, 50 HLSL_TEXTURE_3D_UINT4, 51 HLSL_TEXTURE_2D_ARRAY_UINT4, 52 HLSL_TEXTURE_2D_MS_UINT4, 53 HLSL_TEXTURE_2D_MS_ARRAY_UINT4, 54 55 // Comparison samplers 56 57 HLSL_TEXTURE_2D_COMPARISON, 58 HLSL_TEXTURE_CUBE_COMPARISON, 59 HLSL_TEXTURE_2D_ARRAY_COMPARISON, 60 61 HLSL_COMPARISON_SAMPLER_GROUP_BEGIN = HLSL_TEXTURE_2D_COMPARISON, 62 HLSL_COMPARISON_SAMPLER_GROUP_END = HLSL_TEXTURE_2D_ARRAY_COMPARISON, 63 64 HLSL_TEXTURE_UNKNOWN, 65 HLSL_TEXTURE_MAX = HLSL_TEXTURE_UNKNOWN 66 }; 67 68 // HLSL RWTexture type for GLSL read and write image type. 69 enum HLSLRWTextureGroup 70 { 71 // read/write resource 72 HLSL_RWTEXTURE_2D_FLOAT4, 73 HLSL_RWTEXTURE_MIN = HLSL_RWTEXTURE_2D_FLOAT4, 74 HLSL_RWTEXTURE_2D_ARRAY_FLOAT4, 75 HLSL_RWTEXTURE_3D_FLOAT4, 76 HLSL_RWTEXTURE_2D_UNORM, 77 HLSL_RWTEXTURE_2D_ARRAY_UNORN, 78 HLSL_RWTEXTURE_3D_UNORM, 79 HLSL_RWTEXTURE_2D_SNORM, 80 HLSL_RWTEXTURE_2D_ARRAY_SNORM, 81 HLSL_RWTEXTURE_3D_SNORM, 82 HLSL_RWTEXTURE_2D_UINT4, 83 HLSL_RWTEXTURE_2D_ARRAY_UINT4, 84 HLSL_RWTEXTURE_3D_UINT4, 85 HLSL_RWTEXTURE_2D_INT4, 86 HLSL_RWTEXTURE_2D_ARRAY_INT4, 87 HLSL_RWTEXTURE_3D_INT4, 88 89 HLSL_RWTEXTURE_UNKNOWN, 90 HLSL_RWTEXTURE_MAX = HLSL_RWTEXTURE_UNKNOWN 91 }; 92 93 HLSLTextureGroup TextureGroup(const TBasicType type, 94 TLayoutImageInternalFormat imageInternalFormat = EiifUnspecified); 95 const char *TextureString(const HLSLTextureGroup textureGroup); 96 const char *TextureString(const TBasicType type, 97 TLayoutImageInternalFormat imageInternalFormat = EiifUnspecified); 98 const char *TextureGroupSuffix(const HLSLTextureGroup type); 99 const char *TextureGroupSuffix(const TBasicType type, 100 TLayoutImageInternalFormat imageInternalFormat = EiifUnspecified); 101 const char *TextureTypeSuffix(const TBasicType type, 102 TLayoutImageInternalFormat imageInternalFormat = EiifUnspecified); 103 HLSLRWTextureGroup RWTextureGroup(const TBasicType type, 104 TLayoutImageInternalFormat imageInternalFormat); 105 const char *RWTextureString(const HLSLRWTextureGroup textureGroup); 106 const char *RWTextureString(const TBasicType type, TLayoutImageInternalFormat imageInternalFormat); 107 const char *RWTextureGroupSuffix(const HLSLRWTextureGroup type); 108 const char *RWTextureGroupSuffix(const TBasicType type, 109 TLayoutImageInternalFormat imageInternalFormat); 110 const char *RWTextureTypeSuffix(const TBasicType type, 111 TLayoutImageInternalFormat imageInternalFormat); 112 113 const char *SamplerString(const TBasicType type); 114 const char *SamplerString(HLSLTextureGroup type); 115 116 // Adds a prefix to user-defined names to avoid naming clashes. 117 TString Decorate(const ImmutableString &string); 118 TString DecorateVariableIfNeeded(const TVariable &variable); 119 TString DecorateFunctionIfNeeded(const TFunction *func); 120 TString DecorateField(const ImmutableString &string, const TStructure &structure); 121 TString DecoratePrivate(const ImmutableString &privateText); 122 TString TypeString(const TType &type); 123 TString StructNameString(const TStructure &structure); 124 TString QualifiedStructNameString(const TStructure &structure, 125 bool useHLSLRowMajorPacking, 126 bool useStd140Packing, 127 bool forcePackingEnd); 128 const char *InterpolationString(TQualifier qualifier); 129 const char *QualifierString(TQualifier qualifier); 130 // Parameters may need to be included in function names to disambiguate between overloaded 131 // functions. 132 TString DisambiguateFunctionName(const TFunction *func); 133 TString DisambiguateFunctionName(const TIntermSequence *args); 134 } // namespace sh 135 136 #endif // COMPILER_TRANSLATOR_UTILSHLSL_H_ 137