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 buffer variable of shader storage block 7 // to an offset of RWByteAddressBuffer. 8 // 9 10 #ifndef COMPILER_TRANSLATOR_SHADERSTORAGEBLOCKOUTPUTHLSL_H_ 11 #define COMPILER_TRANSLATOR_SHADERSTORAGEBLOCKOUTPUTHLSL_H_ 12 13 #include "compiler/translator/ShaderStorageBlockFunctionHLSL.h" 14 #include "compiler/translator/blocklayout.h" 15 #include "compiler/translator/tree_util/IntermTraverse.h" 16 17 namespace sh 18 { 19 class ResourcesHLSL; 20 class OutputHLSL; 21 class TSymbolTable; 22 23 struct TReferencedBlock : angle::NonCopyable 24 { 25 POOL_ALLOCATOR_NEW_DELETE 26 TReferencedBlock(const TInterfaceBlock *block, const TVariable *instanceVariable); 27 const TInterfaceBlock *block; 28 const TVariable *instanceVariable; // May be nullptr if the block is not instanced. 29 }; 30 31 // Maps from uniqueId to a variable. 32 using ReferencedInterfaceBlocks = std::map<int, const TReferencedBlock *>; 33 34 // Used to save shader storage block field member information. 35 using BlockMemberInfoMap = std::map<const TField *, BlockMemberInfo>; 36 37 using ShaderVarToFieldMap = std::map<std::string, const TField *>; 38 39 class ShaderStorageBlockOutputHLSL : public TIntermTraverser 40 { 41 public: 42 ShaderStorageBlockOutputHLSL(OutputHLSL *outputHLSL, 43 TSymbolTable *symbolTable, 44 ResourcesHLSL *resourcesHLSL, 45 const std::vector<InterfaceBlock> &shaderStorageBlocks); 46 47 ~ShaderStorageBlockOutputHLSL() override; 48 49 // This writes part of the function call to store a value to a SSBO to the output stream. After 50 // calling this, ", <stored value>)" should be written to the output stream to complete the 51 // function call. 52 void outputStoreFunctionCallPrefix(TIntermTyped *node); 53 // This writes the function call to load a SSBO value to the output stream. 54 void outputLoadFunctionCall(TIntermTyped *node); 55 // This writes the function call to get the lengh of unsized array member of SSBO. 56 void outputLengthFunctionCall(TIntermTyped *node); 57 // Writes the atomic memory function calls for SSBO. 58 void outputAtomicMemoryFunctionCallPrefix(TIntermTyped *node, TOperator op); 59 60 void writeShaderStorageBlocksHeader(TInfoSinkBase &out) const; 61 62 protected: 63 void visitSymbol(TIntermSymbol *) override; 64 void visitConstantUnion(TIntermConstantUnion *) override; 65 bool visitSwizzle(Visit visit, TIntermSwizzle *node) override; 66 bool visitBinary(Visit visit, TIntermBinary *) override; 67 bool visitAggregate(Visit visit, TIntermAggregate *node) override; 68 bool visitTernary(Visit visit, TIntermTernary *) override; 69 bool visitUnary(Visit visit, TIntermUnary *) override; 70 71 private: 72 void traverseSSBOAccess(TIntermTyped *node, SSBOMethod method); 73 void setMatrixStride(TIntermTyped *node, TLayoutBlockStorage storage, bool rowMajor); 74 bool isEndOfSSBOAccessChain(); 75 void writeEOpIndexDirectOrIndirectOutput(TInfoSinkBase &out, Visit visit, TIntermBinary *node); 76 // Common part in dot operations. 77 void writeDotOperatorOutput(TInfoSinkBase &out, const TField *field); 78 79 int mMatrixStride; 80 bool mRowMajor; 81 bool mLocationAsTheLastArgument; 82 OutputHLSL *mOutputHLSL; 83 ShaderStorageBlockFunctionHLSL *mSSBOFunctionHLSL; 84 ResourcesHLSL *mResourcesHLSL; 85 ReferencedInterfaceBlocks mReferencedShaderStorageBlocks; 86 87 BlockMemberInfoMap mBlockMemberInfoMap; 88 const std::vector<InterfaceBlock> &mShaderStorageBlocks; 89 }; 90 } // namespace sh 91 92 #endif // COMPILER_TRANSLATOR_SHADERSTORAGEBLOCKOUTPUTHLSL_H_ 93