Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 79ad3f25 authored by Stephen Hines's avatar Stephen Hines
Browse files

Support missing RS vector types.

Change-Id: I87eae3cc79c3963d5a8edf16cc26eee6d93d81d7
parent b2af97e9
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -16782,6 +16782,9 @@ package android.renderscript {
    method public void addF32(android.renderscript.Float3);
    method public void addF32(android.renderscript.Float4);
    method public void addF64(double);
    method public void addF64(android.renderscript.Double2);
    method public void addF64(android.renderscript.Double3);
    method public void addF64(android.renderscript.Double4);
    method public void addI16(short);
    method public void addI16(android.renderscript.Short2);
    method public void addI16(android.renderscript.Short3);
@@ -16791,6 +16794,9 @@ package android.renderscript {
    method public void addI32(android.renderscript.Int3);
    method public void addI32(android.renderscript.Int4);
    method public void addI64(long);
    method public void addI64(android.renderscript.Long2);
    method public void addI64(android.renderscript.Long3);
    method public void addI64(android.renderscript.Long4);
    method public void addI8(byte);
    method public void addI8(android.renderscript.Byte2);
    method public void addI8(android.renderscript.Byte3);
@@ -16808,6 +16814,9 @@ package android.renderscript {
    method public void addU32(android.renderscript.Long3);
    method public void addU32(android.renderscript.Long4);
    method public void addU64(long);
    method public void addU64(android.renderscript.Long2);
    method public void addU64(android.renderscript.Long3);
    method public void addU64(android.renderscript.Long4);
    method public void addU8(short);
    method public void addU8(android.renderscript.Short2);
    method public void addU8(android.renderscript.Short3);
+48 −0
Original line number Diff line number Diff line
@@ -165,6 +165,22 @@ public class FieldPacker {
        addF32(v.w);
    }

    public void addF64(Double2 v) {
        addF64(v.x);
        addF64(v.y);
    }
    public void addF64(Double3 v) {
        addF64(v.x);
        addF64(v.y);
        addF64(v.z);
    }
    public void addF64(Double4 v) {
        addF64(v.x);
        addF64(v.y);
        addF64(v.z);
        addF64(v.w);
    }

    public void addI8(Byte2 v) {
        addI8(v.x);
        addI8(v.y);
@@ -261,6 +277,38 @@ public class FieldPacker {
        addU32(v.w);
    }

    public void addI64(Long2 v) {
        addI64(v.x);
        addI64(v.y);
    }
    public void addI64(Long3 v) {
        addI64(v.x);
        addI64(v.y);
        addI64(v.z);
    }
    public void addI64(Long4 v) {
        addI64(v.x);
        addI64(v.y);
        addI64(v.z);
        addI64(v.w);
    }

    public void addU64(Long2 v) {
        addU64(v.x);
        addU64(v.y);
    }
    public void addU64(Long3 v) {
        addU64(v.x);
        addU64(v.y);
        addU64(v.z);
    }
    public void addU64(Long4 v) {
        addU64(v.x);
        addU64(v.y);
        addU64(v.z);
        addU64(v.w);
    }

    public void addMatrix(Matrix4f v) {
        for (int i=0; i < v.mMat.length; i++) {
            addF32(v.mMat[i]);
+2 −1
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 The Android Open Source Project
 * Copyright (C) 2008-2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -65,6 +65,7 @@ public class RSTestCore {
        unitTests = new ArrayList<UnitTest>();

        unitTests.add(new UT_primitives(this, mRes, mCtx));
        unitTests.add(new UT_vector(this, mRes, mCtx));
        unitTests.add(new UT_rsdebug(this, mRes, mCtx));
        unitTests.add(new UT_rstime(this, mRes, mCtx));
        unitTests.add(new UT_rstypes(this, mRes, mCtx));
+318 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.rs.test;

import android.content.Context;
import android.content.res.Resources;
import android.renderscript.*;

public class UT_vector extends UnitTest {
    private Resources mRes;

    protected UT_vector(RSTestCore rstc, Resources res, Context ctx) {
        super(rstc, "Vector", ctx);
        mRes = res;
    }

    private boolean initializeGlobals(ScriptC_vector s) {
        Float2 F2 = s.get_f2();
        if (F2.x != 1.0f || F2.y != 2.0f) {
            return false;
        }
        F2.x = 2.99f;
        F2.y = 3.99f;
        s.set_f2(F2);

        Float3 F3 = s.get_f3();
        if (F3.x != 1.0f || F3.y != 2.0f || F3.z != 3.0f) {
            return false;
        }
        F3.x = 2.99f;
        F3.y = 3.99f;
        F3.z = 4.99f;
        s.set_f3(F3);

        Float4 F4 = s.get_f4();
        if (F4.x != 1.0f || F4.y != 2.0f || F4.z != 3.0f || F4.w != 4.0f) {
            return false;
        }
        F4.x = 2.99f;
        F4.y = 3.99f;
        F4.z = 4.99f;
        F4.w = 5.99f;
        s.set_f4(F4);

        Double2 D2 = s.get_d2();
        if (D2.x != 1.0 || D2.y != 2.0) {
            return false;
        }
        D2.x = 2.99;
        D2.y = 3.99;
        s.set_d2(D2);

        Double3 D3 = s.get_d3();
        if (D3.x != 1.0 || D3.y != 2.0 || D3.z != 3.0) {
            return false;
        }
        D3.x = 2.99;
        D3.y = 3.99;
        D3.z = 4.99;
        s.set_d3(D3);

        Double4 D4 = s.get_d4();
        if (D4.x != 1.0 || D4.y != 2.0 || D4.z != 3.0 || D4.w != 4.0) {
            return false;
        }
        D4.x = 2.99;
        D4.y = 3.99;
        D4.z = 4.99;
        D4.w = 5.99;
        s.set_d4(D4);

        Byte2 B2 = s.get_i8_2();
        if (B2.x != 1 || B2.y != 2) {
            return false;
        }
        B2.x = 2;
        B2.y = 3;
        s.set_i8_2(B2);

        Byte3 B3 = s.get_i8_3();
        if (B3.x != 1 || B3.y != 2 || B3.z != 3) {
            return false;
        }
        B3.x = 2;
        B3.y = 3;
        B3.z = 4;
        s.set_i8_3(B3);

        Byte4 B4 = s.get_i8_4();
        if (B4.x != 1 || B4.y != 2 || B4.z != 3 || B4.w != 4) {
            return false;
        }
        B4.x = 2;
        B4.y = 3;
        B4.z = 4;
        B4.w = 5;
        s.set_i8_4(B4);

        Short2 S2 = s.get_u8_2();
        if (S2.x != 1 || S2.y != 2) {
            return false;
        }
        S2.x = 2;
        S2.y = 3;
        s.set_u8_2(S2);

        Short3 S3 = s.get_u8_3();
        if (S3.x != 1 || S3.y != 2 || S3.z != 3) {
            return false;
        }
        S3.x = 2;
        S3.y = 3;
        S3.z = 4;
        s.set_u8_3(S3);

        Short4 S4 = s.get_u8_4();
        if (S4.x != 1 || S4.y != 2 || S4.z != 3 || S4.w != 4) {
            return false;
        }
        S4.x = 2;
        S4.y = 3;
        S4.z = 4;
        S4.w = 5;
        s.set_u8_4(S4);

        S2 = s.get_i16_2();
        if (S2.x != 1 || S2.y != 2) {
            return false;
        }
        S2.x = 2;
        S2.y = 3;
        s.set_i16_2(S2);

        S3 = s.get_i16_3();
        if (S3.x != 1 || S3.y != 2 || S3.z != 3) {
            return false;
        }
        S3.x = 2;
        S3.y = 3;
        S3.z = 4;
        s.set_i16_3(S3);

        S4 = s.get_i16_4();
        if (S4.x != 1 || S4.y != 2 || S4.z != 3 || S4.w != 4) {
            return false;
        }
        S4.x = 2;
        S4.y = 3;
        S4.z = 4;
        S4.w = 5;
        s.set_i16_4(S4);

        Int2 I2 = s.get_u16_2();
        if (I2.x != 1 || I2.y != 2) {
            return false;
        }
        I2.x = 2;
        I2.y = 3;
        s.set_u16_2(I2);

        Int3 I3 = s.get_u16_3();
        if (I3.x != 1 || I3.y != 2 || I3.z != 3) {
            return false;
        }
        I3.x = 2;
        I3.y = 3;
        I3.z = 4;
        s.set_u16_3(I3);

        Int4 I4 = s.get_u16_4();
        if (I4.x != 1 || I4.y != 2 || I4.z != 3 || I4.w != 4) {
            return false;
        }
        I4.x = 2;
        I4.y = 3;
        I4.z = 4;
        I4.w = 5;
        s.set_u16_4(I4);

        I2 = s.get_i32_2();
        if (I2.x != 1 || I2.y != 2) {
            return false;
        }
        I2.x = 2;
        I2.y = 3;
        s.set_i32_2(I2);

        I3 = s.get_i32_3();
        if (I3.x != 1 || I3.y != 2 || I3.z != 3) {
            return false;
        }
        I3.x = 2;
        I3.y = 3;
        I3.z = 4;
        s.set_i32_3(I3);

        I4 = s.get_i32_4();
        if (I4.x != 1 || I4.y != 2 || I4.z != 3 || I4.w != 4) {
            return false;
        }
        I4.x = 2;
        I4.y = 3;
        I4.z = 4;
        I4.w = 5;
        s.set_i32_4(I4);

        Long2 L2 = s.get_u32_2();
        if (L2.x != 1 || L2.y != 2) {
            return false;
        }
        L2.x = 2;
        L2.y = 3;
        s.set_u32_2(L2);

        Long3 L3 = s.get_u32_3();
        if (L3.x != 1 || L3.y != 2 || L3.z != 3) {
            return false;
        }
        L3.x = 2;
        L3.y = 3;
        L3.z = 4;
        s.set_u32_3(L3);

        Long4 L4 = s.get_u32_4();
        if (L4.x != 1 || L4.y != 2 || L4.z != 3 || L4.w != 4) {
            return false;
        }
        L4.x = 2;
        L4.y = 3;
        L4.z = 4;
        L4.w = 5;
        s.set_u32_4(L4);

        L2 = s.get_i64_2();
        if (L2.x != 1 || L2.y != 2) {
            return false;
        }
        L2.x = 2;
        L2.y = 3;
        s.set_i64_2(L2);

        L3 = s.get_i64_3();
        if (L3.x != 1 || L3.y != 2 || L3.z != 3) {
            return false;
        }
        L3.x = 2;
        L3.y = 3;
        L3.z = 4;
        s.set_i64_3(L3);

        L4 = s.get_i64_4();
        if (L4.x != 1 || L4.y != 2 || L4.z != 3 || L4.w != 4) {
            return false;
        }
        L4.x = 2;
        L4.y = 3;
        L4.z = 4;
        L4.w = 5;
        s.set_i64_4(L4);

        L2 = s.get_u64_2();
        if (L2.x != 1 || L2.y != 2) {
            return false;
        }
        L2.x = 2;
        L2.y = 3;
        s.set_u64_2(L2);

        L3 = s.get_u64_3();
        if (L3.x != 1 || L3.y != 2 || L3.z != 3) {
            return false;
        }
        L3.x = 2;
        L3.y = 3;
        L3.z = 4;
        s.set_u64_3(L3);

        L4 = s.get_u64_4();
        if (L4.x != 1 || L4.y != 2 || L4.z != 3 || L4.w != 4) {
            return false;
        }
        L4.x = 2;
        L4.y = 3;
        L4.z = 4;
        L4.w = 5;
        s.set_u64_4(L4);

        return true;
    }

    public void run() {
        RenderScript pRS = RenderScript.create(mCtx);
        ScriptC_vector s = new ScriptC_vector(pRS, mRes, R.raw.vector);
        pRS.setMessageHandler(mRsMessage);
        if (!initializeGlobals(s)) {
            result = -1;
        } else {
            s.invoke_vector_test();
            pRS.finish();
            waitForMessage();
        }
        pRS.destroy();
    }
}
+198 −0
Original line number Diff line number Diff line
#include "shared.rsh"

// Testing vector types
float2 f2 = { 1.0f, 2.0f };
float3 f3 = { 1.0f, 2.0f, 3.0f };
float4 f4 = { 1.0f, 2.0f, 3.0f, 4.0f };

double2 d2 = { 1.0, 2.0 };
double3 d3 = { 1.0, 2.0, 3.0 };
double4 d4 = { 1.0, 2.0, 3.0, 4.0 };

char2 i8_2 = { 1, 2 };
char3 i8_3 = { 1, 2, 3 };
char4 i8_4 = { 1, 2, 3, 4 };

uchar2 u8_2 = { 1, 2 };
uchar3 u8_3 = { 1, 2, 3 };
uchar4 u8_4 = { 1, 2, 3, 4 };

short2 i16_2 = { 1, 2 };
short3 i16_3 = { 1, 2, 3 };
short4 i16_4 = { 1, 2, 3, 4 };

ushort2 u16_2 = { 1, 2 };
ushort3 u16_3 = { 1, 2, 3 };
ushort4 u16_4 = { 1, 2, 3, 4 };

int2 i32_2 = { 1, 2 };
int3 i32_3 = { 1, 2, 3 };
int4 i32_4 = { 1, 2, 3, 4 };

uint2 u32_2 = { 1, 2 };
uint3 u32_3 = { 1, 2, 3 };
uint4 u32_4 = { 1, 2, 3, 4 };

long2 i64_2 = { 1, 2 };
long3 i64_3 = { 1, 2, 3 };
long4 i64_4 = { 1, 2, 3, 4 };

ulong2 u64_2 = { 1, 2 };
ulong3 u64_3 = { 1, 2, 3 };
ulong4 u64_4 = { 1, 2, 3, 4 };

static bool test_vector_types() {
    bool failed = false;

    rsDebug("Testing F32", 0);
    _RS_ASSERT(f2.x == 2.99f);
    _RS_ASSERT(f2.y == 3.99f);

    _RS_ASSERT(f3.x == 2.99f);
    _RS_ASSERT(f3.y == 3.99f);
    _RS_ASSERT(f3.z == 4.99f);

    _RS_ASSERT(f4.x == 2.99f);
    _RS_ASSERT(f4.y == 3.99f);
    _RS_ASSERT(f4.z == 4.99f);
    _RS_ASSERT(f4.w == 5.99f);

    rsDebug("Testing F64", 0);
    _RS_ASSERT(d2.x == 2.99);
    _RS_ASSERT(d2.y == 3.99);

    _RS_ASSERT(d3.x == 2.99);
    _RS_ASSERT(d3.y == 3.99);
    _RS_ASSERT(d3.z == 4.99);

    _RS_ASSERT(d4.x == 2.99);
    _RS_ASSERT(d4.y == 3.99);
    _RS_ASSERT(d4.z == 4.99);
    _RS_ASSERT(d4.w == 5.99);

    rsDebug("Testing I8", 0);
    _RS_ASSERT(i8_2.x == 2);
    _RS_ASSERT(i8_2.y == 3);

    _RS_ASSERT(i8_3.x == 2);
    _RS_ASSERT(i8_3.y == 3);
    _RS_ASSERT(i8_3.z == 4);

    _RS_ASSERT(i8_4.x == 2);
    _RS_ASSERT(i8_4.y == 3);
    _RS_ASSERT(i8_4.z == 4);
    _RS_ASSERT(i8_4.w == 5);

    rsDebug("Testing U8", 0);
    _RS_ASSERT(u8_2.x == 2);
    _RS_ASSERT(u8_2.y == 3);

    _RS_ASSERT(u8_3.x == 2);
    _RS_ASSERT(u8_3.y == 3);
    _RS_ASSERT(u8_3.z == 4);

    _RS_ASSERT(u8_4.x == 2);
    _RS_ASSERT(u8_4.y == 3);
    _RS_ASSERT(u8_4.z == 4);
    _RS_ASSERT(u8_4.w == 5);

    rsDebug("Testing I16", 0);
    _RS_ASSERT(i16_2.x == 2);
    _RS_ASSERT(i16_2.y == 3);

    _RS_ASSERT(i16_3.x == 2);
    _RS_ASSERT(i16_3.y == 3);
    _RS_ASSERT(i16_3.z == 4);

    _RS_ASSERT(i16_4.x == 2);
    _RS_ASSERT(i16_4.y == 3);
    _RS_ASSERT(i16_4.z == 4);
    _RS_ASSERT(i16_4.w == 5);

    rsDebug("Testing U16", 0);
    _RS_ASSERT(u16_2.x == 2);
    _RS_ASSERT(u16_2.y == 3);

    _RS_ASSERT(u16_3.x == 2);
    _RS_ASSERT(u16_3.y == 3);
    _RS_ASSERT(u16_3.z == 4);

    _RS_ASSERT(u16_4.x == 2);
    _RS_ASSERT(u16_4.y == 3);
    _RS_ASSERT(u16_4.z == 4);
    _RS_ASSERT(u16_4.w == 5);

    rsDebug("Testing I32", 0);
    _RS_ASSERT(i32_2.x == 2);
    _RS_ASSERT(i32_2.y == 3);

    _RS_ASSERT(i32_3.x == 2);
    _RS_ASSERT(i32_3.y == 3);
    _RS_ASSERT(i32_3.z == 4);

    _RS_ASSERT(i32_4.x == 2);
    _RS_ASSERT(i32_4.y == 3);
    _RS_ASSERT(i32_4.z == 4);
    _RS_ASSERT(i32_4.w == 5);

    rsDebug("Testing U32", 0);
    _RS_ASSERT(u32_2.x == 2);
    _RS_ASSERT(u32_2.y == 3);

    _RS_ASSERT(u32_3.x == 2);
    _RS_ASSERT(u32_3.y == 3);
    _RS_ASSERT(u32_3.z == 4);

    _RS_ASSERT(u32_4.x == 2);
    _RS_ASSERT(u32_4.y == 3);
    _RS_ASSERT(u32_4.z == 4);
    _RS_ASSERT(u32_4.w == 5);

    rsDebug("Testing I64", 0);
    _RS_ASSERT(i64_2.x == 2);
    _RS_ASSERT(i64_2.y == 3);

    _RS_ASSERT(i64_3.x == 2);
    _RS_ASSERT(i64_3.y == 3);
    _RS_ASSERT(i64_3.z == 4);

    _RS_ASSERT(i64_4.x == 2);
    _RS_ASSERT(i64_4.y == 3);
    _RS_ASSERT(i64_4.z == 4);
    _RS_ASSERT(i64_4.w == 5);

    rsDebug("Testing U64", 0);
    _RS_ASSERT(u64_2.x == 2);
    _RS_ASSERT(u64_2.y == 3);

    _RS_ASSERT(u64_3.x == 2);
    _RS_ASSERT(u64_3.y == 3);
    _RS_ASSERT(u64_3.z == 4);

    _RS_ASSERT(u64_4.x == 2);
    _RS_ASSERT(u64_4.y == 3);
    _RS_ASSERT(u64_4.z == 4);
    _RS_ASSERT(u64_4.w == 5);

    if (failed) {
        rsDebug("test_vector FAILED", 0);
    }
    else {
        rsDebug("test_vector PASSED", 0);
    }

    return failed;
}

void vector_test() {
    bool failed = false;
    failed |= test_vector_types();

    if (failed) {
        rsSendToClientBlocking(RS_MSG_TEST_FAILED);
    }
    else {
        rsSendToClientBlocking(RS_MSG_TEST_PASSED);
    }
}