Replaced memcpy usage with NEON optimized ones.

This commit is contained in:
Rinnegatamante
2020-10-07 11:32:38 +02:00
parent e00336e23a
commit 93bbffb82d
13 changed files with 56 additions and 46 deletions
+6 -4
View File
@@ -19,6 +19,8 @@
#include "rwobjects.h"
#include "rwengine.h"
#include <vitaGL.h>
namespace rw {
#define PLUGIN_ID 0
@@ -759,7 +761,7 @@ Stream::write32(const void *data, uint32 length)
int32 n, len;
for(len = length >>= 2; len > 0; len -= 256){
n = len < 256 ? len : 256;
memcpy(buf, src, n*4);
memcpy_neon(buf, src, n*4);
memLittle16(buf, n*4);
write8(buf, n*4);
src += n*4;
@@ -779,7 +781,7 @@ Stream::write16(const void *data, uint32 length)
int32 n, len;
for(len = length >>= 1; len > 0; len -= 256){
n = len < 256 ? len : 256;
memcpy(buf, src, n*2);
memcpy_neon(buf, src, n*2);
memLittle16(buf, n*2);
write8(buf, n*2);
src += n*2;
@@ -924,7 +926,7 @@ StreamMemory::write8(const void *data, uint32 len)
l = this->capacity-this->position;
this->length = this->position+l;
}
memcpy(&this->data[this->position], data, l);
memcpy_neon(&this->data[this->position], data, l);
this->position += l;
if(len != l)
this->position = S_EOF;
@@ -939,7 +941,7 @@ StreamMemory::read8(void *data, uint32 len)
uint32 l = len;
if(this->position+l > this->length)
l = this->length-this->position;
memcpy(data, &this->data[this->position], l);
memcpy_neon(data, &this->data[this->position], l);
this->position += l;
if(len != l)
this->position = S_EOF;
+4 -2
View File
@@ -11,6 +11,8 @@
#include "rwobjects.h"
#include "rwengine.h"
#include <vitaGL.h>
#define PLUGIN_ID ID_GEOMETRY
namespace rw {
@@ -616,7 +618,7 @@ Geometry::correctTristripWinding(void)
rwFree(header);
// Now allocate indices and copy them
this->allocateMeshes(newhead->numMeshes, newhead->totalIndices, 0);
memcpy(this->meshHeader->getMeshes()->indices, indices, this->meshHeader->totalIndices*2);
memcpy_neon(this->meshHeader->getMeshes()->indices, indices, this->meshHeader->totalIndices*2);
rwFree(indices);
}
@@ -671,7 +673,7 @@ Geometry::removeUnusedMaterials(void)
for(uint32 i = 0; i < mh->numMeshes; i++){
if(m[i].numIndices <= 0)
continue;
memcpy(newm->indices, m[i].indices,
memcpy_neon(newm->indices, m[i].indices,
m[i].numIndices*sizeof(*m[i].indices));
newm++;
}
+8 -8
View File
@@ -800,7 +800,7 @@ setLights(WorldLights *lightData)
l = lightData->directionals[i];
uniformObject.lightParams[n].type = 1.0f;
uniformObject.lightColor[n] = l->color;
memcpy(&uniformObject.lightDirection[n], &l->getFrame()->getLTM()->at, sizeof(V3d));
memcpy_neon(&uniformObject.lightDirection[n], &l->getFrame()->getLTM()->at, sizeof(V3d));
bits |= VSLIGHT_POINT;
n++;
if(n >= MAX_LIGHTS)
@@ -815,7 +815,7 @@ setLights(WorldLights *lightData)
uniformObject.lightParams[n].type = 2.0f;
uniformObject.lightParams[n].radius = l->radius;
uniformObject.lightColor[n] = l->color;
memcpy(&uniformObject.lightPosition[n], &l->getFrame()->getLTM()->pos, sizeof(V3d));
memcpy_neon(&uniformObject.lightPosition[n], &l->getFrame()->getLTM()->pos, sizeof(V3d));
bits |= VSLIGHT_POINT;
n++;
if(n >= MAX_LIGHTS)
@@ -827,8 +827,8 @@ setLights(WorldLights *lightData)
uniformObject.lightParams[n].minusCosAngle = l->minusCosAngle;
uniformObject.lightParams[n].radius = l->radius;
uniformObject.lightColor[n] = l->color;
memcpy(&uniformObject.lightPosition[n], &l->getFrame()->getLTM()->pos, sizeof(V3d));
memcpy(&uniformObject.lightDirection[n], &l->getFrame()->getLTM()->at, sizeof(V3d));
memcpy_neon(&uniformObject.lightPosition[n], &l->getFrame()->getLTM()->pos, sizeof(V3d));
memcpy_neon(&uniformObject.lightDirection[n], &l->getFrame()->getLTM()->at, sizeof(V3d));
// lower bound of falloff
if(l->getType() == Light::SOFTSPOT)
uniformObject.lightParams[n].hardSpot = 0.0f;
@@ -851,14 +851,14 @@ out:
void
setProjectionMatrix(float32 *mat)
{
memcpy(&uniformScene.proj, mat, 64);
memcpy_neon(&uniformScene.proj, mat, 64);
sceneDirty = 1;
}
void
setViewMatrix(float32 *mat)
{
memcpy(&uniformScene.view, mat, 64);
memcpy_neon(&uniformScene.view, mat, 64);
sceneDirty = 1;
}
@@ -1035,7 +1035,7 @@ beginUpdate(Camera *cam)
view[13] = inv.pos.y;
view[14] = inv.pos.z;
view[15] = 1.0f;
memcpy(&cam->devView, &view, sizeof(RawMatrix));
memcpy_neon(&cam->devView, &view, sizeof(RawMatrix));
setViewMatrix(view);
// Projection Matrix
@@ -1070,7 +1070,7 @@ beginUpdate(Camera *cam)
proj[14] = 2.0f*invz;
proj[15] = 1.0f;
}
memcpy(&cam->devProj, &proj, sizeof(RawMatrix));
memcpy_neon(&cam->devProj, &proj, sizeof(RawMatrix));
setProjectionMatrix(proj);
if(rwStateCache.fogStart != cam->fogPlane){
+3 -7
View File
@@ -30,11 +30,7 @@ freeInstanceData(Geometry *geometry)
return;
InstanceDataHeader *header = (InstanceDataHeader*)geometry->instData;
geometry->instData = nil;
glDeleteBuffers(1, &header->ibo);
glDeleteBuffers(1, &header->vbo);
#ifdef RW_GL_USE_VAOS
glDeleteBuffers(1, &header->vao);
#endif
rwFree(header->indexBuffer);
rwFree(header->vertexBuffer);
rwFree(header->attribDesc);
@@ -76,7 +72,7 @@ instanceMesh(rw::ObjPipeline *rwpipe, Geometry *geo)
inst->vertexAlpha = 0;
inst->program = 0;
inst->offset = offset;
memcpy((uint8*)header->indexBuffer + inst->offset,
memcpy_neon((uint8*)header->indexBuffer + inst->offset,
mesh->indices, inst->numIndex*2);
offset += inst->numIndex*2;
mesh++;
@@ -228,7 +224,7 @@ defaultInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance)
for(a = tmpAttribs; a != &tmpAttribs[header->numAttribs]; a++)
a->stride = stride;
header->attribDesc = rwNewT(AttribDesc, header->numAttribs, MEMDUR_EVENT | ID_GEOMETRY);
memcpy(header->attribDesc, tmpAttribs,
memcpy_neon(header->attribDesc, tmpAttribs,
header->numAttribs*sizeof(AttribDesc));
//
+1 -1
View File
@@ -113,7 +113,7 @@ skinInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance)
for(a = tmpAttribs; a != &tmpAttribs[header->numAttribs]; a++)
a->stride = stride;
header->attribDesc = rwNewT(AttribDesc, header->numAttribs, MEMDUR_EVENT | ID_GEOMETRY);
memcpy(header->attribDesc, tmpAttribs,
memcpy_neon(header->attribDesc, tmpAttribs,
header->numAttribs*sizeof(AttribDesc));
//
+3 -3
View File
@@ -116,7 +116,7 @@ packattrib(uint8 *dst, float32 *src, AttribDesc *a, float32 scale=1.0f)
switch(a->type){
case 0: // float
memcpy(dst, src, a->size*4);
memcpy_neon(dst, src, a->size*4);
break;
// TODO: maybe have loop inside if?
@@ -170,7 +170,7 @@ unpackattrib(float *dst, uint8 *src, AttribDesc *a, float32 scale=1.0f)
switch(a->type){
case 0: // float
memcpy(dst, src, a->size*4);
memcpy_neon(dst, src, a->size*4);
break;
// TODO: maybe have loop inside if?
@@ -637,7 +637,7 @@ skinUninstanceCB(Geometry *geo)
uint8 *data = skin->data;
float *invMats = skin->inverseMatrices;
skin->init(skin->numBones, skin->numBones, geo->numVertices);
memcpy(skin->inverseMatrices, invMats, skin->numBones*64);
memcpy_neon(skin->inverseMatrices, invMats, skin->numBones*64);
rwFree(data);
uint8 *p;
+4 -2
View File
@@ -17,6 +17,8 @@
#define PLUGIN_ID ID_IMAGE
#include <vitaGL.h>
namespace rw {
int32 Image::numAllocated;
@@ -476,7 +478,7 @@ Image::palettize(int32 depth)
this->palette = nil;
this->setPixels(newpixels);
this->allocate();
memcpy(this->palette, colors, 4*(1<<depth));
memcpy_neon(this->palette, colors, 4*(1<<depth));
quant.destroy();
}
@@ -681,7 +683,7 @@ rwstrdup(const char *s)
size_t len = strlen(s)+1;
t = (char*)rwMalloc(len, MEMDUR_EVENT);
if(t)
memcpy(t, s, len);
memcpy_neon(t, s, len);
return t;
}
+1 -1
View File
@@ -375,7 +375,7 @@ copyMaterialMatFX(void *dst, void *src, int32 offset, int32)
return dst;
MatFX *dstfx = rwNewT(MatFX, 1, MEMDUR_EVENT | ID_MATFX);
*PLUGINOFFSET(MatFX*, dst, offset) = dstfx;
memcpy(dstfx, srcfx, sizeof(MatFX));
memcpy_neon(dstfx, srcfx, sizeof(MatFX));
for(int i = 0; i < 2; i++)
switch(dstfx->fx[i].type){
case MatFX::BUMPMAP:
+7 -5
View File
@@ -9,6 +9,8 @@
#include "rwobjects.h"
#include "rwengine.h"
#include <vitaGL.h>
#define COLOR_ARGB(a,r,g,b) \
((uint32)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))
@@ -70,7 +72,7 @@ instV4d(int type, uint8 *dst, V4d *src, uint32 numVertices, uint32 stride)
{
if(type == VERT_FLOAT4)
for(uint32 i = 0; i < numVertices; i++){
memcpy(dst, src, 16);
memcpy_neon(dst, src, 16);
dst += stride;
src++;
}
@@ -83,7 +85,7 @@ instV3d(int type, uint8 *dst, V3d *src, uint32 numVertices, uint32 stride)
{
if(type == VERT_FLOAT3)
for(uint32 i = 0; i < numVertices; i++){
memcpy(dst, src, 12);
memcpy_neon(dst, src, 12);
dst += stride;
src++;
}
@@ -105,7 +107,7 @@ uninstV3d(int type, V3d *dst, uint8 *src, uint32 numVertices, uint32 stride)
{
if(type == VERT_FLOAT3)
for(uint32 i = 0; i < numVertices; i++){
memcpy(dst, src, 12);
memcpy_neon(dst, src, 12);
src += stride;
dst++;
}
@@ -135,7 +137,7 @@ instTexCoords(int type, uint8 *dst, TexCoords *src, uint32 numVertices, uint32 s
{
assert(type == VERT_FLOAT2);
for(uint32 i = 0; i < numVertices; i++){
memcpy(dst, src, 8);
memcpy_neon(dst, src, 8);
dst += stride;
src++;
}
@@ -146,7 +148,7 @@ uninstTexCoords(int type, TexCoords *dst, uint8 *src, uint32 numVertices, uint32
{
assert(type == VERT_FLOAT2);
for(uint32 i = 0; i < numVertices; i++){
memcpy(dst, src, 8);
memcpy_neon(dst, src, 8);
src += stride;
dst++;
}
+7 -5
View File
@@ -12,6 +12,8 @@
#include "lodepng/lodepng.h"
#include <vitaGL.h>
#ifdef _WIN32
/* srsly? */
#define strdup _strdup
@@ -46,20 +48,20 @@ readPNG(const char *filename)
if(state.info_raw.bitdepth == 4 && state.info_raw.colortype == LCT_PALETTE){
image = Image::create(w, h, 4);
image->allocate();
memcpy(image->palette, state.info_raw.palette, state.info_raw.palettesize*4);
memcpy_neon(image->palette, state.info_raw.palette, state.info_raw.palettesize*4);
expandPal4_BE(image->pixels, image->stride, raw, w/2, w, h);
}else if(state.info_raw.bitdepth == 8){
switch(state.info_raw.colortype){
case LCT_PALETTE:
image = Image::create(w, h, state.info_raw.palettesize <= 16 ? 4 : 8);
image->allocate();
memcpy(image->palette, state.info_raw.palette, state.info_raw.palettesize*4);
memcpy(image->pixels, raw, w*h);
memcpy_neon(image->palette, state.info_raw.palette, state.info_raw.palettesize*4);
memcpy_neon(image->pixels, raw, w*h);
break;
case LCT_RGB:
image = Image::create(w, h, 24);
image->allocate();
memcpy(image->pixels, raw, w*h*3);
memcpy_neon(image->pixels, raw, w*h*3);
break;
default:
// Second try: just load as 32 bit
@@ -74,7 +76,7 @@ readPNG(const char *filename)
case LCT_RGBA:
image = Image::create(w, h, 32);
image->allocate();
memcpy(image->pixels, raw, w*h*4);
memcpy_neon(image->pixels, raw, w*h*4);
break;
}
}
+4 -4
View File
@@ -64,11 +64,11 @@ copySkin(void *dst, void *src, int32 offset, int32)
assert(0 && "can't copy skin yet");
dstskin->init(srcskin->numBones, srcskin->numUsedBones,
geometry->numVertices);
memcpy(dstskin->usedBones, srcskin->usedBones, srcskin->numUsedBones);
memcpy(dstskin->inverseMatrices, srcskin->inverseMatrices,
memcpy_neon(dstskin->usedBones, srcskin->usedBones, srcskin->numUsedBones);
memcpy_neon(dstskin->inverseMatrices, srcskin->inverseMatrices,
srcskin->numBones*64);
memcpy(dstskin->indices, srcskin->indices, geometry->numVertices*4);
memcpy(dstskin->weights, srcskin->weights, geometry->numVertices*16);
memcpy_neon(dstskin->indices, srcskin->indices, geometry->numVertices*4);
memcpy_neon(dstskin->weights, srcskin->weights, geometry->numVertices*16);
return dst;
}
+3 -1
View File
@@ -11,6 +11,8 @@
#include "rwobjects.h"
#include "rwengine.h"
#include <vitaGL.h>
#define PLUGIN_ID 2
namespace rw {
@@ -609,7 +611,7 @@ printSmesh(&smesh);
md[i].numIndices = ms[i].numIndices;
md[i].indices = indices;
indices += md[i].numIndices;
memcpy(md[i].indices, ms[i].indices, md[i].numIndices*sizeof(uint16));
memcpy_neon(md[i].indices, ms[i].indices, md[i].numIndices*sizeof(uint16));
rwFree(ms[i].indices);
}
rwFree(header);
+5 -3
View File
@@ -11,6 +11,8 @@
#include "rwengine.h"
#include "rwuserdata.h"
#include <vitaGL.h>
#define PLUGIN_ID ID_USERDATA
namespace rw {
@@ -90,11 +92,11 @@ copyUserData(void *dst, void *src, int32 offset, int32)
switch(srca->datatype){
case USERDATAINT:
dsta->data = (int32*)udMalloc(sizeof(int32)*dsta->numElements);
memcpy(dsta->data, srca->data, sizeof(int32)*dsta->numElements);
memcpy_neon(dsta->data, srca->data, sizeof(int32)*dsta->numElements);
break;
case USERDATAFLOAT:
dsta->data = (float32*)udMalloc(sizeof(float32)*dsta->numElements);
memcpy(dsta->data, srca->data, sizeof(float32)*dsta->numElements);
memcpy_neon(dsta->data, srca->data, sizeof(float32)*dsta->numElements);
break;
case USERDATASTRING:
dststrar = (char**)udMalloc(sizeof(char*)*dsta->numElements);
@@ -241,7 +243,7 @@ UserDataExtension::add(const char *name, int32 datatype, int32 numElements)
a = (UserDataArray*)udMalloc((this->numArrays+1)*sizeof(UserDataArray));
if(a == nil)
return -1;
memcpy(a, this->arrays, this->numArrays*sizeof(UserDataArray));
memcpy_neon(a, this->arrays, this->numArrays*sizeof(UserDataArray));
rwFree(this->arrays);
this->arrays = a;
i = this->numArrays++;