blob: d422732e51f46812bd05ed2e632ec4810bacadb7 [file] [log] [blame]
Jamie Madill440dc742013-06-20 11:55:55 -04001//
2// Copyright (c) 2013 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
7#include "compiler/HLSLLayoutEncoder.h"
8#include "compiler/Uniform.h"
9#include "common/mathutil.h"
10#include "common/utilities.h"
11
12namespace sh
13{
14
15HLSLBlockEncoder::HLSLBlockEncoder(std::vector<BlockMemberInfo> *blockInfoOut)
16 : BlockLayoutEncoder(blockInfoOut)
17{
18}
19
20void HLSLBlockEncoder::enterAggregateType()
21{
22 nextRegister();
23}
24
25void HLSLBlockEncoder::exitAggregateType()
26{
27}
28
29void HLSLBlockEncoder::getBlockLayoutInfo(const sh::Uniform &uniform, int *arrayStrideOut, int *matrixStrideOut)
30{
31 ASSERT(uniform.fields.empty());
32
33 // We assume we are only dealing with 4 byte components (no doubles or half-words currently)
34 ASSERT(gl::UniformComponentSize(gl::UniformComponentType(uniform.type)) == ComponentSize);
35
36 int matrixStride = 0;
37 int arrayStride = 0;
38
39 if (gl::IsMatrixType(uniform.type))
40 {
41 nextRegister();
42 matrixStride = RegisterSize;
43
44 if (uniform.arraySize > 0)
45 {
46 const int numRegisters = gl::MatrixRegisterCount(uniform.type, uniform.isRowMajorMatrix);
47 arrayStride = RegisterSize * numRegisters;
48 }
49 }
50 else if (uniform.arraySize > 0)
51 {
52 nextRegister();
53 arrayStride = RegisterSize;
54 }
55 else
56 {
57 int numComponents = gl::UniformComponentCount(uniform.type);
58 if ((numComponents + (mCurrentOffset % RegisterSize)) > RegisterSize)
59 {
60 nextRegister();
61 }
62 }
63
64 *matrixStrideOut = matrixStride;
65 *arrayStrideOut = arrayStride;
66}
67
68void HLSLBlockEncoder::advanceOffset(const sh::Uniform &uniform, int arrayStride, int matrixStride)
69{
70 if (uniform.arraySize > 0)
71 {
72 mCurrentOffset += arrayStride * (uniform.arraySize - 1);
73 }
74
75 if (gl::IsMatrixType(uniform.type))
76 {
77 ASSERT(matrixStride == RegisterSize);
78 const int numRegisters = gl::MatrixRegisterCount(uniform.type, uniform.isRowMajorMatrix);
79 const int numComponents = gl::MatrixComponentCount(uniform.type, uniform.isRowMajorMatrix);
80 mCurrentOffset += RegisterSize * (numRegisters - 1);
81 mCurrentOffset += numComponents;
82 }
83 else
84 {
85 mCurrentOffset += gl::UniformComponentCount(uniform.type);
86 }
87}
88
89}