diff options
author | Alex Sakhartchouk <alexst@google.com> | 2011-11-15 15:15:21 -0800 |
---|---|---|
committer | Alex Sakhartchouk <alexst@google.com> | 2011-11-15 15:15:21 -0800 |
commit | e60149d2277da53c4a681b7f3971cf13cd4b012b (patch) | |
tree | 1bb4f453808bf3ebd87d6f724c7b1b73d5d54934 /graphics/java | |
parent | 7b95eba9f47a3992128d59a9ec593b887e4dac0e (diff) | |
download | frameworks_base-e60149d2277da53c4a681b7f3971cf13cd4b012b.zip frameworks_base-e60149d2277da53c4a681b7f3971cf13cd4b012b.tar.gz frameworks_base-e60149d2277da53c4a681b7f3971cf13cd4b012b.tar.bz2 |
Expand RS vector3 types to vector4.
BUG=5609007
The underlying LLVM implementation for vector3 types does this implicitly. If
RS does not adjust its implementation, we will always be misaligned for any
subsequent data after a vector3 type. We previously inserted padding into the
reflected layers from llvm-rs-cc (hence the skip padding part of this change).
We can safely ignore the padding now that the Java/native code is updated to
use the expanded size. The compiler will also need modification to ensure that
we don't mistakenly skip over any end-of-struct padding.
Fixing the 3 component vector padding problem.
Change-Id: If68af42287deb8f4b28addcd19a9fa314656be44
Diffstat (limited to 'graphics/java')
-rw-r--r-- | graphics/java/android/renderscript/Element.java | 22 | ||||
-rw-r--r-- | graphics/java/android/renderscript/Mesh.java | 23 |
2 files changed, 33 insertions, 12 deletions
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java index 8a9ca85..29306e4 100644 --- a/graphics/java/android/renderscript/Element.java +++ b/graphics/java/android/renderscript/Element.java @@ -690,7 +690,11 @@ public class Element extends BaseObj { if ((dt != DataType.UNSIGNED_5_6_5) && (dt != DataType.UNSIGNED_4_4_4_4) && (dt != DataType.UNSIGNED_5_5_5_1)) { - mSize = dt.mSize * size; + if (size == 3) { + mSize = dt.mSize * 4; + } else { + mSize = dt.mSize * size; + } } else { mSize = dt.mSize; } @@ -885,6 +889,7 @@ public class Element extends BaseObj { String[] mElementNames; int[] mArraySizes; int mCount; + int mSkipPadding; /** * Create a builder object. @@ -910,6 +915,21 @@ public class Element extends BaseObj { if (arraySize < 1) { throw new RSIllegalArgumentException("Array size cannot be less than 1."); } + + // Skip padding fields after a vector 3 type. + if (mSkipPadding != 0) { + if (name.startsWith("#padding_")) { + mSkipPadding = 0; + return this; + } + } + + if (element.mVectorSize == 3) { + mSkipPadding = 1; + } else { + mSkipPadding = 0; + } + if(mCount == mElements.length) { Element[] e = new Element[mCount + 8]; String[] s = new String[mCount + 8]; diff --git a/graphics/java/android/renderscript/Mesh.java b/graphics/java/android/renderscript/Mesh.java index 7b3b73f..b6ca58c 100644 --- a/graphics/java/android/renderscript/Mesh.java +++ b/graphics/java/android/renderscript/Mesh.java @@ -514,6 +514,7 @@ public class Mesh extends BaseObj { public static class TriangleMeshBuilder { float mVtxData[]; int mVtxCount; + int mMaxIndex; short mIndexData[]; int mIndexCount; RenderScript mRS; @@ -548,6 +549,7 @@ public class Mesh extends BaseObj { public TriangleMeshBuilder(RenderScript rs, int vtxSize, int flags) { mRS = rs; mVtxCount = 0; + mMaxIndex = 0; mIndexCount = 0; mVtxData = new float[128]; mIndexData = new short[128]; @@ -581,11 +583,13 @@ public class Mesh extends BaseObj { mVtxData[mVtxCount++] = mT0; } if ((mFlags & NORMAL) != 0) { - makeSpace(3); + makeSpace(4); mVtxData[mVtxCount++] = mNX; mVtxData[mVtxCount++] = mNY; mVtxData[mVtxCount++] = mNZ; + mVtxData[mVtxCount++] = 0.0f; } + mMaxIndex ++; } /** @@ -622,10 +626,11 @@ public class Mesh extends BaseObj { if (mVtxSize != 3) { throw new IllegalStateException("add mistmatch with declared components."); } - makeSpace(3); + makeSpace(4); mVtxData[mVtxCount++] = x; mVtxData[mVtxCount++] = y; mVtxData[mVtxCount++] = z; + mVtxData[mVtxCount++] = 1.0f; latch(); return this; } @@ -697,9 +702,9 @@ public class Mesh extends BaseObj { * @return this **/ public TriangleMeshBuilder addTriangle(int idx1, int idx2, int idx3) { - if((idx1 >= mVtxCount) || (idx1 < 0) || - (idx2 >= mVtxCount) || (idx2 < 0) || - (idx3 >= mVtxCount) || (idx3 < 0)) { + if((idx1 >= mMaxIndex) || (idx1 < 0) || + (idx2 >= mMaxIndex) || (idx2 < 0) || + (idx3 >= mMaxIndex) || (idx3 < 0)) { throw new IllegalStateException("Index provided greater than vertex count."); } if ((mIndexCount + 3) >= mIndexData.length) { @@ -729,20 +734,16 @@ public class Mesh extends BaseObj { **/ public Mesh create(boolean uploadToBufferObject) { Element.Builder b = new Element.Builder(mRS); - int floatCount = mVtxSize; b.add(Element.createVector(mRS, Element.DataType.FLOAT_32, mVtxSize), "position"); if ((mFlags & COLOR) != 0) { - floatCount += 4; b.add(Element.F32_4(mRS), "color"); } if ((mFlags & TEXTURE_0) != 0) { - floatCount += 2; b.add(Element.F32_2(mRS), "texture0"); } if ((mFlags & NORMAL) != 0) { - floatCount += 3; b.add(Element.F32_3(mRS), "normal"); } mElement = b.create(); @@ -753,12 +754,12 @@ public class Mesh extends BaseObj { } Builder smb = new Builder(mRS, usage); - smb.addVertexType(mElement, mVtxCount / floatCount); + smb.addVertexType(mElement, mMaxIndex); smb.addIndexSetType(Element.U16(mRS), mIndexCount, Primitive.TRIANGLE); Mesh sm = smb.create(); - sm.getVertexAllocation(0).copy1DRangeFromUnchecked(0, mVtxCount / floatCount, mVtxData); + sm.getVertexAllocation(0).copy1DRangeFromUnchecked(0, mMaxIndex, mVtxData); if(uploadToBufferObject) { if (uploadToBufferObject) { sm.getVertexAllocation(0).syncAll(Allocation.USAGE_SCRIPT); |