blob: cffe2a41ae05e22118af52d951a22c5b8f76c1be [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
Geoff Lang0a73dd82014-11-19 16:18:08 -050010#ifndef COMPILER_TRANSLATOR_STRUCTUREHLSL_H_
11#define COMPILER_TRANSLATOR_STRUCTUREHLSL_H_
Jamie Madill8daaba12014-06-13 10:04:33 -040012
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:
Jamie Madill33a74bd2014-08-18 15:47:59 -040029 explicit Std140PaddingHelper(const std::map<TString, int> &structElementIndexes,
Jamie Madill80d934b2015-02-19 10:16:12 -050030 unsigned int *uniqueCounter);
31 Std140PaddingHelper(const Std140PaddingHelper &other);
32 Std140PaddingHelper &operator=(const Std140PaddingHelper &other);
Jamie Madill8daaba12014-06-13 10:04:33 -040033
34 int elementIndex() const { return mElementIndex; }
35 int prePadding(const TType &type);
36 TString prePaddingString(const TType &type);
37 TString postPaddingString(const TType &type, bool useHLSLRowMajorPacking);
38
39 private:
Jamie Madill33a74bd2014-08-18 15:47:59 -040040 TString next();
41
42 unsigned *mPaddingCounter;
Jamie Madill8daaba12014-06-13 10:04:33 -040043 int mElementIndex;
Jamie Madill80d934b2015-02-19 10:16:12 -050044 const std::map<TString, int> *mStructElementIndexes;
Jamie Madill8daaba12014-06-13 10:04:33 -040045};
46
Jamie Madillf0d10f82015-03-31 12:56:52 -040047class StructureHLSL : angle::NonCopyable
Jamie Madill8daaba12014-06-13 10:04:33 -040048{
49 public:
50 StructureHLSL();
51
52 void addConstructor(const TType &type, const TString &name, const TIntermSequence *parameters);
53 std::string structsHeader() const;
54
55 TString defineQualified(const TStructure &structure, bool useHLSLRowMajorPacking, bool useStd140Packing);
56 static TString defineNameless(const TStructure &structure);
57
Jamie Madill33a74bd2014-08-18 15:47:59 -040058 Std140PaddingHelper getPaddingHelper();
Jamie Madill8daaba12014-06-13 10:04:33 -040059
60 private:
Jamie Madill33a74bd2014-08-18 15:47:59 -040061 unsigned mUniquePaddingCounter;
62
Jamie Madill8daaba12014-06-13 10:04:33 -040063 std::map<TString, int> mStd140StructElementIndexes;
64
65 typedef std::set<TString> StructNames;
66 StructNames mStructNames;
67
68 typedef std::set<TString> Constructors;
69 Constructors mConstructors;
70
71 typedef std::vector<TString> StructDeclarations;
72 StructDeclarations mStructDeclarations;
73
74 void storeStd140ElementIndex(const TStructure &structure, bool useHLSLRowMajorPacking);
75 static TString define(const TStructure &structure, bool useHLSLRowMajorPacking,
76 bool useStd140Packing, Std140PaddingHelper *padHelper);
77};
78
79}
80
Geoff Lang0a73dd82014-11-19 16:18:08 -050081#endif // COMPILER_TRANSLATOR_STRUCTUREHLSL_H_