blob: c6a320649c14d9c3cf200a1dc69aa90a5075146a [file] [log] [blame]
gman@chromium.org8d804792012-10-17 21:33:48 +00001//
2// Copyright (c) 2002-2012 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
Geoff Lang0a73dd82014-11-19 16:18:08 -05007#ifndef COMPILER_TRANSLATOR_VARIABLEPACKER_H_
8#define COMPILER_TRANSLATOR_VARIABLEPACKER_H_
gman@chromium.org8d804792012-10-17 21:33:48 +00009
10#include <vector>
Jamie Madilld4a3a312014-06-25 16:04:56 -040011#include "compiler/translator/VariableInfo.h"
gman@chromium.org8d804792012-10-17 21:33:48 +000012
Jamie Madilld7b1ab52016-12-12 14:42:19 -050013class VariablePacker
14{
15 public:
16 // Returns true if the passed in variables pack in maxVectors following
17 // the packing rules from the GLSL 1.017 spec, Appendix A, section 7.
18 bool CheckVariablesWithinPackingLimits(unsigned int maxVectors,
19 const std::vector<sh::ShaderVariable> &in_variables);
gman@chromium.org8d804792012-10-17 21:33:48 +000020
Jamie Madilld7b1ab52016-12-12 14:42:19 -050021 // Gets how many components in a row a data type takes.
22 static int GetNumComponentsPerRow(sh::GLenum type);
gman@chromium.org8d804792012-10-17 21:33:48 +000023
Jamie Madilld7b1ab52016-12-12 14:42:19 -050024 // Gets how many rows a data type takes.
25 static int GetNumRows(sh::GLenum type);
gman@chromium.org8d804792012-10-17 21:33:48 +000026
Jamie Madilld7b1ab52016-12-12 14:42:19 -050027 private:
28 static const int kNumColumns = 4;
29 static const unsigned kColumnMask = (1 << kNumColumns) - 1;
gman@chromium.org8d804792012-10-17 21:33:48 +000030
Jamie Madilld7b1ab52016-12-12 14:42:19 -050031 unsigned makeColumnFlags(int column, int numComponentsPerRow);
32 void fillColumns(int topRow, int numRows, int column, int numComponentsPerRow);
33 bool searchColumn(int column, int numRows, int *destRow, int *destSize);
gman@chromium.org8d804792012-10-17 21:33:48 +000034
Jamie Madilld7b1ab52016-12-12 14:42:19 -050035 int topNonFullRow_;
36 int bottomNonFullRow_;
37 int maxRows_;
38 std::vector<unsigned> rows_;
gman@chromium.org8d804792012-10-17 21:33:48 +000039};
40
Jamie Madilld7b1ab52016-12-12 14:42:19 -050041#endif // COMPILER_TRANSLATOR_VARIABLEPACKER_H_