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

Commit 0b9bbb6d authored by Jason Sams's avatar Jason Sams
Browse files

DO NOT MERGE. Merge Froyo renderscript to Eclair to support live wallpapers on...

DO NOT MERGE. Merge Froyo renderscript to Eclair to support live wallpapers on droid.  This gives the necessary CPU reduction to allow the wallpapers to work on the slower CPU.

 Committer: Jason Sams <rjsams@android.com>

 On branch droid
 Changes to be committed:
   (use "git reset HEAD <file>..." to unstage)

	modified:   libs/rs/rsAllocation.cpp
	modified:   libs/rs/rsAllocation.h
	modified:   libs/rs/rsContext.cpp
	modified:   libs/rs/rsContext.h
	modified:   libs/rs/rsProgram.cpp
	modified:   libs/rs/rsProgram.h

Delete the old rollo sample which is obsolete.

Fix film init

Begin gl2 support.  Renderscript still uses GL1.1 by default.  However, 2.0 can be enabled and will render most tests correctly.

Fix film

Beging GL2 user shaders.  Switch master to using GL2 by default.

Implement RS tracked defered texture and buffer object uploads.

 Committer: Jason Sams <rjsams@android.com>

 On branch droid
 Changes to be committed:
   (use "git reset HEAD <file>..." to unstage)

	modified:   libs/rs/rsAllocation.cpp
	modified:   libs/rs/rsAllocation.h
	modified:   libs/rs/rsContext.h
	modified:   libs/rs/rsProgramFragment.cpp
	modified:   libs/rs/rsSimpleMesh.cpp

Remove check for surface valid that is no longer valid.

Continue development of es2.0 user shader support for renderscript.  This change cleans up ProgramVertex creation and adds support for passing input, output, and constant type info.

Continue es2 shader dev

Conflicts:

	graphics/java/android/renderscript/Program.java
	graphics/java/android/renderscript/ProgramVertex.java

Place shader logging behind prop to declutter logs.

Fix emulated glColor in es2 mode.

Fix live wallpaper many.  Z coordinate was being ignored for draw quad call.

Add argument checking to sampler builder to disallow illegal modes.

Move texture bindings to base program object.  Change ProgramFragment creation to require a texture format in 1.0 mode.

Element restructuring.  Add support for new basic Element types including the RS objects and vectors(2-4).  In theory this paves the way for maintaining type info for RS objects, passing elements for GLSL uiforms/attribs/varyings, and supporting nested structures.

This will break some apps, checkings for other projects will follow to unbreak them.

Disable excessive RS logging.

Add RS support for generic attribs as input to vertex programs.

More complete support for named attribs.  Adds user typed attribs as available to programVertex.  Non user attribs are not treated like user for GL2 for simplicity.

Support npot on es 2.0 HW.

Change user attribs to look for empty slot rather than using them in order.  Prevents conflict with numbered legacy slots.

Fix npot but where mipmap level sizes were rounding in the wrong direction.  Should always be floor.

Implement type generation for user uniforms in vertex shader.

Remove excessive logging, fix error in GLSL uniform generation.

Fix RS mipmap generation for 8 bit alpha textures.

Cleanup seperation of Legacy and user attribs.  All user programs now use the new names.  Legacy vertex attribs are given default names.

Fix some minor bugs with GL state setup that were exposed by Droids driver.

Implement drawSpriteCropped on es2.0
parent c1eba82b
Loading
Loading
Loading
Loading
+20 −7
Original line number Diff line number Diff line
@@ -39,15 +39,17 @@ public class Allocation extends BaseObj {
        mType = t;
    }

    public Type getType() {
        return mType;
    }

    public void uploadToTexture(int baseMipLevel) {
        mRS.validate();
        mRS.validateSurface();
        mRS.nAllocationUploadToTexture(mID, baseMipLevel);
    }

    public void uploadToBufferObject() {
        mRS.validate();
        mRS.validateSurface();
        mRS.nAllocationUploadToBufferObject(mID);
    }

@@ -171,9 +173,10 @@ public class Allocation extends BaseObj {
    public Adapter1D createAdapter1D() {
        mRS.validate();
        int id = mRS.nAdapter1DCreate();
        if (id != 0) {
            mRS.nAdapter1DBindAllocation(id, mID);
        if(id == 0) {
            throw new IllegalStateException("allocation failed.");
        }
        mRS.nAdapter1DBindAllocation(id, mID);
        return new Adapter1D(id, mRS);
    }

@@ -213,9 +216,10 @@ public class Allocation extends BaseObj {
    public Adapter2D createAdapter2D() {
        mRS.validate();
        int id = mRS.nAdapter2DCreate();
        if (id != 0) {
            mRS.nAdapter2DBindAllocation(id, mID);
        if(id == 0) {
            throw new IllegalStateException("allocation failed.");
        }
        mRS.nAdapter2DBindAllocation(id, mID);
        return new Adapter2D(id, mRS);
    }

@@ -258,14 +262,20 @@ public class Allocation extends BaseObj {

        rs.validate();
        int id = rs.nAllocationCreateFromBitmap(dstFmt.mID, genMips, b);
        if(id == 0) {
            throw new IllegalStateException("Load failed.");
        }
        return new Allocation(id, rs, null);
    }

    static public Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
    static Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
        throws IllegalArgumentException {

        rs.validate();
        int id = rs.nAllocationCreateFromBitmapBoxed(dstFmt.mID, genMips, b);
        if(id == 0) {
            throw new IllegalStateException("Load failed.");
        }
        return new Allocation(id, rs, null);
    }

@@ -282,6 +292,9 @@ public class Allocation extends BaseObj {
            int allocationId = rs.nAllocationCreateFromAssetStream(dstFmt.mID, genMips,
                    asset);

            if(allocationId == 0) {
                throw new IllegalStateException("Load failed.");
            }
            return new Allocation(allocationId, rs, null);
        } catch (Exception e) {
            // Ignore
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.util.Log;
class BaseObj {

    BaseObj(RenderScript rs) {
        rs.validate();
        mRS = rs;
        mID = 0;
        mDestroyed = false;
+239 −314

File changed.

Preview size limit exceeded, changes collapsed.

+144 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 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 android.renderscript;


import android.util.Config;
import android.util.Log;


/**
 * @hide
 *
 **/
public class Program extends BaseObj {
    public static final int MAX_INPUT = 8;
    public static final int MAX_OUTPUT = 8;
    public static final int MAX_CONSTANT = 8;
    public static final int MAX_TEXTURE = 8;

    Element mInputs[];
    Element mOutputs[];
    Type mConstants[];
    int mTextureCount;
    String mShader;

    Program(int id, RenderScript rs) {
        super(rs);
        mID = id;
    }

    public void bindConstants(Allocation a, int slot) {
        mRS.nProgramBindConstants(mID, slot, a.mID);
    }

    public void bindTexture(Allocation va, int slot)
        throws IllegalArgumentException {
        mRS.validate();
        if((slot < 0) || (slot >= mTextureCount)) {
            throw new IllegalArgumentException("Slot ID out of range.");
        }

        mRS.nProgramBindTexture(mID, slot, va.mID);
    }

    public void bindSampler(Sampler vs, int slot)
        throws IllegalArgumentException {
        mRS.validate();
        if((slot < 0) || (slot >= mTextureCount)) {
            throw new IllegalArgumentException("Slot ID out of range.");
        }

        mRS.nProgramBindSampler(mID, slot, vs.mID);
    }


    public static class BaseProgramBuilder {
        RenderScript mRS;
        Element mInputs[];
        Element mOutputs[];
        Type mConstants[];
        Type mTextures[];
        int mInputCount;
        int mOutputCount;
        int mConstantCount;
        int mTextureCount;
        String mShader;


        protected BaseProgramBuilder(RenderScript rs) {
            mRS = rs;
            mInputs = new Element[MAX_INPUT];
            mOutputs = new Element[MAX_OUTPUT];
            mConstants = new Type[MAX_CONSTANT];
            mInputCount = 0;
            mOutputCount = 0;
            mConstantCount = 0;
            mTextureCount = 0;
        }

        public void setShader(String s) {
            mShader = s;
        }

        public void addInput(Element e) throws IllegalStateException {
            // Should check for consistant and non-conflicting names...
            if(mInputCount >= MAX_INPUT) {
                throw new IllegalArgumentException("Max input count exceeded.");
            }
            mInputs[mInputCount++] = e;
        }

        public void addOutput(Element e) throws IllegalStateException {
            // Should check for consistant and non-conflicting names...
            if(mOutputCount >= MAX_OUTPUT) {
                throw new IllegalArgumentException("Max output count exceeded.");
            }
            mOutputs[mOutputCount++] = e;
        }

        public int addConstant(Type t) throws IllegalStateException {
            // Should check for consistant and non-conflicting names...
            if(mConstantCount >= MAX_CONSTANT) {
                throw new IllegalArgumentException("Max input count exceeded.");
            }
            mConstants[mConstantCount] = t;
            return mConstantCount++;
        }

        public void setTextureCount(int count) throws IllegalArgumentException {
            // Should check for consistant and non-conflicting names...
            if(count >= MAX_CONSTANT) {
                throw new IllegalArgumentException("Max texture count exceeded.");
            }
            mTextureCount = count;
        }

        protected void initProgram(Program p) {
            p.mInputs = new Element[mInputCount];
            System.arraycopy(mInputs, 0, p.mInputs, 0, mInputCount);
            p.mOutputs = new Element[mOutputCount];
            System.arraycopy(mOutputs, 0, p.mOutputs, 0, mOutputCount);
            p.mConstants = new Type[mConstantCount];
            System.arraycopy(mConstants, 0, p.mConstants, 0, mConstantCount);
            p.mTextureCount = mTextureCount;
        }
    }

}

+74 −93
Original line number Diff line number Diff line
@@ -25,134 +25,115 @@ import android.util.Log;
 * @hide
 *
 **/
public class ProgramFragment extends BaseObj {
    public static final int MAX_SLOT = 2;

    public enum EnvMode {
        REPLACE (0),
        MODULATE (1),
        DECAL (2);

        int mID;
        EnvMode(int id) {
            mID = id;
        }
public class ProgramFragment extends Program {
    ProgramFragment(int id, RenderScript rs) {
        super(id, rs);
    }


    ProgramFragment(int id, RenderScript rs) {
    public static class ShaderBuilder extends BaseProgramBuilder {
        public ShaderBuilder(RenderScript rs) {
            super(rs);
        mID = id;
        }

    public void bindTexture(Allocation va, int slot)
        throws IllegalArgumentException {
        public ProgramFragment create() {
            mRS.validate();
        if((slot < 0) || (slot >= MAX_SLOT)) {
            throw new IllegalArgumentException("Slot ID out of range.");
        }
            int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + 1) * 2];
            int idx = 0;

        mRS.nProgramFragmentBindTexture(mID, slot, va.mID);
            for (int i=0; i < mInputCount; i++) {
                tmp[idx++] = 0;
                tmp[idx++] = mInputs[i].mID;
            }

    public void bindSampler(Sampler vs, int slot)
        throws IllegalArgumentException {
        mRS.validate();
        if((slot < 0) || (slot >= MAX_SLOT)) {
            throw new IllegalArgumentException("Slot ID out of range.");
            for (int i=0; i < mOutputCount; i++) {
                tmp[idx++] = 1;
                tmp[idx++] = mOutputs[i].mID;
            }

        mRS.nProgramFragmentBindSampler(mID, slot, vs.mID);
            for (int i=0; i < mConstantCount; i++) {
                tmp[idx++] = 2;
                tmp[idx++] = mConstants[i].mID;
            }
            tmp[idx++] = 3;
            tmp[idx++] = mTextureCount;

            int id = mRS.nProgramFragmentCreate2(mShader, tmp);
            ProgramFragment pf = new ProgramFragment(id, mRS);
            initProgram(pf);
            return pf;
        }
    }

    public static class Builder {
        public static final int MAX_TEXTURE = 2;
        RenderScript mRS;
        Element mIn;
        Element mOut;
        boolean mPointSpriteEnable;

        private class Slot {
            Type mType;
            EnvMode mEnv;
            boolean mTexEnable;
        public enum EnvMode {
            REPLACE (1),
            MODULATE (2),
            DECAL (3);

            Slot() {
                mTexEnable = false;
            int mID;
            EnvMode(int id) {
                mID = id;
            }
        }
        Slot[] mSlots;

        public Builder(RenderScript rs, Element in, Element out) {
            mRS = rs;
            mIn = in;
            mOut = out;
            mSlots = new Slot[MAX_SLOT];
            mPointSpriteEnable = false;
            for(int ct=0; ct < MAX_SLOT; ct++) {
                mSlots[ct] = new Slot();
            }
        }
        public enum Format {
            ALPHA (1),
            LUMINANCE_ALPHA (2),
            RGB (3),
            RGBA (4);

        public void setType(int slot, Type t)
            throws IllegalArgumentException {
            if((slot < 0) || (slot >= MAX_SLOT)) {
                throw new IllegalArgumentException("Slot ID out of range.");
            int mID;
            Format(int id) {
                mID = id;
            }

            mSlots[slot].mType = t;
        }

        public void setTexEnable(boolean enable, int slot)
            throws IllegalArgumentException {
            if((slot < 0) || (slot >= MAX_SLOT)) {
                throw new IllegalArgumentException("Slot ID out of range.");
        private class Slot {
            EnvMode env;
            Format format;
            Slot(EnvMode _env, Format _fmt) {
                env = _env;
                format = _fmt;
            }
        }
        Slot[] mSlots;

            mSlots[slot].mTexEnable = enable;
        public Builder(RenderScript rs) {
            mRS = rs;
            mSlots = new Slot[MAX_TEXTURE];
            mPointSpriteEnable = false;
        }

        public void setTexEnvMode(EnvMode env, int slot)
        public void setTexture(EnvMode env, Format fmt, int slot)
            throws IllegalArgumentException {
            if((slot < 0) || (slot >= MAX_SLOT)) {
                throw new IllegalArgumentException("Slot ID out of range.");
            if((slot < 0) || (slot >= MAX_TEXTURE)) {
                throw new IllegalArgumentException("MAX_TEXTURE exceeded.");
            }

            mSlots[slot].mEnv = env;
            mSlots[slot] = new Slot(env, fmt);
        }

        public void setPointSpriteTexCoordinateReplacement(boolean enable) {
            mPointSpriteEnable = enable;
        }

        static synchronized ProgramFragment internalCreate(RenderScript rs, Builder b) {
            int inID = 0;
            int outID = 0;
            if (b.mIn != null) {
                inID = b.mIn.mID;
            }
            if (b.mOut != null) {
                outID = b.mOut.mID;
            }
            rs.nProgramFragmentBegin(inID, outID, b.mPointSpriteEnable);
            for(int ct=0; ct < MAX_SLOT; ct++) {
                if(b.mSlots[ct].mTexEnable) {
                    Slot s = b.mSlots[ct];
                    int typeID = 0;
                    if(s.mType != null) {
                        typeID = s.mType.mID;
                    }
                    rs.nProgramFragmentSetSlot(ct, true, s.mEnv.mID, typeID);
                }
            }

            int id = rs.nProgramFragmentCreate();
            return new ProgramFragment(id, rs);
        }

        public ProgramFragment create() {
            mRS.validate();
            return internalCreate(mRS, this);
            int[] tmp = new int[MAX_TEXTURE * 2 + 1];
            if (mSlots[0] != null) {
                tmp[0] = mSlots[0].env.mID;
                tmp[1] = mSlots[0].format.mID;
            }
            if (mSlots[1] != null) {
                tmp[2] = mSlots[1].env.mID;
                tmp[3] = mSlots[1].format.mID;
            }
            tmp[4] = mPointSpriteEnable ? 1 : 0;
            int id = mRS.nProgramFragmentCreate(tmp);
            ProgramFragment pf = new ProgramFragment(id, mRS);
            pf.mTextureCount = MAX_TEXTURE;
            return pf;
        }
    }
}
Loading