Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | */ |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 16 | #ifndef ANDROID_RS_BUILD_FOR_HOST |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 17 | #include "rsContext.h" |
| 18 | |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 19 | #include <GLES/gl.h> |
Jason Sams | c2908e6 | 2010-02-23 17:44:28 -0800 | [diff] [blame] | 20 | #include <GLES2/gl2.h> |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 21 | #include <GLES/glext.h> |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 22 | #else |
| 23 | #include "rsContextHostStub.h" |
| 24 | |
| 25 | #include <OpenGL/gl.h> |
| 26 | #include <OpenGl/glext.h> |
| 27 | #endif |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 28 | |
Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 29 | #include "utils/StopWatch.h" |
| 30 | |
Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 31 | static void rsaAllocationGenerateScriptMips(RsContext con, RsAllocation va); |
| 32 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 33 | using namespace android; |
| 34 | using namespace android::renderscript; |
| 35 | |
Alex Sakhartchouk | 0857196 | 2010-12-15 09:59:58 -0800 | [diff] [blame] | 36 | Allocation::Allocation(Context *rsc, const Type *type, uint32_t usages, |
| 37 | RsAllocationMipmapControl mc) |
| 38 | : ObjectBase(rsc) { |
Jason Sams | 8a64743f | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 39 | init(rsc, type); |
| 40 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 41 | mUsageFlags = usages; |
Alex Sakhartchouk | 0857196 | 2010-12-15 09:59:58 -0800 | [diff] [blame] | 42 | mMipmapControl = mc; |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 43 | |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 44 | allocScriptMemory(); |
Jason Sams | ee73498 | 2010-08-12 12:44:02 -0700 | [diff] [blame] | 45 | if (mType->getElement()->getHasReferences()) { |
| 46 | memset(mPtr, 0, mType->getSizeBytes()); |
| 47 | } |
Jason Sams | 8a64743f | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 48 | if (!mPtr) { |
| 49 | LOGE("Allocation::Allocation, alloc failure"); |
| 50 | } |
| 51 | } |
| 52 | |
Jason Sams | 8a64743f | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 53 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 54 | void Allocation::init(Context *rsc, const Type *type) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 55 | mPtr = NULL; |
| 56 | |
| 57 | mCpuWrite = false; |
| 58 | mCpuRead = false; |
| 59 | mGpuWrite = false; |
| 60 | mGpuRead = false; |
| 61 | |
| 62 | mReadWriteRatio = 0; |
| 63 | mUpdateSize = 0; |
Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 64 | mUsageFlags = 0; |
| 65 | mMipmapControl = RS_ALLOCATION_MIPMAP_NONE; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 66 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 67 | mTextureID = 0; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 68 | mBufferID = 0; |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 69 | mUploadDefered = false; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 70 | |
Jason Sams | 8a64743f | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 71 | mUserBitmapCallback = NULL; |
| 72 | mUserBitmapCallbackData = NULL; |
| 73 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 74 | mType.set(type); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 75 | rsAssert(type); |
Jason Sams | 8a64743f | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 76 | |
| 77 | mPtr = NULL; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 80 | Allocation::~Allocation() { |
Jason Sams | 8a64743f | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 81 | if (mUserBitmapCallback != NULL) { |
| 82 | mUserBitmapCallback(mUserBitmapCallbackData); |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 83 | mPtr = NULL; |
Jason Sams | 8a64743f | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 84 | } |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 85 | freeScriptMemory(); |
Jason Sams | 9d5e03d | 2009-11-03 11:25:42 -0800 | [diff] [blame] | 86 | |
| 87 | if (mBufferID) { |
| 88 | // Causes a SW crash.... |
| 89 | //LOGV(" mBufferID %i", mBufferID); |
| 90 | //glDeleteBuffers(1, &mBufferID); |
| 91 | //mBufferID = 0; |
| 92 | } |
| 93 | if (mTextureID) { |
| 94 | glDeleteTextures(1, &mTextureID); |
| 95 | mTextureID = 0; |
| 96 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 99 | void Allocation::setCpuWritable(bool) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 102 | void Allocation::setGpuWritable(bool) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 105 | void Allocation::setCpuReadable(bool) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 108 | void Allocation::setGpuReadable(bool) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 111 | bool Allocation::fixAllocation() { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 112 | return false; |
| 113 | } |
| 114 | |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 115 | void Allocation::deferedUploadToTexture(const Context *rsc) { |
Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 116 | mUsageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 117 | mUploadDefered = true; |
| 118 | } |
| 119 | |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 120 | uint32_t Allocation::getGLTarget() const { |
Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 121 | if (getIsTexture()) { |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 122 | if (mType->getDimFaces()) { |
| 123 | return GL_TEXTURE_CUBE_MAP; |
| 124 | } else { |
| 125 | return GL_TEXTURE_2D; |
| 126 | } |
| 127 | } |
Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 128 | if (getIsBufferObject()) { |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 129 | return GL_ARRAY_BUFFER; |
| 130 | } |
| 131 | return 0; |
| 132 | } |
| 133 | |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 134 | void Allocation::allocScriptMemory() { |
| 135 | rsAssert(!mPtr); |
| 136 | mPtr = malloc(mType->getSizeBytes()); |
| 137 | } |
| 138 | |
| 139 | void Allocation::freeScriptMemory() { |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 140 | if (mPtr) { |
| 141 | free(mPtr); |
| 142 | mPtr = NULL; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 147 | void Allocation::syncAll(Context *rsc, RsAllocationUsageType src) { |
| 148 | rsAssert(src == RS_ALLOCATION_USAGE_SCRIPT); |
| 149 | |
Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 150 | if (getIsTexture()) { |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 151 | uploadToTexture(rsc); |
| 152 | } |
Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 153 | if (getIsBufferObject()) { |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 154 | uploadToBufferObject(rsc); |
| 155 | } |
| 156 | |
| 157 | mUploadDefered = false; |
| 158 | } |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 159 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 160 | void Allocation::uploadToTexture(const Context *rsc) { |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 161 | |
Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 162 | mUsageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 163 | GLenum type = mType->getElement()->getComponent().getGLType(); |
| 164 | GLenum format = mType->getElement()->getComponent().getGLFormat(); |
Jason Sams | e2ae85f | 2009-06-03 16:04:54 -0700 | [diff] [blame] | 165 | |
| 166 | if (!type || !format) { |
| 167 | return; |
| 168 | } |
| 169 | |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 170 | if (!mPtr) { |
| 171 | return; |
| 172 | } |
| 173 | |
Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 174 | bool isFirstUpload = false; |
| 175 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 176 | if (!mTextureID) { |
| 177 | glGenTextures(1, &mTextureID); |
Jason Sams | 9dab667 | 2009-11-24 12:26:35 -0800 | [diff] [blame] | 178 | |
| 179 | if (!mTextureID) { |
| 180 | // This should not happen, however, its likely the cause of the |
| 181 | // white sqare bug. |
| 182 | // Force a crash to 1: restart the app, 2: make sure we get a bugreport. |
| 183 | LOGE("Upload to texture failed to gen mTextureID"); |
| 184 | rsc->dumpDebug(); |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 185 | mUploadDefered = true; |
| 186 | return; |
Jason Sams | 9dab667 | 2009-11-24 12:26:35 -0800 | [diff] [blame] | 187 | } |
Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 188 | isFirstUpload = true; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 189 | } |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 190 | |
| 191 | GLenum target = (GLenum)getGLTarget(); |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 192 | if (target == GL_TEXTURE_2D) { |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 193 | upload2DTexture(isFirstUpload, mPtr); |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 194 | } else if (target == GL_TEXTURE_CUBE_MAP) { |
| 195 | uploadCubeTexture(isFirstUpload); |
| 196 | } |
| 197 | |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 198 | if (!(mUsageFlags & RS_ALLOCATION_USAGE_SCRIPT)) { |
| 199 | freeScriptMemory(); |
| 200 | } |
| 201 | |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 202 | rsc->checkError("Allocation::uploadToTexture"); |
| 203 | } |
| 204 | |
Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame^] | 205 | void Allocation::update2DTexture(const void *ptr, uint32_t xoff, uint32_t yoff, |
| 206 | uint32_t lod, RsAllocationCubemapFace face, |
| 207 | uint32_t w, uint32_t h) { |
| 208 | GLenum type = mType->getElement()->getComponent().getGLType(); |
| 209 | GLenum format = mType->getElement()->getComponent().getGLFormat(); |
| 210 | GLenum target = (GLenum)getGLTarget(); |
| 211 | glBindTexture(target, mTextureID); |
| 212 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 213 | glTexSubImage2D(GL_TEXTURE_2D, lod, xoff, yoff, w, h, format, type, ptr); |
| 214 | } |
| 215 | |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 216 | void Allocation::upload2DTexture(bool isFirstUpload, const void *ptr) { |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 217 | GLenum type = mType->getElement()->getComponent().getGLType(); |
| 218 | GLenum format = mType->getElement()->getComponent().getGLFormat(); |
| 219 | |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 220 | GLenum target = (GLenum)getGLTarget(); |
| 221 | glBindTexture(target, mTextureID); |
| 222 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 223 | |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 224 | for (uint32_t lod = 0; lod < mType->getLODCount(); lod++) { |
| 225 | const uint8_t *p = (const uint8_t *)ptr; |
| 226 | p += mType->getLODOffset(lod); |
| 227 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 228 | if (isFirstUpload) { |
Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 229 | glTexImage2D(GL_TEXTURE_2D, lod, format, |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 230 | mType->getLODDimX(lod), mType->getLODDimY(lod), |
| 231 | 0, format, type, p); |
Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 232 | } else { |
| 233 | glTexSubImage2D(GL_TEXTURE_2D, lod, 0, 0, |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 234 | mType->getLODDimX(lod), mType->getLODDimY(lod), |
| 235 | format, type, p); |
Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 236 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 237 | } |
Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 238 | |
| 239 | if (mMipmapControl == RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE) { |
| 240 | #ifndef ANDROID_RS_BUILD_FOR_HOST |
| 241 | glGenerateMipmap(target); |
| 242 | #endif //ANDROID_RS_BUILD_FOR_HOST |
| 243 | } |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 244 | } |
Jason Sams | c2908e6 | 2010-02-23 17:44:28 -0800 | [diff] [blame] | 245 | |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 246 | void Allocation::uploadCubeTexture(bool isFirstUpload) { |
| 247 | GLenum type = mType->getElement()->getComponent().getGLType(); |
| 248 | GLenum format = mType->getElement()->getComponent().getGLFormat(); |
| 249 | |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 250 | GLenum target = (GLenum)getGLTarget(); |
| 251 | glBindTexture(target, mTextureID); |
| 252 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 253 | |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 254 | GLenum faceOrder[] = { |
| 255 | GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
| 256 | GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
| 257 | GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
| 258 | GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, |
| 259 | GL_TEXTURE_CUBE_MAP_POSITIVE_Z, |
| 260 | GL_TEXTURE_CUBE_MAP_NEGATIVE_Z |
| 261 | }; |
| 262 | |
| 263 | Adapter2D adapt(getContext(), this); |
| 264 | for (uint32_t face = 0; face < 6; face ++) { |
| 265 | adapt.setFace(face); |
| 266 | |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 267 | for (uint32_t lod = 0; lod < mType->getLODCount(); lod++) { |
| 268 | adapt.setLOD(lod); |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 269 | |
| 270 | uint16_t * ptr = static_cast<uint16_t *>(adapt.getElement(0,0)); |
| 271 | |
| 272 | if (isFirstUpload) { |
| 273 | glTexImage2D(faceOrder[face], lod, format, |
| 274 | adapt.getDimX(), adapt.getDimY(), |
| 275 | 0, format, type, ptr); |
| 276 | } else { |
| 277 | glTexSubImage2D(faceOrder[face], lod, 0, 0, |
| 278 | adapt.getDimX(), adapt.getDimY(), |
| 279 | format, type, ptr); |
| 280 | } |
| 281 | } |
| 282 | } |
Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 283 | |
| 284 | if (mMipmapControl == RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE) { |
| 285 | #ifndef ANDROID_RS_BUILD_FOR_HOST |
| 286 | glGenerateMipmap(target); |
| 287 | #endif //ANDROID_RS_BUILD_FOR_HOST |
| 288 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 291 | void Allocation::deferedUploadToBufferObject(const Context *rsc) { |
Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 292 | mUsageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_VERTEX; |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 293 | mUploadDefered = true; |
| 294 | } |
| 295 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 296 | void Allocation::uploadToBufferObject(const Context *rsc) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 297 | rsAssert(!mType->getDimY()); |
| 298 | rsAssert(!mType->getDimZ()); |
| 299 | |
Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 300 | mUsageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_VERTEX; |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 301 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 302 | if (!mBufferID) { |
| 303 | glGenBuffers(1, &mBufferID); |
| 304 | } |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 305 | if (!mBufferID) { |
| 306 | LOGE("Upload to buffer object failed"); |
| 307 | mUploadDefered = true; |
| 308 | return; |
| 309 | } |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 310 | GLenum target = (GLenum)getGLTarget(); |
| 311 | glBindBuffer(target, mBufferID); |
| 312 | glBufferData(target, mType->getSizeBytes(), getPtr(), GL_DYNAMIC_DRAW); |
| 313 | glBindBuffer(target, 0); |
Jason Sams | f468700 | 2010-03-10 17:30:41 -0800 | [diff] [blame] | 314 | rsc->checkError("Allocation::uploadToBufferObject"); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 317 | void Allocation::uploadCheck(Context *rsc) { |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 318 | if (mUploadDefered) { |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 319 | syncAll(rsc, RS_ALLOCATION_USAGE_SCRIPT); |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 323 | void Allocation::read(void *data) { |
Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 324 | memcpy(data, mPtr, mType->getSizeBytes()); |
| 325 | } |
| 326 | |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 327 | void Allocation::data(Context *rsc, uint32_t xoff, uint32_t lod, |
| 328 | uint32_t count, const void *data, uint32_t sizeBytes) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 329 | uint32_t eSize = mType->getElementSizeBytes(); |
| 330 | uint8_t * ptr = static_cast<uint8_t *>(mPtr); |
| 331 | ptr += eSize * xoff; |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 332 | uint32_t size = count * eSize; |
| 333 | |
| 334 | if (size != sizeBytes) { |
| 335 | LOGE("Allocation::subData called with mismatched size expected %i, got %i", size, sizeBytes); |
Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 336 | mType->dumpLOGV("type info"); |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 337 | return; |
| 338 | } |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 339 | |
| 340 | if (mType->getElement()->getHasReferences()) { |
| 341 | incRefs(data, count); |
| 342 | decRefs(ptr, count); |
| 343 | } |
| 344 | |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 345 | memcpy(ptr, data, size); |
Jason Sams | 83f1c63 | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 346 | sendDirty(); |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 347 | mUploadDefered = true; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 350 | void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face, |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 351 | uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 352 | uint32_t eSize = mType->getElementSizeBytes(); |
| 353 | uint32_t lineSize = eSize * w; |
| 354 | uint32_t destW = mType->getDimX(); |
| 355 | |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 356 | //LOGE("data2d %p, %i %i %i %i %i %i %p %i", this, xoff, yoff, lod, face, w, h, data, sizeBytes); |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 357 | |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 358 | if ((lineSize * h) != sizeBytes) { |
| 359 | LOGE("Allocation size mismatch, expected %i, got %i", (lineSize * h), sizeBytes); |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 360 | rsAssert(!"Allocation::subData called with mismatched size"); |
| 361 | return; |
| 362 | } |
| 363 | |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 364 | if (mPtr) { |
| 365 | const uint8_t *src = static_cast<const uint8_t *>(data); |
| 366 | uint8_t *dst = static_cast<uint8_t *>(mPtr); |
| 367 | dst += mType->getLODOffset(lod, xoff, yoff); |
| 368 | |
| 369 | //LOGE(" %p %p %i ", dst, src, eSize); |
| 370 | for (uint32_t line=yoff; line < (yoff+h); line++) { |
| 371 | if (mType->getElement()->getHasReferences()) { |
| 372 | incRefs(src, w); |
| 373 | decRefs(dst, w); |
| 374 | } |
| 375 | memcpy(dst, src, lineSize); |
| 376 | src += lineSize; |
| 377 | dst += destW * eSize; |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 378 | } |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 379 | sendDirty(); |
| 380 | mUploadDefered = true; |
| 381 | } else { |
Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame^] | 382 | update2DTexture(data, xoff, yoff, lod, face, w, h); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame^] | 386 | void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, |
| 387 | uint32_t lod, RsAllocationCubemapFace face, |
| 388 | uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 391 | void Allocation::elementData(Context *rsc, uint32_t x, const void *data, |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 392 | uint32_t cIdx, uint32_t sizeBytes) { |
Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 393 | uint32_t eSize = mType->getElementSizeBytes(); |
| 394 | uint8_t * ptr = static_cast<uint8_t *>(mPtr); |
| 395 | ptr += eSize * x; |
| 396 | |
| 397 | if (cIdx >= mType->getElement()->getFieldCount()) { |
| 398 | LOGE("Error Allocation::subElementData component %i out of range.", cIdx); |
| 399 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range."); |
| 400 | return; |
| 401 | } |
| 402 | |
| 403 | if (x >= mType->getDimX()) { |
| 404 | LOGE("Error Allocation::subElementData X offset %i out of range.", x); |
| 405 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range."); |
| 406 | return; |
| 407 | } |
| 408 | |
| 409 | const Element * e = mType->getElement()->getField(cIdx); |
| 410 | ptr += mType->getElement()->getFieldOffsetBytes(cIdx); |
| 411 | |
| 412 | if (sizeBytes != e->getSizeBytes()) { |
| 413 | LOGE("Error Allocation::subElementData data size %i does not match field size %i.", sizeBytes, e->getSizeBytes()); |
| 414 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size."); |
| 415 | return; |
| 416 | } |
| 417 | |
| 418 | if (e->getHasReferences()) { |
| 419 | e->incRefs(data); |
| 420 | e->decRefs(ptr); |
| 421 | } |
| 422 | |
| 423 | memcpy(ptr, data, sizeBytes); |
| 424 | sendDirty(); |
| 425 | mUploadDefered = true; |
| 426 | } |
| 427 | |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 428 | void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y, |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 429 | const void *data, uint32_t cIdx, uint32_t sizeBytes) { |
Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 430 | uint32_t eSize = mType->getElementSizeBytes(); |
| 431 | uint8_t * ptr = static_cast<uint8_t *>(mPtr); |
| 432 | ptr += eSize * (x + y * mType->getDimX()); |
| 433 | |
| 434 | if (x >= mType->getDimX()) { |
| 435 | LOGE("Error Allocation::subElementData X offset %i out of range.", x); |
| 436 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range."); |
| 437 | return; |
| 438 | } |
| 439 | |
| 440 | if (y >= mType->getDimY()) { |
| 441 | LOGE("Error Allocation::subElementData X offset %i out of range.", x); |
| 442 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range."); |
| 443 | return; |
| 444 | } |
| 445 | |
| 446 | if (cIdx >= mType->getElement()->getFieldCount()) { |
| 447 | LOGE("Error Allocation::subElementData component %i out of range.", cIdx); |
| 448 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range."); |
| 449 | return; |
| 450 | } |
| 451 | |
| 452 | const Element * e = mType->getElement()->getField(cIdx); |
| 453 | ptr += mType->getElement()->getFieldOffsetBytes(cIdx); |
| 454 | |
| 455 | if (sizeBytes != e->getSizeBytes()) { |
| 456 | LOGE("Error Allocation::subElementData data size %i does not match field size %i.", sizeBytes, e->getSizeBytes()); |
| 457 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size."); |
| 458 | return; |
| 459 | } |
| 460 | |
| 461 | if (e->getHasReferences()) { |
| 462 | e->incRefs(data); |
| 463 | e->decRefs(ptr); |
| 464 | } |
| 465 | |
| 466 | memcpy(ptr, data, sizeBytes); |
| 467 | sendDirty(); |
| 468 | mUploadDefered = true; |
| 469 | } |
| 470 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 471 | void Allocation::addProgramToDirty(const Program *p) { |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 472 | mToDirtyList.push(p); |
Jason Sams | 83f1c63 | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 473 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 474 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 475 | void Allocation::removeProgramToDirty(const Program *p) { |
Jason Sams | 83f1c63 | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 476 | for (size_t ct=0; ct < mToDirtyList.size(); ct++) { |
| 477 | if (mToDirtyList[ct] == p) { |
| 478 | mToDirtyList.removeAt(ct); |
| 479 | return; |
| 480 | } |
| 481 | } |
| 482 | rsAssert(0); |
| 483 | } |
| 484 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 485 | void Allocation::dumpLOGV(const char *prefix) const { |
Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 486 | ObjectBase::dumpLOGV(prefix); |
| 487 | |
| 488 | String8 s(prefix); |
| 489 | s.append(" type "); |
| 490 | if (mType.get()) { |
| 491 | mType->dumpLOGV(s.string()); |
| 492 | } |
| 493 | |
| 494 | LOGV("%s allocation ptr=%p mCpuWrite=%i, mCpuRead=%i, mGpuWrite=%i, mGpuRead=%i", |
| 495 | prefix, mPtr, mCpuWrite, mCpuRead, mGpuWrite, mGpuRead); |
| 496 | |
Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 497 | LOGV("%s allocation mUsageFlags=0x04%x, mMipmapControl=0x%04x, mTextureID=%i, mBufferID=%i", |
| 498 | prefix, mUsageFlags, mMipmapControl, mTextureID, mBufferID); |
Jason Sams | 715333b | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 499 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 500 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 501 | void Allocation::serialize(OStream *stream) const { |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 502 | // Need to identify ourselves |
| 503 | stream->addU32((uint32_t)getClassId()); |
| 504 | |
| 505 | String8 name(getName()); |
| 506 | stream->addString(&name); |
| 507 | |
| 508 | // First thing we need to serialize is the type object since it will be needed |
| 509 | // to initialize the class |
| 510 | mType->serialize(stream); |
| 511 | |
| 512 | uint32_t dataSize = mType->getSizeBytes(); |
| 513 | // Write how much data we are storing |
| 514 | stream->addU32(dataSize); |
| 515 | // Now write the data |
| 516 | stream->addByteArray(mPtr, dataSize); |
| 517 | } |
| 518 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 519 | Allocation *Allocation::createFromStream(Context *rsc, IStream *stream) { |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 520 | // First make sure we are reading the correct object |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 521 | RsA3DClassID classID = (RsA3DClassID)stream->loadU32(); |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 522 | if (classID != RS_A3D_CLASS_ID_ALLOCATION) { |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 523 | LOGE("allocation loading skipped due to invalid class id\n"); |
| 524 | return NULL; |
| 525 | } |
| 526 | |
| 527 | String8 name; |
| 528 | stream->loadString(&name); |
| 529 | |
| 530 | Type *type = Type::createFromStream(rsc, stream); |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 531 | if (!type) { |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 532 | return NULL; |
| 533 | } |
| 534 | type->compute(); |
| 535 | |
| 536 | // Number of bytes we wrote out for this allocation |
| 537 | uint32_t dataSize = stream->loadU32(); |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 538 | if (dataSize != type->getSizeBytes()) { |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 539 | LOGE("failed to read allocation because numbytes written is not the same loaded type wants\n"); |
Jason Sams | b38d534 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 540 | ObjectBase::checkDelete(type); |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 541 | return NULL; |
| 542 | } |
| 543 | |
Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 544 | Allocation *alloc = new Allocation(rsc, type, RS_ALLOCATION_USAGE_SCRIPT); |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 545 | alloc->setName(name.string(), name.size()); |
| 546 | |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 547 | uint32_t count = dataSize / type->getElementSizeBytes(); |
| 548 | |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 549 | // Read in all of our allocation data |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 550 | alloc->data(rsc, 0, 0, count, stream->getPtr() + stream->getPos(), dataSize); |
Alex Sakhartchouk | 2ce0e3f | 2010-08-11 10:30:44 -0700 | [diff] [blame] | 551 | stream->reset(stream->getPos() + dataSize); |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 552 | |
| 553 | return alloc; |
| 554 | } |
| 555 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 556 | void Allocation::sendDirty() const { |
Jason Sams | 83f1c63 | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 557 | for (size_t ct=0; ct < mToDirtyList.size(); ct++) { |
| 558 | mToDirtyList[ct]->forceDirty(); |
| 559 | } |
| 560 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 561 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 562 | void Allocation::incRefs(const void *ptr, size_t ct, size_t startOff) const { |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 563 | const uint8_t *p = static_cast<const uint8_t *>(ptr); |
| 564 | const Element *e = mType->getElement(); |
| 565 | uint32_t stride = e->getSizeBytes(); |
| 566 | |
Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 567 | p += stride * startOff; |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 568 | while (ct > 0) { |
| 569 | e->incRefs(p); |
| 570 | ct --; |
| 571 | p += stride; |
| 572 | } |
| 573 | } |
| 574 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 575 | void Allocation::decRefs(const void *ptr, size_t ct, size_t startOff) const { |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 576 | const uint8_t *p = static_cast<const uint8_t *>(ptr); |
| 577 | const Element *e = mType->getElement(); |
| 578 | uint32_t stride = e->getSizeBytes(); |
| 579 | |
Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 580 | p += stride * startOff; |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 581 | while (ct > 0) { |
| 582 | e->decRefs(p); |
| 583 | ct --; |
| 584 | p += stride; |
| 585 | } |
| 586 | } |
| 587 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 588 | void Allocation::copyRange1D(Context *rsc, const Allocation *src, int32_t srcOff, int32_t destOff, int32_t len) { |
Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 591 | void Allocation::resize1D(Context *rsc, uint32_t dimX) { |
Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 592 | Type *t = mType->cloneAndResize1D(rsc, dimX); |
| 593 | |
| 594 | uint32_t oldDimX = mType->getDimX(); |
| 595 | if (dimX == oldDimX) { |
| 596 | return; |
| 597 | } |
| 598 | |
| 599 | if (dimX < oldDimX) { |
| 600 | decRefs(mPtr, oldDimX - dimX, dimX); |
| 601 | } |
| 602 | mPtr = realloc(mPtr, t->getSizeBytes()); |
| 603 | |
| 604 | if (dimX > oldDimX) { |
| 605 | const Element *e = mType->getElement(); |
| 606 | uint32_t stride = e->getSizeBytes(); |
| 607 | memset(((uint8_t *)mPtr) + stride * oldDimX, 0, stride * (dimX - oldDimX)); |
| 608 | } |
| 609 | mType.set(t); |
| 610 | } |
| 611 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 612 | void Allocation::resize2D(Context *rsc, uint32_t dimX, uint32_t dimY) { |
Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 613 | LOGE("not implemented"); |
| 614 | } |
| 615 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 616 | ///////////////// |
Jason Sams | e2ae85f | 2009-06-03 16:04:54 -0700 | [diff] [blame] | 617 | // |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 618 | |
| 619 | |
| 620 | namespace android { |
| 621 | namespace renderscript { |
| 622 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 623 | void rsi_AllocationUploadToTexture(Context *rsc, RsAllocation va, bool genmip, uint32_t baseMipLevel) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 624 | Allocation *alloc = static_cast<Allocation *>(va); |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 625 | alloc->deferedUploadToTexture(rsc); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 628 | void rsi_AllocationUploadToBufferObject(Context *rsc, RsAllocation va) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 629 | Allocation *alloc = static_cast<Allocation *>(va); |
Jason Sams | 3b7d39b | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 630 | alloc->deferedUploadToBufferObject(rsc); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 633 | static void mip565(const Adapter2D &out, const Adapter2D &in) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 634 | uint32_t w = out.getDimX(); |
| 635 | uint32_t h = out.getDimY(); |
| 636 | |
Jason Sams | 6f5c61c | 2009-07-28 17:20:11 -0700 | [diff] [blame] | 637 | for (uint32_t y=0; y < h; y++) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 638 | uint16_t *oPtr = static_cast<uint16_t *>(out.getElement(0, y)); |
| 639 | const uint16_t *i1 = static_cast<uint16_t *>(in.getElement(0, y*2)); |
| 640 | const uint16_t *i2 = static_cast<uint16_t *>(in.getElement(0, y*2+1)); |
| 641 | |
Jason Sams | 6f5c61c | 2009-07-28 17:20:11 -0700 | [diff] [blame] | 642 | for (uint32_t x=0; x < w; x++) { |
Jason Sams | e2ae85f | 2009-06-03 16:04:54 -0700 | [diff] [blame] | 643 | *oPtr = rsBoxFilter565(i1[0], i1[1], i2[0], i2[1]); |
| 644 | oPtr ++; |
| 645 | i1 += 2; |
| 646 | i2 += 2; |
| 647 | } |
| 648 | } |
| 649 | } |
| 650 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 651 | static void mip8888(const Adapter2D &out, const Adapter2D &in) { |
Jason Sams | e2ae85f | 2009-06-03 16:04:54 -0700 | [diff] [blame] | 652 | uint32_t w = out.getDimX(); |
| 653 | uint32_t h = out.getDimY(); |
| 654 | |
Jason Sams | 6f5c61c | 2009-07-28 17:20:11 -0700 | [diff] [blame] | 655 | for (uint32_t y=0; y < h; y++) { |
Jason Sams | e2ae85f | 2009-06-03 16:04:54 -0700 | [diff] [blame] | 656 | uint32_t *oPtr = static_cast<uint32_t *>(out.getElement(0, y)); |
| 657 | const uint32_t *i1 = static_cast<uint32_t *>(in.getElement(0, y*2)); |
| 658 | const uint32_t *i2 = static_cast<uint32_t *>(in.getElement(0, y*2+1)); |
| 659 | |
Jason Sams | 6f5c61c | 2009-07-28 17:20:11 -0700 | [diff] [blame] | 660 | for (uint32_t x=0; x < w; x++) { |
Jason Sams | e2ae85f | 2009-06-03 16:04:54 -0700 | [diff] [blame] | 661 | *oPtr = rsBoxFilter8888(i1[0], i1[1], i2[0], i2[1]); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 662 | oPtr ++; |
| 663 | i1 += 2; |
| 664 | i2 += 2; |
| 665 | } |
| 666 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 669 | static void mip8(const Adapter2D &out, const Adapter2D &in) { |
Jason Sams | e20e3b4 | 2010-01-19 17:53:54 -0800 | [diff] [blame] | 670 | uint32_t w = out.getDimX(); |
| 671 | uint32_t h = out.getDimY(); |
| 672 | |
| 673 | for (uint32_t y=0; y < h; y++) { |
| 674 | uint8_t *oPtr = static_cast<uint8_t *>(out.getElement(0, y)); |
| 675 | const uint8_t *i1 = static_cast<uint8_t *>(in.getElement(0, y*2)); |
| 676 | const uint8_t *i2 = static_cast<uint8_t *>(in.getElement(0, y*2+1)); |
| 677 | |
| 678 | for (uint32_t x=0; x < w; x++) { |
| 679 | *oPtr = (uint8_t)(((uint32_t)i1[0] + i1[1] + i2[0] + i2[1]) * 0.25f); |
| 680 | oPtr ++; |
| 681 | i1 += 2; |
| 682 | i2 += 2; |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 687 | static void mip(const Adapter2D &out, const Adapter2D &in) { |
| 688 | switch (out.getBaseType()->getElement()->getSizeBits()) { |
Jason Sams | 6f5c61c | 2009-07-28 17:20:11 -0700 | [diff] [blame] | 689 | case 32: |
| 690 | mip8888(out, in); |
| 691 | break; |
| 692 | case 16: |
| 693 | mip565(out, in); |
| 694 | break; |
Jason Sams | e20e3b4 | 2010-01-19 17:53:54 -0800 | [diff] [blame] | 695 | case 8: |
| 696 | mip8(out, in); |
| 697 | break; |
Jason Sams | 6f5c61c | 2009-07-28 17:20:11 -0700 | [diff] [blame] | 698 | } |
Jason Sams | 6f5c61c | 2009-07-28 17:20:11 -0700 | [diff] [blame] | 699 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 700 | |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 701 | #ifndef ANDROID_RS_BUILD_FOR_HOST |
| 702 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 703 | void rsi_AllocationSyncAll(Context *rsc, RsAllocation va, RsAllocationUsageType src) { |
| 704 | Allocation *a = static_cast<Allocation *>(va); |
| 705 | a->syncAll(rsc, src); |
| 706 | } |
| 707 | |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 708 | void rsi_AllocationGenerateMipmaps(Context *rsc, RsAllocation va) { |
Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 709 | Allocation *texAlloc = static_cast<Allocation *>(va); |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 710 | rsaAllocationGenerateScriptMips(rsc, texAlloc); |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | void rsi_AllocationCopyToBitmap(Context *rsc, RsAllocation va, void *data, size_t dataLen) { |
| 714 | Allocation *texAlloc = static_cast<Allocation *>(va); |
| 715 | const Type * t = texAlloc->getType(); |
| 716 | |
| 717 | size_t s = t->getDimX() * t->getDimY() * t->getElementSizeBytes(); |
| 718 | if (s != dataLen) { |
| 719 | rsc->setError(RS_ERROR_BAD_VALUE, "Bitmap size didn't match allocation size"); |
| 720 | return; |
| 721 | } |
| 722 | |
| 723 | memcpy(data, texAlloc->getPtr(), s); |
Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 726 | void rsi_Allocation1DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod, |
| 727 | uint32_t count, const void *data, uint32_t sizeBytes) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 728 | Allocation *a = static_cast<Allocation *>(va); |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 729 | a->data(rsc, xoff, lod, count, data, sizeBytes); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 732 | void rsi_Allocation2DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t lod, RsAllocationCubemapFace face, |
| 733 | const void *data, uint32_t eoff, uint32_t sizeBytes) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 734 | Allocation *a = static_cast<Allocation *>(va); |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 735 | a->elementData(rsc, x, y, data, eoff, sizeBytes); |
Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 738 | void rsi_Allocation1DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t lod, |
| 739 | const void *data, uint32_t eoff, uint32_t sizeBytes) { |
Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 740 | Allocation *a = static_cast<Allocation *>(va); |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 741 | a->elementData(rsc, x, data, eoff, sizeBytes); |
Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 744 | void rsi_Allocation2DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face, |
| 745 | uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes) { |
Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 746 | Allocation *a = static_cast<Allocation *>(va); |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 747 | a->data(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 750 | void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data) { |
Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 751 | Allocation *a = static_cast<Allocation *>(va); |
| 752 | a->read(data); |
| 753 | } |
| 754 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 755 | void rsi_AllocationResize1D(Context *rsc, RsAllocation va, uint32_t dimX) { |
Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 756 | Allocation *a = static_cast<Allocation *>(va); |
| 757 | a->resize1D(rsc, dimX); |
| 758 | } |
| 759 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 760 | void rsi_AllocationResize2D(Context *rsc, RsAllocation va, uint32_t dimX, uint32_t dimY) { |
Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 761 | Allocation *a = static_cast<Allocation *>(va); |
| 762 | a->resize2D(rsc, dimX, dimY); |
| 763 | } |
| 764 | |
Alex Sakhartchouk | 581cc64 | 2010-10-27 14:10:07 -0700 | [diff] [blame] | 765 | #endif //ANDROID_RS_BUILD_FOR_HOST |
| 766 | |
| 767 | } |
| 768 | } |
| 769 | |
Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 770 | static void rsaAllocationGenerateScriptMips(RsContext con, RsAllocation va) { |
| 771 | Context *rsc = static_cast<Context *>(con); |
| 772 | Allocation *texAlloc = static_cast<Allocation *>(va); |
| 773 | uint32_t numFaces = texAlloc->getType()->getDimFaces() ? 6 : 1; |
| 774 | for (uint32_t face = 0; face < numFaces; face ++) { |
| 775 | Adapter2D adapt(rsc, texAlloc); |
| 776 | Adapter2D adapt2(rsc, texAlloc); |
| 777 | adapt.setFace(face); |
| 778 | adapt2.setFace(face); |
| 779 | for (uint32_t lod=0; lod < (texAlloc->getType()->getLODCount() -1); lod++) { |
| 780 | adapt.setLOD(lod); |
| 781 | adapt2.setLOD(lod + 1); |
| 782 | mip(adapt2, adapt); |
| 783 | } |
| 784 | } |
| 785 | } |
| 786 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 787 | const void * rsaAllocationGetType(RsContext con, RsAllocation va) { |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 788 | Allocation *a = static_cast<Allocation *>(va); |
| 789 | a->getType()->incUserRef(); |
| 790 | |
| 791 | return a->getType(); |
| 792 | } |
| 793 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 794 | RsAllocation rsaAllocationCreateTyped(RsContext con, RsType vtype, |
Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 795 | RsAllocationMipmapControl mips, |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 796 | uint32_t usages) { |
Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 797 | Context *rsc = static_cast<Context *>(con); |
Alex Sakhartchouk | 0857196 | 2010-12-15 09:59:58 -0800 | [diff] [blame] | 798 | Allocation * alloc = new Allocation(rsc, static_cast<Type *>(vtype), usages, mips); |
Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 799 | alloc->incUserRef(); |
| 800 | return alloc; |
| 801 | } |
| 802 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 803 | |
| 804 | RsAllocation rsaAllocationCreateFromBitmap(RsContext con, RsType vtype, |
Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 805 | RsAllocationMipmapControl mips, |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 806 | const void *data, uint32_t usages) { |
Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 807 | Context *rsc = static_cast<Context *>(con); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 808 | Type *t = static_cast<Type *>(vtype); |
Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 809 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 810 | RsAllocation vTexAlloc = rsaAllocationCreateTyped(rsc, vtype, mips, usages); |
Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 811 | Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc); |
| 812 | if (texAlloc == NULL) { |
| 813 | LOGE("Memory allocation failure"); |
| 814 | return NULL; |
| 815 | } |
| 816 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 817 | memcpy(texAlloc->getPtr(), data, t->getDimX() * t->getDimY() * t->getElementSizeBytes()); |
Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 818 | if (mips == RS_ALLOCATION_MIPMAP_FULL) { |
Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 819 | rsaAllocationGenerateScriptMips(rsc, texAlloc); |
Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 822 | texAlloc->deferedUploadToTexture(rsc); |
Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 823 | return texAlloc; |
| 824 | } |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 825 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 826 | RsAllocation rsaAllocationCubeCreateFromBitmap(RsContext con, RsType vtype, |
Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 827 | RsAllocationMipmapControl mips, |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 828 | const void *data, uint32_t usages) { |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 829 | Context *rsc = static_cast<Context *>(con); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 830 | Type *t = static_cast<Type *>(vtype); |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 831 | |
| 832 | // Cubemap allocation's faces should be Width by Width each. |
| 833 | // Source data should have 6 * Width by Width pixels |
| 834 | // Error checking is done in the java layer |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 835 | RsAllocation vTexAlloc = rsaAllocationCreateTyped(rsc, t, mips, usages); |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 836 | Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc); |
| 837 | if (texAlloc == NULL) { |
| 838 | LOGE("Memory allocation failure"); |
| 839 | return NULL; |
| 840 | } |
| 841 | |
Alex Sakhartchouk | fe852e2 | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 842 | uint32_t faceSize = t->getDimX(); |
| 843 | uint32_t strideBytes = faceSize * 6 * t->getElementSizeBytes(); |
| 844 | uint32_t copySize = faceSize * t->getElementSizeBytes(); |
| 845 | |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 846 | uint8_t *sourcePtr = (uint8_t*)data; |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 847 | for (uint32_t face = 0; face < 6; face ++) { |
| 848 | Adapter2D faceAdapter(rsc, texAlloc); |
| 849 | faceAdapter.setFace(face); |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 850 | |
Alex Sakhartchouk | fe852e2 | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 851 | for (uint32_t dI = 0; dI < faceSize; dI ++) { |
| 852 | memcpy(faceAdapter.getElement(0, dI), sourcePtr + strideBytes * dI, copySize); |
| 853 | } |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 854 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 855 | // Move the data pointer to the next cube face |
Alex Sakhartchouk | fe852e2 | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 856 | sourcePtr += copySize; |
Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 857 | } |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 858 | |
Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 859 | if (mips == RS_ALLOCATION_MIPMAP_FULL) { |
| 860 | rsaAllocationGenerateScriptMips(rsc, texAlloc); |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 861 | } |
| 862 | |
Jason Sams | 5e0035a | 2010-12-13 17:11:21 -0800 | [diff] [blame] | 863 | texAlloc->deferedUploadToTexture(rsc); |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 864 | return texAlloc; |
| 865 | } |