1 //
2 // Copyright 2018 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 // ShaderStorageBlockOutputHLSL: A traverser to translate a ssbo_access_chain to an offset of
7 // RWByteAddressBuffer.
8 //     //EOpIndexDirectInterfaceBlock
9 //     ssbo_variable :=
10 //       | the name of the SSBO
11 //       | the name of a variable in an SSBO backed interface block
12 
13 //     // EOpIndexInDirect
14 //     // EOpIndexDirect
15 //     ssbo_array_indexing := ssbo_access_chain[expr_no_ssbo]
16 
17 //     // EOpIndexDirectStruct
18 //     ssbo_structure_access := ssbo_access_chain.identifier
19 
20 //     ssbo_access_chain :=
21 //       | ssbo_variable
22 //       | ssbo_array_indexing
23 //       | ssbo_structure_access
24 //
25 
26 #ifndef COMPILER_TRANSLATOR_SHADERSTORAGEBLOCKFUNCTIONHLSL_H_
27 #define COMPILER_TRANSLATOR_SHADERSTORAGEBLOCKFUNCTIONHLSL_H_
28 
29 #include <set>
30 
31 #include "compiler/translator/InfoSink.h"
32 #include "compiler/translator/Types.h"
33 
34 namespace sh
35 {
36 
37 class TIntermSwizzle;
38 enum class SSBOMethod
39 {
40     LOAD,
41     STORE,
42     LENGTH,
43     ATOMIC_ADD,
44     ATOMIC_MIN,
45     ATOMIC_MAX,
46     ATOMIC_AND,
47     ATOMIC_OR,
48     ATOMIC_XOR,
49     ATOMIC_EXCHANGE,
50     ATOMIC_COMPSWAP
51 };
52 
53 class ShaderStorageBlockFunctionHLSL final : angle::NonCopyable
54 {
55   public:
56     TString registerShaderStorageBlockFunction(const TType &type,
57                                                SSBOMethod method,
58                                                TLayoutBlockStorage storage,
59                                                bool rowMajor,
60                                                int matrixStride,
61                                                int unsizedArrayStride,
62                                                TIntermSwizzle *node);
63 
64     void shaderStorageBlockFunctionHeader(TInfoSinkBase &out);
65 
66   private:
67     struct ShaderStorageBlockFunction
68     {
69         bool operator<(const ShaderStorageBlockFunction &rhs) const;
70         TString functionName;
71         TString typeString;
72         SSBOMethod method;
73         TType type;
74         bool rowMajor;
75         int matrixStride;
76         int unsizedArrayStride;
77         TVector<int> swizzleOffsets;
78         bool isDefaultSwizzle;
79     };
80 
81     static void OutputSSBOLoadFunctionBody(TInfoSinkBase &out,
82                                            const ShaderStorageBlockFunction &ssboFunction);
83     static void OutputSSBOStoreFunctionBody(TInfoSinkBase &out,
84                                             const ShaderStorageBlockFunction &ssboFunction);
85     static void OutputSSBOLengthFunctionBody(TInfoSinkBase &out, int unsizedArrayStride);
86     static void OutputSSBOAtomicMemoryFunctionBody(TInfoSinkBase &out,
87                                                    const ShaderStorageBlockFunction &ssboFunction);
88     using ShaderStorageBlockFunctionSet = std::set<ShaderStorageBlockFunction>;
89     ShaderStorageBlockFunctionSet mRegisteredShaderStorageBlockFunctions;
90 };
91 
92 }  // namespace sh
93 
94 #endif  // COMPILER_TRANSLATOR_SHADERSTORAGEBLOCKFUNCTIONHLSL_H_
95