Skip to content

Commit

Permalink
fix AK_MORPH_P1P2N1N2 interleaving
Browse files Browse the repository at this point in the history
  • Loading branch information
recp committed Sep 6, 2023
1 parent afc50d6 commit b7ca821
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
7 changes: 4 additions & 3 deletions include/ak/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ typedef struct AkInstanceSkin {
* @brief input/attribute layout in shader orr in interleaved buffer
*/
typedef enum AkMorphInterleaveLayout {
AK_MORPH_ILAYOUT_P1P2N1N2 = 0,
AK_MORPH_ILAYOUT_P1N1P2N2 = 1,
AK_MORPH_ILAYOUT_P1N1P2N2_ORIGINAL = 2,
AK_MORPH_P1P2N1N2 = 0,
AK_MORPH_P1N1P2N2 = 1,
AK_MORPH_P1P2N1N2_IDENTICAL = 2,
AK_MORPH_P1N1P2N2_IDENTICAL = 3,
} AkMorphInterleaveLayout;

/*!
Expand Down
46 changes: 25 additions & 21 deletions src/morph/intr.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,13 @@ ak_morphInterleave(AkGeometry * __restrict baseMesh,
FListItem *finp;
char *src, *dst;
uint16_t *offs2, *offs1;
size_t srcStride, targetStride, compSize;
uint32_t j, k, count, nTargets, inpOff;
uint32_t srcStride, targetStride, compSize;
uint32_t i, j, k, count, nTargets, inpOff, inpOff2;

/* ispect is not called, we need to inspect it with default behavior */
if (!morph->inspectResult) {
if (ak_morphInspect(baseMesh, morph, NULL, 0, false, true) != AK_OK) { return AK_ERR; }
if (!morph->inspectResult
|| ak_morphInspect(baseMesh, morph, NULL, 0, false, true) != AK_OK) {
return AK_ERR;
}

if (!(morphView = morph->inspectResult)
Expand All @@ -219,7 +220,7 @@ ak_morphInterleave(AkGeometry * __restrict baseMesh,

dst = (char *)destBuff;
nTargets = morphView->nTargets;
targetStride = morphView->interleaveByteStride;
targetStride = (uint32_t)morphView->interleaveByteStride;
count = morphView->accessorAccessCount;
offs1 = alloca(base->inputsCount * sizeof(*offs1));
offs2 = alloca(base->inputsCount * sizeof(*offs2));
Expand All @@ -233,40 +234,42 @@ ak_morphInterleave(AkGeometry * __restrict baseMesh,
offs1 -- P1 -- offs2 -- P2
*/
switch (layout) {
case AK_MORPH_ILAYOUT_P1P2N1N2: {
case AK_MORPH_P1P2N1N2: {
for (j = 0, inpOff = 0;
finp && (inp = finp->data) && (acc = inp->accessor);
finp = finp->next, j++) {
compSize = acc->fillByteSize;
offs1[j] = inpOff + compSize * nTargets;
offs2[j] = targetStride - offs1[j];
inpOff += offs1[j];
compSize = (uint32_t)acc->fillByteSize;
offs1[j] = inpOff;
offs2[j] = compSize;
inpOff += compSize * nTargets;
}
break;
}
case AK_MORPH_ILAYOUT_P1N1P2N2: {
case AK_MORPH_P1N1P2N2: {
for (j = 0, inpOff = 0;
finp && (inp = finp->data) && (acc = inp->accessor);
finp = finp->next, j++) {
compSize = acc->fillByteSize;
offs1[j] = inpOff + compSize;
compSize = (uint32_t)acc->fillByteSize;
offs1[j] = inpOff;
offs2[j] = targetStride - offs1[j];
inpOff += offs1[j];
}
break;
}
case AK_MORPH_ILAYOUT_P1N1P2N2_ORIGINAL: {
printf("AK_MORPH_ILAYOUT_P1N1P2N2_ORIGINAL is not implemented yet.");
case AK_MORPH_P1P2N1N2_IDENTICAL:
case AK_MORPH_P1N1P2N2_IDENTICAL: {
// TODO: implement these
printf("not implemented yet.");
return AK_ERR;
}
default: return AK_ERR;
}

/* TODO: optimize these operations */

for (;
for (i = 0;
targetView && (finp = targetView->inputs);
targetView = targetView->next)
targetView = targetView->next, i++)
{
for (j = 0;
finp
Expand All @@ -276,12 +279,13 @@ ak_morphInterleave(AkGeometry * __restrict baseMesh,
&& (src = (char *)buf->data + acc->byteOffset);
finp = finp->next, j++)
{
srcStride = acc->byteStride;
compSize = acc->fillByteSize;
inpOff = offs1[j] + offs2[j];
srcStride = (uint32_t)acc->byteStride;
compSize = (uint32_t)acc->fillByteSize;
inpOff = offs1[j] + offs2[j] * i;
inpOff2 = targetStride - compSize;

for (k = 0; k < count; k++) {
memcpy(dst + inpOff * k, src + srcStride * k, compSize);
memcpy(dst + inpOff + targetStride * k, src + srcStride * k, compSize);
}
}
}
Expand Down

0 comments on commit b7ca821

Please sign in to comment.