1 //
2 // Copyright (c) 2016 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 // TextureFunctionHLSL: Class for writing implementations of ESSL texture functions into HLSL
7 // output. Some of the implementations are straightforward and just call the HLSL equivalent of the
8 // ESSL texture function, others do more work to emulate ESSL texture sampling or size query
9 // behavior.
10 //
11 
12 #ifndef COMPILER_TRANSLATOR_TEXTUREFUNCTIONHLSL_H_
13 #define COMPILER_TRANSLATOR_TEXTUREFUNCTIONHLSL_H_
14 
15 #include <set>
16 
17 #include "compiler/translator/BaseTypes.h"
18 #include "compiler/translator/Common.h"
19 #include "compiler/translator/InfoSink.h"
20 #include "GLSLANG/ShaderLang.h"
21 
22 namespace sh
23 {
24 
25 class TextureFunctionHLSL final : angle::NonCopyable
26 {
27   public:
28     struct TextureFunction
29     {
30         // See ESSL 3.00.6 section 8.8 for reference about what the different methods below do.
31         enum Method
32         {
33             IMPLICIT,  // Mipmap LOD determined implicitly (standard lookup)
34             BIAS,
35             LOD,
36             LOD0,
37             LOD0BIAS,
38             SIZE,  // textureSize()
39             FETCH,
40             GRAD
41         };
42 
43         TString name() const;
44 
45         bool operator<(const TextureFunction &rhs) const;
46 
47         const char *getReturnType() const;
48 
49         TBasicType sampler;
50         int coords;
51         bool proj;
52         bool offset;
53         Method method;
54     };
55 
56     // Returns the name of the texture function implementation to call.
57     // The name that's passed in is the name of the GLSL texture function that it should implement.
58     TString useTextureFunction(const TString &name,
59                                TBasicType samplerType,
60                                int coords,
61                                size_t argumentCount,
62                                bool lod0,
63                                sh::GLenum shaderType);
64 
65     void textureFunctionHeader(TInfoSinkBase &out,
66                                const ShShaderOutput outputType,
67                                bool getDimensionsIgnoresBaseLevel);
68 
69   private:
70     typedef std::set<TextureFunction> TextureFunctionSet;
71     TextureFunctionSet mUsesTexture;
72 };
73 
74 }  // namespace sh
75 
76 #endif  // COMPILER_TRANSLATOR_TEXTUREFUNCTIONHLSL_H_
77