1 // 2 // Copyright 2017 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 // ImageFunctionHLSL: Class for writing implementations of ESSL image functions into HLSL output. 7 // 8 9 #ifndef COMPILER_TRANSLATOR_IMAGEFUNCTIONHLSL_H_ 10 #define COMPILER_TRANSLATOR_IMAGEFUNCTIONHLSL_H_ 11 12 #include <set> 13 14 #include "GLSLANG/ShaderLang.h" 15 #include "compiler/translator/BaseTypes.h" 16 #include "compiler/translator/Common.h" 17 #include "compiler/translator/InfoSink.h" 18 #include "compiler/translator/Types.h" 19 20 namespace sh 21 { 22 23 class ImageFunctionHLSL final : angle::NonCopyable 24 { 25 public: 26 // Returns the name of the image function implementation to caller. 27 // The name that's passed in is the name of the GLSL image function that it should implement. 28 ImmutableString useImageFunction(const ImmutableString &name, 29 const TBasicType &type, 30 TLayoutImageInternalFormat imageInternalFormat, 31 bool readonly); 32 33 void imageFunctionHeader(TInfoSinkBase &out); getUsedImage2DFunctionNames()34 const std::set<std::string> &getUsedImage2DFunctionNames() const 35 { 36 return mUsedImage2DFunctionNames; 37 } 38 39 private: 40 struct ImageFunction 41 { 42 // See ESSL 3.10.4 section 8.12 for reference about what the different methods below do. 43 enum class Method 44 { 45 SIZE, 46 LOAD, 47 STORE 48 }; 49 50 enum class DataType 51 { 52 NONE, 53 FLOAT4, 54 UINT4, 55 INT4, 56 UNORM_FLOAT4, 57 SNORM_FLOAT4 58 }; 59 60 ImmutableString name() const; 61 62 bool operator<(const ImageFunction &rhs) const; 63 64 DataType getDataType(TLayoutImageInternalFormat format) const; 65 66 const char *getReturnType() const; 67 68 TBasicType image; 69 TLayoutImageInternalFormat imageInternalFormat; 70 bool readonly; 71 Method method; 72 DataType type; 73 }; 74 75 static ImmutableString GetImageReference(TInfoSinkBase &out, 76 const ImageFunctionHLSL::ImageFunction &imageFunction); 77 static void OutputImageFunctionArgumentList( 78 TInfoSinkBase &out, 79 const ImageFunctionHLSL::ImageFunction &imageFunction); 80 static void OutputImageSizeFunctionBody(TInfoSinkBase &out, 81 const ImageFunctionHLSL::ImageFunction &imageFunction, 82 const ImmutableString &imageReference); 83 static void OutputImageLoadFunctionBody(TInfoSinkBase &out, 84 const ImageFunctionHLSL::ImageFunction &imageFunction, 85 const ImmutableString &imageReference); 86 static void OutputImageStoreFunctionBody(TInfoSinkBase &out, 87 const ImageFunctionHLSL::ImageFunction &imageFunction, 88 const ImmutableString &imageReference); 89 using ImageFunctionSet = std::set<ImageFunction>; 90 ImageFunctionSet mUsesImage; 91 std::set<std::string> mUsedImage2DFunctionNames; 92 }; 93 94 } // namespace sh 95 96 #endif // COMPILER_TRANSLATOR_IMAGEFUNCTIONHLSL_H_ 97