webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
blocklayout.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2013-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 // blocklayout.h:
7 // Methods and classes related to uniform layout and packing in GLSL and HLSL.
8 //
9 
10 #ifndef COMMON_BLOCKLAYOUT_H_
11 #define COMMON_BLOCKLAYOUT_H_
12 
13 #include <cstddef>
14 #include <vector>
15 
16 #include "angle_gl.h"
17 #include <GLSLANG/ShaderLang.h>
18 
19 namespace sh
20 {
21 struct ShaderVariable;
22 struct InterfaceBlockField;
23 struct Uniform;
24 struct Varying;
25 struct InterfaceBlock;
26 
28 {
29  BlockMemberInfo() : offset(-1), arrayStride(-1), matrixStride(-1), isRowMajorMatrix(false) {}
30 
31  BlockMemberInfo(int offset, int arrayStride, int matrixStride, bool isRowMajorMatrix)
32  : offset(offset),
33  arrayStride(arrayStride),
34  matrixStride(matrixStride),
35  isRowMajorMatrix(isRowMajorMatrix)
36  {}
37 
39  {
40  return BlockMemberInfo(-1, -1, -1, false);
41  }
42 
43  int offset;
47 };
48 
50 {
51  public:
53  virtual ~BlockLayoutEncoder() {}
54 
55  BlockMemberInfo encodeType(GLenum type, unsigned int arraySize, bool isRowMajorMatrix);
56 
57  size_t getBlockSize() const { return mCurrentOffset * BytesPerComponent; }
58 
59  virtual void enterAggregateType() = 0;
60  virtual void exitAggregateType() = 0;
61 
62  static const size_t BytesPerComponent = 4u;
63  static const unsigned int ComponentsPerRegister = 4u;
64 
65  static size_t getBlockRegister(const BlockMemberInfo &info);
66  static size_t getBlockRegisterElement(const BlockMemberInfo &info);
67 
68  protected:
70 
71  void nextRegister();
72 
73  virtual void getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut) = 0;
74  virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride) = 0;
75 };
76 
77 // Block layout according to the std140 block layout
78 // See "Standard Uniform Block Layout" in Section 2.11.6 of the OpenGL ES 3.0 specification
79 
81 {
82  public:
84 
85  void enterAggregateType() override;
86  void exitAggregateType() override;
87 
88  protected:
89  void getBlockLayoutInfo(GLenum type,
90  unsigned int arraySize,
91  bool isRowMajorMatrix,
92  int *arrayStrideOut,
93  int *matrixStrideOut) override;
94  void advanceOffset(GLenum type,
95  unsigned int arraySize,
96  bool isRowMajorMatrix,
97  int arrayStride,
98  int matrixStride) override;
99 };
100 
101 }
102 
103 #endif // COMMON_BLOCKLAYOUT_H_
#define COMPILER_EXPORT
Definition: ShaderLang.h:23
static BlockMemberInfo getDefaultBlockInfo()
Definition: blocklayout.h:38
OPENSSL_EXPORT pem_password_cb void * u
Definition: pem.h:398
virtual ~BlockLayoutEncoder()
Definition: blocklayout.h:53
size_t mCurrentOffset
Definition: blocklayout.h:69
def info(msg, args, kwargs)
Definition: __init__.py:1165
int matrixStride
Definition: blocklayout.h:45
bool isRowMajorMatrix
Definition: blocklayout.h:46
EGLStreamKHR EGLint EGLint offset
Definition: eglext.h:984
size_t getBlockSize() const
Definition: blocklayout.h:57
BlockMemberInfo()
Definition: blocklayout.h:29
Definition: ShaderLang.h:40
int offset
Definition: blocklayout.h:43
Definition: blocklayout.h:49
Definition: blocklayout.h:27
BlockMemberInfo(int offset, int arrayStride, int matrixStride, bool isRowMajorMatrix)
Definition: blocklayout.h:31
int arrayStride
Definition: blocklayout.h:44
EGLenum type
Definition: eglext.h:63
unsigned int GLenum
Definition: ShaderLang.h:43
#define false
Definition: float-mm.c:5
Definition: blocklayout.h:80