void rsi_AllocationCopyToBitmap(Context *rsc, RsAllocation va, void *data, size_t dataLen) { Allocation *texAlloc = static_cast<Allocation *>(va); const Type * t = texAlloc->getType(); size_t s = t->getDimX() * t->getDimY() * t->getElementSizeBytes(); if (s != dataLen) { rsc->setError(RS_ERROR_BAD_VALUE, "Bitmap size didn't match allocation size"); return; } memcpy(data, texAlloc->getPtr(), s); }
void RsdShader::setupUserConstants(const Context *rsc, RsdShaderCache *sc, bool isFragment) { uint32_t uidx = 0; for (uint32_t ct=0; ct < mRSProgram->mHal.state.constantsCount; ct++) { Allocation *alloc = mRSProgram->mHal.state.constants[ct]; if (!alloc) { LOGE("Attempting to set constants on shader id %u, but alloc at slot %u is not set", (uint32_t)this, ct); rsc->setError(RS_ERROR_BAD_SHADER, "No constant allocation bound"); continue; } const uint8_t *data = static_cast<const uint8_t *>(alloc->getPtr()); const Element *e = mRSProgram->mHal.state.constantTypes[ct]->getElement(); for (uint32_t field=0; field < e->getFieldCount(); field++) { const Element *f = e->getField(field); const char *fieldName = e->getFieldName(field); // If this field is padding, skip it if (fieldName[0] == '#') { continue; } uint32_t offset = e->getFieldOffsetBytes(field); const float *fd = reinterpret_cast<const float *>(&data[offset]); int32_t slot = -1; uint32_t arraySize = 1; if (!isFragment) { slot = sc->vtxUniformSlot(uidx); arraySize = sc->vtxUniformSize(uidx); } else { slot = sc->fragUniformSlot(uidx); arraySize = sc->fragUniformSize(uidx); } if (rsc->props.mLogShadersUniforms) { LOGV("Uniform slot=%i, offset=%i, constant=%i, field=%i, uidx=%i, name=%s", slot, offset, ct, field, uidx, fieldName); } uidx ++; if (slot < 0) { continue; } if (rsc->props.mLogShadersUniforms) { logUniform(f, fd, arraySize); } setUniform(rsc, f, fd, slot, arraySize); } } }
RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, RsType vtype, RsAllocationMipmapControl mips, const void *data, size_t data_length, uint32_t usages) { Type *t = static_cast<Type *>(vtype); RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages); Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc); if (texAlloc == NULL) { ALOGE("Memory allocation failure"); return NULL; } memcpy(texAlloc->getPtr(), data, t->getDimX() * t->getDimY() * t->getElementSizeBytes()); if (mips == RS_ALLOCATION_MIPMAP_FULL) { AllocationGenerateScriptMips(rsc, texAlloc); } texAlloc->sendDirty(rsc); return texAlloc; }