blob: 068fa2ec49461d5507fc312ab2e13c7dd6d1c5ca [file] [log] [blame]
Jamie Madill8daaba12014-06-13 10:04:33 -04001//
2// Copyright (c) 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// StructureHLSL.h:
7// Interfaces of methods for HLSL translation of GLSL structures.
8//
9
10#ifndef TRANSLATOR_STRUCTUREHLSL_H_
11#define TRANSLATOR_STRUCTUREHLSL_H_
12
13#include "compiler/translator/Common.h"
Jamie Madillb1a85f42014-08-19 15:23:24 -040014#include "compiler/translator/IntermNode.h"
Jamie Madill8daaba12014-06-13 10:04:33 -040015
16#include <set>
17
18class TInfoSinkBase;
19class TScopeBracket;
20
21namespace sh
22{
23
24// This helper class assists structure and interface block definitions in determining
25// how to pack std140 structs within HLSL's packing rules.
26class Std140PaddingHelper
27{
28 public:
29 explicit Std140PaddingHelper(const std::map<TString, int> &structElementIndexes);
30
31 int elementIndex() const { return mElementIndex; }
32 int prePadding(const TType &type);
33 TString prePaddingString(const TType &type);
34 TString postPaddingString(const TType &type, bool useHLSLRowMajorPacking);
35
36 private:
37 int mPaddingCounter;
38 int mElementIndex;
39 const std::map<TString, int> &mStructElementIndexes;
40};
41
42class StructureHLSL
43{
44 public:
45 StructureHLSL();
46
47 void addConstructor(const TType &type, const TString &name, const TIntermSequence *parameters);
48 std::string structsHeader() const;
49
50 TString defineQualified(const TStructure &structure, bool useHLSLRowMajorPacking, bool useStd140Packing);
51 static TString defineNameless(const TStructure &structure);
52
53 Std140PaddingHelper getPaddingHelper() const { return Std140PaddingHelper(mStd140StructElementIndexes); }
54
55 private:
56 std::map<TString, int> mStd140StructElementIndexes;
57
58 typedef std::set<TString> StructNames;
59 StructNames mStructNames;
60
61 typedef std::set<TString> Constructors;
62 Constructors mConstructors;
63
64 typedef std::vector<TString> StructDeclarations;
65 StructDeclarations mStructDeclarations;
66
67 void storeStd140ElementIndex(const TStructure &structure, bool useHLSLRowMajorPacking);
68 static TString define(const TStructure &structure, bool useHLSLRowMajorPacking,
69 bool useStd140Packing, Std140PaddingHelper *padHelper);
70};
71
72}
73
74#endif // COMPILER_STRUCTUREHLSL_H_