1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2010 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker
7*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Uniform.h"
8*8975f5c5SAndroid Build Coastguard Worker #include "common/BinaryStream.h"
9*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/ProgramLinkedResources.h"
10*8975f5c5SAndroid Build Coastguard Worker
11*8975f5c5SAndroid Build Coastguard Worker #include <cstring>
12*8975f5c5SAndroid Build Coastguard Worker
13*8975f5c5SAndroid Build Coastguard Worker namespace gl
14*8975f5c5SAndroid Build Coastguard Worker {
15*8975f5c5SAndroid Build Coastguard Worker
LinkedUniform(GLenum typeIn,GLenum precisionIn,const std::vector<unsigned int> & arraySizesIn,const int bindingIn,const int offsetIn,const int locationIn,const int bufferIndexIn,const sh::BlockMemberInfo & blockInfoIn)16*8975f5c5SAndroid Build Coastguard Worker LinkedUniform::LinkedUniform(GLenum typeIn,
17*8975f5c5SAndroid Build Coastguard Worker GLenum precisionIn,
18*8975f5c5SAndroid Build Coastguard Worker const std::vector<unsigned int> &arraySizesIn,
19*8975f5c5SAndroid Build Coastguard Worker const int bindingIn,
20*8975f5c5SAndroid Build Coastguard Worker const int offsetIn,
21*8975f5c5SAndroid Build Coastguard Worker const int locationIn,
22*8975f5c5SAndroid Build Coastguard Worker const int bufferIndexIn,
23*8975f5c5SAndroid Build Coastguard Worker const sh::BlockMemberInfo &blockInfoIn)
24*8975f5c5SAndroid Build Coastguard Worker {
25*8975f5c5SAndroid Build Coastguard Worker // arrays are always flattened, which means at most 1D array
26*8975f5c5SAndroid Build Coastguard Worker ASSERT(arraySizesIn.size() <= 1);
27*8975f5c5SAndroid Build Coastguard Worker
28*8975f5c5SAndroid Build Coastguard Worker memset(this, 0, sizeof(*this));
29*8975f5c5SAndroid Build Coastguard Worker pod.typeIndex = GetUniformTypeIndex(typeIn);
30*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.precision, precisionIn);
31*8975f5c5SAndroid Build Coastguard Worker pod.location = locationIn;
32*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.binding, bindingIn);
33*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.offset, offsetIn);
34*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.bufferIndex, bufferIndexIn);
35*8975f5c5SAndroid Build Coastguard Worker pod.outerArraySizeProduct = 1;
36*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.arraySize, arraySizesIn.empty() ? 1u : arraySizesIn[0]);
37*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.flagBits.isArray, !arraySizesIn.empty());
38*8975f5c5SAndroid Build Coastguard Worker if (!(blockInfoIn == sh::kDefaultBlockMemberInfo))
39*8975f5c5SAndroid Build Coastguard Worker {
40*8975f5c5SAndroid Build Coastguard Worker pod.flagBits.isBlock = 1;
41*8975f5c5SAndroid Build Coastguard Worker pod.flagBits.blockIsRowMajorMatrix = blockInfoIn.isRowMajorMatrix;
42*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.blockOffset, blockInfoIn.offset);
43*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.blockArrayStride, blockInfoIn.arrayStride);
44*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.blockMatrixStride, blockInfoIn.matrixStride);
45*8975f5c5SAndroid Build Coastguard Worker }
46*8975f5c5SAndroid Build Coastguard Worker }
47*8975f5c5SAndroid Build Coastguard Worker
LinkedUniform(const UsedUniform & usedUniform)48*8975f5c5SAndroid Build Coastguard Worker LinkedUniform::LinkedUniform(const UsedUniform &usedUniform)
49*8975f5c5SAndroid Build Coastguard Worker {
50*8975f5c5SAndroid Build Coastguard Worker ASSERT(!usedUniform.isArrayOfArrays());
51*8975f5c5SAndroid Build Coastguard Worker ASSERT(!usedUniform.isStruct());
52*8975f5c5SAndroid Build Coastguard Worker ASSERT(usedUniform.active);
53*8975f5c5SAndroid Build Coastguard Worker ASSERT(usedUniform.blockInfo == sh::kDefaultBlockMemberInfo);
54*8975f5c5SAndroid Build Coastguard Worker
55*8975f5c5SAndroid Build Coastguard Worker // Note: Ensure every data member is initialized.
56*8975f5c5SAndroid Build Coastguard Worker pod.flagBitsAsUByte = 0;
57*8975f5c5SAndroid Build Coastguard Worker pod.typeIndex = GetUniformTypeIndex(usedUniform.type);
58*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.precision, usedUniform.precision);
59*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.imageUnitFormat, usedUniform.imageUnitFormat);
60*8975f5c5SAndroid Build Coastguard Worker pod.location = usedUniform.location;
61*8975f5c5SAndroid Build Coastguard Worker pod.blockOffset = 0;
62*8975f5c5SAndroid Build Coastguard Worker pod.blockArrayStride = 0;
63*8975f5c5SAndroid Build Coastguard Worker pod.blockMatrixStride = 0;
64*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.binding, usedUniform.binding);
65*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.offset, usedUniform.offset);
66*8975f5c5SAndroid Build Coastguard Worker
67*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.bufferIndex, usedUniform.bufferIndex);
68*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.parentArrayIndex, usedUniform.parentArrayIndex());
69*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.outerArraySizeProduct, ArraySizeProduct(usedUniform.outerArraySizes));
70*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.outerArrayOffset, usedUniform.outerArrayOffset);
71*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.arraySize, usedUniform.isArray() ? usedUniform.getArraySizeProduct() : 1u);
72*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.flagBits.isArray, usedUniform.isArray());
73*8975f5c5SAndroid Build Coastguard Worker
74*8975f5c5SAndroid Build Coastguard Worker pod.id = usedUniform.id;
75*8975f5c5SAndroid Build Coastguard Worker pod.activeUseBits = usedUniform.activeVariable.activeShaders();
76*8975f5c5SAndroid Build Coastguard Worker pod.ids = usedUniform.activeVariable.getIds();
77*8975f5c5SAndroid Build Coastguard Worker
78*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.flagBits.isFragmentInOut, usedUniform.isFragmentInOut);
79*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.flagBits.texelFetchStaticUse, usedUniform.texelFetchStaticUse);
80*8975f5c5SAndroid Build Coastguard Worker ASSERT(!usedUniform.isArray() || pod.arraySize == usedUniform.getArraySizeProduct());
81*8975f5c5SAndroid Build Coastguard Worker }
82*8975f5c5SAndroid Build Coastguard Worker
BufferVariable()83*8975f5c5SAndroid Build Coastguard Worker BufferVariable::BufferVariable()
84*8975f5c5SAndroid Build Coastguard Worker {
85*8975f5c5SAndroid Build Coastguard Worker memset(&pod, 0, sizeof(pod));
86*8975f5c5SAndroid Build Coastguard Worker pod.bufferIndex = -1;
87*8975f5c5SAndroid Build Coastguard Worker pod.blockInfo = sh::kDefaultBlockMemberInfo;
88*8975f5c5SAndroid Build Coastguard Worker pod.topLevelArraySize = -1;
89*8975f5c5SAndroid Build Coastguard Worker }
90*8975f5c5SAndroid Build Coastguard Worker
BufferVariable(GLenum type,GLenum precision,const std::string & name,const std::vector<unsigned int> & arraySizes,const int bufferIndex,int topLevelArraySize,const sh::BlockMemberInfo & blockInfo)91*8975f5c5SAndroid Build Coastguard Worker BufferVariable::BufferVariable(GLenum type,
92*8975f5c5SAndroid Build Coastguard Worker GLenum precision,
93*8975f5c5SAndroid Build Coastguard Worker const std::string &name,
94*8975f5c5SAndroid Build Coastguard Worker const std::vector<unsigned int> &arraySizes,
95*8975f5c5SAndroid Build Coastguard Worker const int bufferIndex,
96*8975f5c5SAndroid Build Coastguard Worker int topLevelArraySize,
97*8975f5c5SAndroid Build Coastguard Worker const sh::BlockMemberInfo &blockInfo)
98*8975f5c5SAndroid Build Coastguard Worker : name(name)
99*8975f5c5SAndroid Build Coastguard Worker {
100*8975f5c5SAndroid Build Coastguard Worker memset(&pod, 0, sizeof(pod));
101*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.type, type);
102*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.precision, precision);
103*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.bufferIndex, bufferIndex);
104*8975f5c5SAndroid Build Coastguard Worker pod.blockInfo = blockInfo;
105*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.topLevelArraySize, topLevelArraySize);
106*8975f5c5SAndroid Build Coastguard Worker pod.isArray = !arraySizes.empty();
107*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.basicTypeElementCount, arraySizes.empty() ? 1u : arraySizes.back());
108*8975f5c5SAndroid Build Coastguard Worker }
109*8975f5c5SAndroid Build Coastguard Worker
AtomicCounterBuffer()110*8975f5c5SAndroid Build Coastguard Worker AtomicCounterBuffer::AtomicCounterBuffer()
111*8975f5c5SAndroid Build Coastguard Worker {
112*8975f5c5SAndroid Build Coastguard Worker memset(&pod, 0, sizeof(pod));
113*8975f5c5SAndroid Build Coastguard Worker }
114*8975f5c5SAndroid Build Coastguard Worker
unionReferencesWith(const LinkedUniform & other)115*8975f5c5SAndroid Build Coastguard Worker void AtomicCounterBuffer::unionReferencesWith(const LinkedUniform &other)
116*8975f5c5SAndroid Build Coastguard Worker {
117*8975f5c5SAndroid Build Coastguard Worker pod.activeUseBits |= other.pod.activeUseBits;
118*8975f5c5SAndroid Build Coastguard Worker for (const ShaderType shaderType : AllShaderTypes())
119*8975f5c5SAndroid Build Coastguard Worker {
120*8975f5c5SAndroid Build Coastguard Worker ASSERT(pod.ids[shaderType] == 0 || other.getId(shaderType) == 0 ||
121*8975f5c5SAndroid Build Coastguard Worker pod.ids[shaderType] == other.getId(shaderType));
122*8975f5c5SAndroid Build Coastguard Worker if (pod.ids[shaderType] == 0)
123*8975f5c5SAndroid Build Coastguard Worker {
124*8975f5c5SAndroid Build Coastguard Worker pod.ids[shaderType] = other.getId(shaderType);
125*8975f5c5SAndroid Build Coastguard Worker }
126*8975f5c5SAndroid Build Coastguard Worker }
127*8975f5c5SAndroid Build Coastguard Worker }
128*8975f5c5SAndroid Build Coastguard Worker
InterfaceBlock()129*8975f5c5SAndroid Build Coastguard Worker InterfaceBlock::InterfaceBlock()
130*8975f5c5SAndroid Build Coastguard Worker {
131*8975f5c5SAndroid Build Coastguard Worker memset(&pod, 0, sizeof(pod));
132*8975f5c5SAndroid Build Coastguard Worker }
133*8975f5c5SAndroid Build Coastguard Worker
InterfaceBlock(const std::string & name,const std::string & mappedName,bool isArray,bool isReadOnly,unsigned int arrayElementIn,unsigned int firstFieldArraySizeIn,int binding)134*8975f5c5SAndroid Build Coastguard Worker InterfaceBlock::InterfaceBlock(const std::string &name,
135*8975f5c5SAndroid Build Coastguard Worker const std::string &mappedName,
136*8975f5c5SAndroid Build Coastguard Worker bool isArray,
137*8975f5c5SAndroid Build Coastguard Worker bool isReadOnly,
138*8975f5c5SAndroid Build Coastguard Worker unsigned int arrayElementIn,
139*8975f5c5SAndroid Build Coastguard Worker unsigned int firstFieldArraySizeIn,
140*8975f5c5SAndroid Build Coastguard Worker int binding)
141*8975f5c5SAndroid Build Coastguard Worker : name(name), mappedName(mappedName)
142*8975f5c5SAndroid Build Coastguard Worker {
143*8975f5c5SAndroid Build Coastguard Worker memset(&pod, 0, sizeof(pod));
144*8975f5c5SAndroid Build Coastguard Worker
145*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.isArray, isArray);
146*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.isReadOnly, isReadOnly);
147*8975f5c5SAndroid Build Coastguard Worker SetBitField(pod.inShaderBinding, binding);
148*8975f5c5SAndroid Build Coastguard Worker pod.arrayElement = arrayElementIn;
149*8975f5c5SAndroid Build Coastguard Worker pod.firstFieldArraySize = firstFieldArraySizeIn;
150*8975f5c5SAndroid Build Coastguard Worker }
151*8975f5c5SAndroid Build Coastguard Worker
nameWithArrayIndex() const152*8975f5c5SAndroid Build Coastguard Worker std::string InterfaceBlock::nameWithArrayIndex() const
153*8975f5c5SAndroid Build Coastguard Worker {
154*8975f5c5SAndroid Build Coastguard Worker std::stringstream fullNameStr;
155*8975f5c5SAndroid Build Coastguard Worker fullNameStr << name;
156*8975f5c5SAndroid Build Coastguard Worker if (pod.isArray)
157*8975f5c5SAndroid Build Coastguard Worker {
158*8975f5c5SAndroid Build Coastguard Worker fullNameStr << "[" << pod.arrayElement << "]";
159*8975f5c5SAndroid Build Coastguard Worker }
160*8975f5c5SAndroid Build Coastguard Worker
161*8975f5c5SAndroid Build Coastguard Worker return fullNameStr.str();
162*8975f5c5SAndroid Build Coastguard Worker }
163*8975f5c5SAndroid Build Coastguard Worker
mappedNameWithArrayIndex() const164*8975f5c5SAndroid Build Coastguard Worker std::string InterfaceBlock::mappedNameWithArrayIndex() const
165*8975f5c5SAndroid Build Coastguard Worker {
166*8975f5c5SAndroid Build Coastguard Worker std::stringstream fullNameStr;
167*8975f5c5SAndroid Build Coastguard Worker fullNameStr << mappedName;
168*8975f5c5SAndroid Build Coastguard Worker if (pod.isArray)
169*8975f5c5SAndroid Build Coastguard Worker {
170*8975f5c5SAndroid Build Coastguard Worker fullNameStr << "[" << pod.arrayElement << "]";
171*8975f5c5SAndroid Build Coastguard Worker }
172*8975f5c5SAndroid Build Coastguard Worker
173*8975f5c5SAndroid Build Coastguard Worker return fullNameStr.str();
174*8975f5c5SAndroid Build Coastguard Worker }
175*8975f5c5SAndroid Build Coastguard Worker } // namespace gl
176