Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 1 | // |
| 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 | |
| 12 | namespace sh |
| 13 | { |
| 14 | |
| 15 | HLSLBlockEncoder::HLSLBlockEncoder(std::vector<BlockMemberInfo> *blockInfoOut) |
| 16 | : BlockLayoutEncoder(blockInfoOut) |
| 17 | { |
| 18 | } |
| 19 | |
| 20 | void HLSLBlockEncoder::enterAggregateType() |
| 21 | { |
| 22 | nextRegister(); |
| 23 | } |
| 24 | |
| 25 | void HLSLBlockEncoder::exitAggregateType() |
| 26 | { |
| 27 | } |
| 28 | |
Jamie Madill | 912cbfe | 2013-08-30 13:21:03 -0400 | [diff] [blame^] | 29 | void HLSLBlockEncoder::getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut) |
Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 30 | { |
Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 31 | // We assume we are only dealing with 4 byte components (no doubles or half-words currently) |
Jamie Madill | 912cbfe | 2013-08-30 13:21:03 -0400 | [diff] [blame^] | 32 | ASSERT(gl::UniformComponentSize(gl::UniformComponentType(type)) == ComponentSize); |
Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 33 | |
| 34 | int matrixStride = 0; |
| 35 | int arrayStride = 0; |
| 36 | |
Jamie Madill | 912cbfe | 2013-08-30 13:21:03 -0400 | [diff] [blame^] | 37 | if (gl::IsMatrixType(type)) |
Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 38 | { |
| 39 | nextRegister(); |
| 40 | matrixStride = RegisterSize; |
| 41 | |
Jamie Madill | 912cbfe | 2013-08-30 13:21:03 -0400 | [diff] [blame^] | 42 | if (arraySize > 0) |
Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 43 | { |
Jamie Madill | 912cbfe | 2013-08-30 13:21:03 -0400 | [diff] [blame^] | 44 | const int numRegisters = gl::MatrixRegisterCount(type, isRowMajorMatrix); |
Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 45 | arrayStride = RegisterSize * numRegisters; |
| 46 | } |
| 47 | } |
Jamie Madill | 912cbfe | 2013-08-30 13:21:03 -0400 | [diff] [blame^] | 48 | else if (arraySize > 0) |
Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 49 | { |
| 50 | nextRegister(); |
| 51 | arrayStride = RegisterSize; |
| 52 | } |
| 53 | else |
| 54 | { |
Jamie Madill | 912cbfe | 2013-08-30 13:21:03 -0400 | [diff] [blame^] | 55 | int numComponents = gl::UniformComponentCount(type); |
Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 56 | if ((numComponents + (mCurrentOffset % RegisterSize)) > RegisterSize) |
| 57 | { |
| 58 | nextRegister(); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | *matrixStrideOut = matrixStride; |
| 63 | *arrayStrideOut = arrayStride; |
| 64 | } |
| 65 | |
Jamie Madill | 912cbfe | 2013-08-30 13:21:03 -0400 | [diff] [blame^] | 66 | void HLSLBlockEncoder::advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride) |
Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 67 | { |
Jamie Madill | 912cbfe | 2013-08-30 13:21:03 -0400 | [diff] [blame^] | 68 | if (arraySize > 0) |
Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 69 | { |
Jamie Madill | 912cbfe | 2013-08-30 13:21:03 -0400 | [diff] [blame^] | 70 | mCurrentOffset += arrayStride * (arraySize - 1); |
Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 71 | } |
| 72 | |
Jamie Madill | 912cbfe | 2013-08-30 13:21:03 -0400 | [diff] [blame^] | 73 | if (gl::IsMatrixType(type)) |
Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 74 | { |
| 75 | ASSERT(matrixStride == RegisterSize); |
Jamie Madill | 912cbfe | 2013-08-30 13:21:03 -0400 | [diff] [blame^] | 76 | const int numRegisters = gl::MatrixRegisterCount(type, isRowMajorMatrix); |
| 77 | const int numComponents = gl::MatrixComponentCount(type, isRowMajorMatrix); |
Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 78 | mCurrentOffset += RegisterSize * (numRegisters - 1); |
| 79 | mCurrentOffset += numComponents; |
| 80 | } |
| 81 | else |
| 82 | { |
Jamie Madill | 912cbfe | 2013-08-30 13:21:03 -0400 | [diff] [blame^] | 83 | mCurrentOffset += gl::UniformComponentCount(type); |
Jamie Madill | 440dc74 | 2013-06-20 11:55:55 -0400 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
| 87 | } |