Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <GLES2/gl2.h> |
| 18 | #include <GLES2/gl2ext.h> |
| 19 | |
| 20 | #include <rs_hal.h> |
| 21 | #include <rsContext.h> |
| 22 | #include <rsProgram.h> |
| 23 | |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 24 | #include "rsdCore.h" |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 25 | #include "rsdAllocation.h" |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 26 | #include "rsdShader.h" |
| 27 | #include "rsdShaderCache.h" |
| 28 | |
| 29 | using namespace android; |
| 30 | using namespace android::renderscript; |
| 31 | |
| 32 | RsdShader::RsdShader(const Program *p, uint32_t type, |
| 33 | const char * shaderText, uint32_t shaderLength) { |
| 34 | |
| 35 | mUserShader.setTo(shaderText, shaderLength); |
| 36 | mRSProgram = p; |
| 37 | mType = type; |
| 38 | initMemberVars(); |
| 39 | initAttribAndUniformArray(); |
| 40 | init(); |
| 41 | } |
| 42 | |
| 43 | RsdShader::~RsdShader() { |
| 44 | if (mShaderID) { |
| 45 | glDeleteShader(mShaderID); |
| 46 | } |
| 47 | |
| 48 | delete[] mAttribNames; |
| 49 | delete[] mUniformNames; |
| 50 | delete[] mUniformArraySizes; |
Alex Sakhartchouk | ba15730 | 2011-08-05 15:27:25 -0700 | [diff] [blame] | 51 | delete[] mTextureTargets; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | void RsdShader::initMemberVars() { |
| 55 | mDirty = true; |
| 56 | mShaderID = 0; |
| 57 | mAttribCount = 0; |
| 58 | mUniformCount = 0; |
| 59 | |
| 60 | mAttribNames = NULL; |
| 61 | mUniformNames = NULL; |
| 62 | mUniformArraySizes = NULL; |
Alex Sakhartchouk | ba15730 | 2011-08-05 15:27:25 -0700 | [diff] [blame] | 63 | mTextureTargets = NULL; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 64 | |
| 65 | mIsValid = false; |
| 66 | } |
| 67 | |
| 68 | void RsdShader::init() { |
| 69 | uint32_t attribCount = 0; |
| 70 | uint32_t uniformCount = 0; |
| 71 | for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) { |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 72 | initAddUserElement(mRSProgram->mHal.state.inputElements[ct], mAttribNames, NULL, &attribCount, RS_SHADER_ATTR); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 73 | } |
| 74 | for (uint32_t ct=0; ct < mRSProgram->mHal.state.constantsCount; ct++) { |
| 75 | initAddUserElement(mRSProgram->mHal.state.constantTypes[ct]->getElement(), mUniformNames, mUniformArraySizes, &uniformCount, RS_SHADER_UNI); |
| 76 | } |
| 77 | |
| 78 | mTextureUniformIndexStart = uniformCount; |
| 79 | char buf[256]; |
| 80 | for (uint32_t ct=0; ct < mRSProgram->mHal.state.texturesCount; ct++) { |
| 81 | snprintf(buf, sizeof(buf), "UNI_Tex%i", ct); |
| 82 | mUniformNames[uniformCount].setTo(buf); |
| 83 | mUniformArraySizes[uniformCount] = 1; |
| 84 | uniformCount++; |
| 85 | } |
Alex Sakhartchouk | ba15730 | 2011-08-05 15:27:25 -0700 | [diff] [blame] | 86 | |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | String8 RsdShader::getGLSLInputString() const { |
| 90 | String8 s; |
| 91 | for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) { |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 92 | const Element *e = mRSProgram->mHal.state.inputElements[ct]; |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 93 | for (uint32_t field=0; field < e->mHal.state.fieldsCount; field++) { |
| 94 | const Element *f = e->mHal.state.fields[field]; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 95 | |
| 96 | // Cannot be complex |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 97 | rsAssert(!f->mHal.state.fieldsCount); |
| 98 | switch (f->mHal.state.vectorSize) { |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 99 | case 1: s.append("attribute float ATTRIB_"); break; |
| 100 | case 2: s.append("attribute vec2 ATTRIB_"); break; |
| 101 | case 3: s.append("attribute vec3 ATTRIB_"); break; |
| 102 | case 4: s.append("attribute vec4 ATTRIB_"); break; |
| 103 | default: |
| 104 | rsAssert(0); |
| 105 | } |
| 106 | |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 107 | s.append(e->mHal.state.fieldNames[field]); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 108 | s.append(";\n"); |
| 109 | } |
| 110 | } |
| 111 | return s; |
| 112 | } |
| 113 | |
| 114 | void RsdShader::appendAttributes() { |
| 115 | for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) { |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 116 | const Element *e = mRSProgram->mHal.state.inputElements[ct]; |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 117 | for (uint32_t field=0; field < e->mHal.state.fieldsCount; field++) { |
| 118 | const Element *f = e->mHal.state.fields[field]; |
| 119 | const char *fn = e->mHal.state.fieldNames[field]; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 120 | |
| 121 | // Cannot be complex |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 122 | rsAssert(!f->mHal.state.fieldsCount); |
| 123 | switch (f->mHal.state.vectorSize) { |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 124 | case 1: mShader.append("attribute float ATTRIB_"); break; |
| 125 | case 2: mShader.append("attribute vec2 ATTRIB_"); break; |
| 126 | case 3: mShader.append("attribute vec3 ATTRIB_"); break; |
| 127 | case 4: mShader.append("attribute vec4 ATTRIB_"); break; |
| 128 | default: |
| 129 | rsAssert(0); |
| 130 | } |
| 131 | |
| 132 | mShader.append(fn); |
| 133 | mShader.append(";\n"); |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | void RsdShader::appendTextures() { |
| 139 | char buf[256]; |
| 140 | for (uint32_t ct=0; ct < mRSProgram->mHal.state.texturesCount; ct++) { |
| 141 | if (mRSProgram->mHal.state.textureTargets[ct] == RS_TEXTURE_2D) { |
Jason Sams | 41e373d | 2012-01-13 14:01:20 -0800 | [diff] [blame^] | 142 | Allocation *a = mRSProgram->mHal.state.textures[ct]; |
| 143 | if (a && a->mHal.state.surfaceTextureID) { |
| 144 | snprintf(buf, sizeof(buf), "uniform samplerExternalOES UNI_Tex%i;\n", ct); |
| 145 | } else { |
| 146 | snprintf(buf, sizeof(buf), "uniform sampler2D UNI_Tex%i;\n", ct); |
| 147 | } |
Alex Sakhartchouk | ba15730 | 2011-08-05 15:27:25 -0700 | [diff] [blame] | 148 | mTextureTargets[ct] = GL_TEXTURE_2D; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 149 | } else { |
| 150 | snprintf(buf, sizeof(buf), "uniform samplerCube UNI_Tex%i;\n", ct); |
Alex Sakhartchouk | ba15730 | 2011-08-05 15:27:25 -0700 | [diff] [blame] | 151 | mTextureTargets[ct] = GL_TEXTURE_CUBE_MAP; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 152 | } |
| 153 | mShader.append(buf); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | bool RsdShader::createShader() { |
| 158 | |
| 159 | if (mType == GL_FRAGMENT_SHADER) { |
| 160 | mShader.append("precision mediump float;\n"); |
| 161 | } |
| 162 | appendUserConstants(); |
| 163 | appendAttributes(); |
| 164 | appendTextures(); |
| 165 | |
| 166 | mShader.append(mUserShader); |
| 167 | |
| 168 | return true; |
| 169 | } |
| 170 | |
| 171 | bool RsdShader::loadShader(const Context *rsc) { |
| 172 | mShaderID = glCreateShader(mType); |
| 173 | rsAssert(mShaderID); |
| 174 | |
| 175 | if (rsc->props.mLogShaders) { |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 176 | ALOGV("Loading shader type %x, ID %i", mType, mShaderID); |
| 177 | ALOGV("%s", mShader.string()); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | if (mShaderID) { |
| 181 | const char * ss = mShader.string(); |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 182 | RSD_CALL_GL(glShaderSource, mShaderID, 1, &ss, NULL); |
| 183 | RSD_CALL_GL(glCompileShader, mShaderID); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 184 | |
| 185 | GLint compiled = 0; |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 186 | RSD_CALL_GL(glGetShaderiv, mShaderID, GL_COMPILE_STATUS, &compiled); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 187 | if (!compiled) { |
| 188 | GLint infoLen = 0; |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 189 | RSD_CALL_GL(glGetShaderiv, mShaderID, GL_INFO_LOG_LENGTH, &infoLen); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 190 | if (infoLen) { |
| 191 | char* buf = (char*) malloc(infoLen); |
| 192 | if (buf) { |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 193 | RSD_CALL_GL(glGetShaderInfoLog, mShaderID, infoLen, NULL, buf); |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 194 | ALOGE("Could not compile shader \n%s\n", buf); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 195 | free(buf); |
| 196 | } |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 197 | RSD_CALL_GL(glDeleteShader, mShaderID); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 198 | mShaderID = 0; |
| 199 | rsc->setError(RS_ERROR_BAD_SHADER, "Error returned from GL driver loading shader text,"); |
| 200 | return false; |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | if (rsc->props.mLogShaders) { |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 206 | ALOGV("--Shader load result %x ", glGetError()); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 207 | } |
| 208 | mIsValid = true; |
| 209 | return true; |
| 210 | } |
| 211 | |
| 212 | void RsdShader::appendUserConstants() { |
| 213 | for (uint32_t ct=0; ct < mRSProgram->mHal.state.constantsCount; ct++) { |
| 214 | const Element *e = mRSProgram->mHal.state.constantTypes[ct]->getElement(); |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 215 | for (uint32_t field=0; field < e->mHal.state.fieldsCount; field++) { |
| 216 | const Element *f = e->mHal.state.fields[field]; |
| 217 | const char *fn = e->mHal.state.fieldNames[field]; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 218 | |
| 219 | // Cannot be complex |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 220 | rsAssert(!f->mHal.state.fieldsCount); |
| 221 | if (f->mHal.state.dataType == RS_TYPE_MATRIX_4X4) { |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 222 | mShader.append("uniform mat4 UNI_"); |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 223 | } else if (f->mHal.state.dataType == RS_TYPE_MATRIX_3X3) { |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 224 | mShader.append("uniform mat3 UNI_"); |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 225 | } else if (f->mHal.state.dataType == RS_TYPE_MATRIX_2X2) { |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 226 | mShader.append("uniform mat2 UNI_"); |
| 227 | } else { |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 228 | switch (f->mHal.state.vectorSize) { |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 229 | case 1: mShader.append("uniform float UNI_"); break; |
| 230 | case 2: mShader.append("uniform vec2 UNI_"); break; |
| 231 | case 3: mShader.append("uniform vec3 UNI_"); break; |
| 232 | case 4: mShader.append("uniform vec4 UNI_"); break; |
| 233 | default: |
| 234 | rsAssert(0); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | mShader.append(fn); |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 239 | if (e->mHal.state.fieldArraySizes[field] > 1) { |
| 240 | mShader.appendFormat("[%d]", e->mHal.state.fieldArraySizes[field]); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 241 | } |
| 242 | mShader.append(";\n"); |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | void RsdShader::logUniform(const Element *field, const float *fd, uint32_t arraySize ) { |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 248 | RsDataType dataType = field->mHal.state.dataType; |
| 249 | uint32_t elementSize = field->mHal.state.elementSizeBytes / sizeof(float); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 250 | for (uint32_t i = 0; i < arraySize; i ++) { |
| 251 | if (arraySize > 1) { |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 252 | ALOGV("Array Element [%u]", i); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 253 | } |
| 254 | if (dataType == RS_TYPE_MATRIX_4X4) { |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 255 | ALOGV("Matrix4x4"); |
| 256 | ALOGV("{%f, %f, %f, %f", fd[0], fd[4], fd[8], fd[12]); |
| 257 | ALOGV(" %f, %f, %f, %f", fd[1], fd[5], fd[9], fd[13]); |
| 258 | ALOGV(" %f, %f, %f, %f", fd[2], fd[6], fd[10], fd[14]); |
| 259 | ALOGV(" %f, %f, %f, %f}", fd[3], fd[7], fd[11], fd[15]); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 260 | } else if (dataType == RS_TYPE_MATRIX_3X3) { |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 261 | ALOGV("Matrix3x3"); |
| 262 | ALOGV("{%f, %f, %f", fd[0], fd[3], fd[6]); |
| 263 | ALOGV(" %f, %f, %f", fd[1], fd[4], fd[7]); |
| 264 | ALOGV(" %f, %f, %f}", fd[2], fd[5], fd[8]); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 265 | } else if (dataType == RS_TYPE_MATRIX_2X2) { |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 266 | ALOGV("Matrix2x2"); |
| 267 | ALOGV("{%f, %f", fd[0], fd[2]); |
| 268 | ALOGV(" %f, %f}", fd[1], fd[3]); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 269 | } else { |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 270 | switch (field->mHal.state.vectorSize) { |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 271 | case 1: |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 272 | ALOGV("Uniform 1 = %f", fd[0]); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 273 | break; |
| 274 | case 2: |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 275 | ALOGV("Uniform 2 = %f %f", fd[0], fd[1]); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 276 | break; |
| 277 | case 3: |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 278 | ALOGV("Uniform 3 = %f %f %f", fd[0], fd[1], fd[2]); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 279 | break; |
| 280 | case 4: |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 281 | ALOGV("Uniform 4 = %f %f %f %f", fd[0], fd[1], fd[2], fd[3]); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 282 | break; |
| 283 | default: |
| 284 | rsAssert(0); |
| 285 | } |
| 286 | } |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 287 | ALOGE("Element size %u data=%p", elementSize, fd); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 288 | fd += elementSize; |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 289 | ALOGE("New data=%p", fd); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
| 293 | void RsdShader::setUniform(const Context *rsc, const Element *field, const float *fd, |
| 294 | int32_t slot, uint32_t arraySize ) { |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 295 | RsDataType dataType = field->mHal.state.dataType; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 296 | if (dataType == RS_TYPE_MATRIX_4X4) { |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 297 | RSD_CALL_GL(glUniformMatrix4fv, slot, arraySize, GL_FALSE, fd); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 298 | } else if (dataType == RS_TYPE_MATRIX_3X3) { |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 299 | RSD_CALL_GL(glUniformMatrix3fv, slot, arraySize, GL_FALSE, fd); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 300 | } else if (dataType == RS_TYPE_MATRIX_2X2) { |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 301 | RSD_CALL_GL(glUniformMatrix2fv, slot, arraySize, GL_FALSE, fd); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 302 | } else { |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 303 | switch (field->mHal.state.vectorSize) { |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 304 | case 1: |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 305 | RSD_CALL_GL(glUniform1fv, slot, arraySize, fd); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 306 | break; |
| 307 | case 2: |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 308 | RSD_CALL_GL(glUniform2fv, slot, arraySize, fd); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 309 | break; |
| 310 | case 3: |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 311 | RSD_CALL_GL(glUniform3fv, slot, arraySize, fd); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 312 | break; |
| 313 | case 4: |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 314 | RSD_CALL_GL(glUniform4fv, slot, arraySize, fd); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 315 | break; |
| 316 | default: |
| 317 | rsAssert(0); |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 322 | void RsdShader::setupSampler(const Context *rsc, const Sampler *s, const Allocation *tex) { |
| 323 | RsdHal *dc = (RsdHal *)rsc->mHal.drv; |
| 324 | |
| 325 | GLenum trans[] = { |
| 326 | GL_NEAREST, //RS_SAMPLER_NEAREST, |
| 327 | GL_LINEAR, //RS_SAMPLER_LINEAR, |
| 328 | GL_LINEAR_MIPMAP_LINEAR, //RS_SAMPLER_LINEAR_MIP_LINEAR, |
| 329 | GL_REPEAT, //RS_SAMPLER_WRAP, |
| 330 | GL_CLAMP_TO_EDGE, //RS_SAMPLER_CLAMP |
| 331 | GL_LINEAR_MIPMAP_NEAREST, //RS_SAMPLER_LINEAR_MIP_NEAREST |
| 332 | }; |
| 333 | |
| 334 | GLenum transNP[] = { |
| 335 | GL_NEAREST, //RS_SAMPLER_NEAREST, |
| 336 | GL_LINEAR, //RS_SAMPLER_LINEAR, |
| 337 | GL_LINEAR, //RS_SAMPLER_LINEAR_MIP_LINEAR, |
| 338 | GL_CLAMP_TO_EDGE, //RS_SAMPLER_WRAP, |
| 339 | GL_CLAMP_TO_EDGE, //RS_SAMPLER_CLAMP |
| 340 | GL_LINEAR, //RS_SAMPLER_LINEAR_MIP_NEAREST, |
| 341 | }; |
| 342 | |
| 343 | // This tells us the correct texture type |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 344 | DrvAllocation *drvTex = (DrvAllocation *)tex->mHal.drv; |
| 345 | const GLenum target = drvTex->glTarget; |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 346 | |
| 347 | if (!dc->gl.gl.OES_texture_npot && tex->getType()->getIsNp2()) { |
| 348 | if (tex->getHasGraphicsMipmaps() && |
| 349 | (dc->gl.gl.GL_NV_texture_npot_2D_mipmap || dc->gl.gl.GL_IMG_texture_npot)) { |
| 350 | if (dc->gl.gl.GL_NV_texture_npot_2D_mipmap) { |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 351 | RSD_CALL_GL(glTexParameteri, target, GL_TEXTURE_MIN_FILTER, |
| 352 | trans[s->mHal.state.minFilter]); |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 353 | } else { |
| 354 | switch (trans[s->mHal.state.minFilter]) { |
| 355 | case GL_LINEAR_MIPMAP_LINEAR: |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 356 | RSD_CALL_GL(glTexParameteri, target, GL_TEXTURE_MIN_FILTER, |
| 357 | GL_LINEAR_MIPMAP_NEAREST); |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 358 | break; |
| 359 | default: |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 360 | RSD_CALL_GL(glTexParameteri, target, GL_TEXTURE_MIN_FILTER, |
| 361 | trans[s->mHal.state.minFilter]); |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 362 | break; |
| 363 | } |
| 364 | } |
| 365 | } else { |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 366 | RSD_CALL_GL(glTexParameteri, target, GL_TEXTURE_MIN_FILTER, |
| 367 | transNP[s->mHal.state.minFilter]); |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 368 | } |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 369 | RSD_CALL_GL(glTexParameteri, target, GL_TEXTURE_MAG_FILTER, |
| 370 | transNP[s->mHal.state.magFilter]); |
| 371 | RSD_CALL_GL(glTexParameteri, target, GL_TEXTURE_WRAP_S, transNP[s->mHal.state.wrapS]); |
| 372 | RSD_CALL_GL(glTexParameteri, target, GL_TEXTURE_WRAP_T, transNP[s->mHal.state.wrapT]); |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 373 | } else { |
| 374 | if (tex->getHasGraphicsMipmaps()) { |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 375 | RSD_CALL_GL(glTexParameteri, target, GL_TEXTURE_MIN_FILTER, |
| 376 | trans[s->mHal.state.minFilter]); |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 377 | } else { |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 378 | RSD_CALL_GL(glTexParameteri, target, GL_TEXTURE_MIN_FILTER, |
| 379 | transNP[s->mHal.state.minFilter]); |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 380 | } |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 381 | RSD_CALL_GL(glTexParameteri, target, GL_TEXTURE_MAG_FILTER, trans[s->mHal.state.magFilter]); |
| 382 | RSD_CALL_GL(glTexParameteri, target, GL_TEXTURE_WRAP_S, trans[s->mHal.state.wrapS]); |
| 383 | RSD_CALL_GL(glTexParameteri, target, GL_TEXTURE_WRAP_T, trans[s->mHal.state.wrapT]); |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | float anisoValue = rsMin(dc->gl.gl.EXT_texture_max_aniso, s->mHal.state.aniso); |
| 387 | if (dc->gl.gl.EXT_texture_max_aniso > 1.0f) { |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 388 | RSD_CALL_GL(glTexParameterf, target, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisoValue); |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Alex Sakhartchouk | c19ff01 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 391 | rsdGLCheckError(rsc, "Sampler::setup tex env"); |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 394 | void RsdShader::setupTextures(const Context *rsc, RsdShaderCache *sc) { |
| 395 | if (mRSProgram->mHal.state.texturesCount == 0) { |
| 396 | return; |
| 397 | } |
| 398 | |
Alex Sakhartchouk | c19ff01 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 399 | RsdHal *dc = (RsdHal *)rsc->mHal.drv; |
| 400 | |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 401 | uint32_t numTexturesToBind = mRSProgram->mHal.state.texturesCount; |
Alex Sakhartchouk | c19ff01 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 402 | uint32_t numTexturesAvailable = dc->gl.gl.maxFragmentTextureImageUnits; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 403 | if (numTexturesToBind >= numTexturesAvailable) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 404 | ALOGE("Attempting to bind %u textures on shader id %u, but only %u are available", |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 405 | mRSProgram->mHal.state.texturesCount, (uint32_t)this, numTexturesAvailable); |
| 406 | rsc->setError(RS_ERROR_BAD_SHADER, "Cannot bind more textuers than available"); |
| 407 | numTexturesToBind = numTexturesAvailable; |
| 408 | } |
| 409 | |
| 410 | for (uint32_t ct=0; ct < numTexturesToBind; ct++) { |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 411 | RSD_CALL_GL(glActiveTexture, GL_TEXTURE0 + ct); |
| 412 | RSD_CALL_GL(glUniform1i, sc->fragUniformSlot(mTextureUniformIndexStart + ct), ct); |
Alex Sakhartchouk | ba15730 | 2011-08-05 15:27:25 -0700 | [diff] [blame] | 413 | |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 414 | if (!mRSProgram->mHal.state.textures[ct]) { |
Alex Sakhartchouk | ba15730 | 2011-08-05 15:27:25 -0700 | [diff] [blame] | 415 | // if nothing is bound, reset to default GL texture |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 416 | RSD_CALL_GL(glBindTexture, mTextureTargets[ct], 0); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 417 | continue; |
| 418 | } |
| 419 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 420 | DrvAllocation *drvTex = (DrvAllocation *)mRSProgram->mHal.state.textures[ct]->mHal.drv; |
| 421 | if (drvTex->glTarget != GL_TEXTURE_2D && drvTex->glTarget != GL_TEXTURE_CUBE_MAP) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 422 | ALOGE("Attempting to bind unknown texture to shader id %u, texture unit %u", (uint)this, ct); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 423 | rsc->setError(RS_ERROR_BAD_SHADER, "Non-texture allocation bound to a shader"); |
| 424 | } |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 425 | RSD_CALL_GL(glBindTexture, drvTex->glTarget, drvTex->textureID); |
Alex Sakhartchouk | c19ff01 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 426 | rsdGLCheckError(rsc, "ProgramFragment::setup tex bind"); |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 427 | if (mRSProgram->mHal.state.samplers[ct]) { |
| 428 | setupSampler(rsc, mRSProgram->mHal.state.samplers[ct], |
| 429 | mRSProgram->mHal.state.textures[ct]); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 430 | } else { |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 431 | RSD_CALL_GL(glTexParameteri, drvTex->glTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 432 | RSD_CALL_GL(glTexParameteri, drvTex->glTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 433 | RSD_CALL_GL(glTexParameteri, drvTex->glTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 434 | RSD_CALL_GL(glTexParameteri, drvTex->glTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
Alex Sakhartchouk | c19ff01 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 435 | rsdGLCheckError(rsc, "ProgramFragment::setup tex env"); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 436 | } |
Alex Sakhartchouk | c19ff01 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 437 | rsdGLCheckError(rsc, "ProgramFragment::setup uniforms"); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 440 | RSD_CALL_GL(glActiveTexture, GL_TEXTURE0); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 441 | mDirty = false; |
Alex Sakhartchouk | c19ff01 | 2011-05-06 14:59:45 -0700 | [diff] [blame] | 442 | rsdGLCheckError(rsc, "ProgramFragment::setup"); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | void RsdShader::setupUserConstants(const Context *rsc, RsdShaderCache *sc, bool isFragment) { |
| 446 | uint32_t uidx = 0; |
| 447 | for (uint32_t ct=0; ct < mRSProgram->mHal.state.constantsCount; ct++) { |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 448 | Allocation *alloc = mRSProgram->mHal.state.constants[ct]; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 449 | if (!alloc) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 450 | ALOGE("Attempting to set constants on shader id %u, but alloc at slot %u is not set", |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 451 | (uint32_t)this, ct); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 452 | rsc->setError(RS_ERROR_BAD_SHADER, "No constant allocation bound"); |
| 453 | continue; |
| 454 | } |
| 455 | |
| 456 | const uint8_t *data = static_cast<const uint8_t *>(alloc->getPtr()); |
| 457 | const Element *e = mRSProgram->mHal.state.constantTypes[ct]->getElement(); |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 458 | for (uint32_t field=0; field < e->mHal.state.fieldsCount; field++) { |
| 459 | const Element *f = e->mHal.state.fields[field]; |
| 460 | const char *fieldName = e->mHal.state.fieldNames[field]; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 461 | |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 462 | uint32_t offset = e->mHal.state.fieldOffsetBytes[field]; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 463 | const float *fd = reinterpret_cast<const float *>(&data[offset]); |
| 464 | |
| 465 | int32_t slot = -1; |
| 466 | uint32_t arraySize = 1; |
| 467 | if (!isFragment) { |
| 468 | slot = sc->vtxUniformSlot(uidx); |
| 469 | arraySize = sc->vtxUniformSize(uidx); |
| 470 | } else { |
| 471 | slot = sc->fragUniformSlot(uidx); |
| 472 | arraySize = sc->fragUniformSize(uidx); |
| 473 | } |
| 474 | if (rsc->props.mLogShadersUniforms) { |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 475 | ALOGV("Uniform slot=%i, offset=%i, constant=%i, field=%i, uidx=%i, name=%s", |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 476 | slot, offset, ct, field, uidx, fieldName); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 477 | } |
| 478 | uidx ++; |
| 479 | if (slot < 0) { |
| 480 | continue; |
| 481 | } |
| 482 | |
| 483 | if (rsc->props.mLogShadersUniforms) { |
| 484 | logUniform(f, fd, arraySize); |
| 485 | } |
| 486 | setUniform(rsc, f, fd, slot, arraySize); |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | void RsdShader::setup(const android::renderscript::Context *rsc, RsdShaderCache *sc) { |
| 492 | |
| 493 | setupUserConstants(rsc, sc, mType == GL_FRAGMENT_SHADER); |
| 494 | setupTextures(rsc, sc); |
| 495 | } |
| 496 | |
| 497 | void RsdShader::initAttribAndUniformArray() { |
| 498 | mAttribCount = 0; |
| 499 | for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) { |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 500 | const Element *elem = mRSProgram->mHal.state.inputElements[ct]; |
Alex Sakhartchouk | c0a6542 | 2012-01-05 14:55:11 -0800 | [diff] [blame] | 501 | mAttribCount += elem->mHal.state.fieldsCount; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | mUniformCount = 0; |
| 505 | for (uint32_t ct=0; ct < mRSProgram->mHal.state.constantsCount; ct++) { |
| 506 | const Element *elem = mRSProgram->mHal.state.constantTypes[ct]->getElement(); |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 507 | mUniformCount += elem->mHal.state.fieldsCount; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 508 | } |
| 509 | mUniformCount += mRSProgram->mHal.state.texturesCount; |
| 510 | |
| 511 | if (mAttribCount) { |
| 512 | mAttribNames = new String8[mAttribCount]; |
| 513 | } |
| 514 | if (mUniformCount) { |
| 515 | mUniformNames = new String8[mUniformCount]; |
| 516 | mUniformArraySizes = new uint32_t[mUniformCount]; |
| 517 | } |
Alex Sakhartchouk | ba15730 | 2011-08-05 15:27:25 -0700 | [diff] [blame] | 518 | |
| 519 | mTextureCount = mRSProgram->mHal.state.texturesCount; |
| 520 | if (mTextureCount) { |
| 521 | mTextureTargets = new uint32_t[mTextureCount]; |
| 522 | } |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Jason Sams | 2382aba | 2011-09-13 15:41:01 -0700 | [diff] [blame] | 525 | void RsdShader::initAddUserElement(const Element *e, String8 *names, uint32_t *arrayLengths, |
| 526 | uint32_t *count, const char *prefix) { |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 527 | rsAssert(e->mHal.state.fieldsCount); |
| 528 | for (uint32_t ct=0; ct < e->mHal.state.fieldsCount; ct++) { |
| 529 | const Element *ce = e->mHal.state.fields[ct]; |
| 530 | if (ce->mHal.state.fieldsCount) { |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 531 | initAddUserElement(ce, names, arrayLengths, count, prefix); |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 532 | } else { |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 533 | String8 tmp(prefix); |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 534 | tmp.append(e->mHal.state.fieldNames[ct]); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 535 | names[*count].setTo(tmp.string()); |
| 536 | if (arrayLengths) { |
Alex Sakhartchouk | 4a43e3e | 2011-12-28 13:47:05 -0800 | [diff] [blame] | 537 | arrayLengths[*count] = e->mHal.state.fieldArraySizes[ct]; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 538 | } |
| 539 | (*count)++; |
| 540 | } |
| 541 | } |
| 542 | } |