diff options
author | 2011-03-16 16:29:28 -0700 | |
---|---|---|
committer | 2011-03-17 16:13:03 -0700 | |
commit | e4a06c5fc738bf219f2a495e12a637b2d0871651 (patch) | |
tree | a7102d6914154f456a57403ae690d9d2f8979aae | |
parent | ce06ebfda4bd7c511cef3d98aacf7291a743ea46 (diff) |
Start seperating out RS compute implementation. Create hal
layer to seperate from runtime.
Change-Id: Idf5c1261be4131690d25c15948e98324e979b4f9
-rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 17 | ||||
-rw-r--r-- | graphics/java/android/renderscript/ScriptC.java | 7 | ||||
-rw-r--r-- | graphics/jni/android_renderscript_RenderScript.cpp | 54 | ||||
-rw-r--r-- | libs/rs/Android.mk | 4 | ||||
-rw-r--r-- | libs/rs/RenderScript.h | 295 | ||||
-rw-r--r-- | libs/rs/RenderScriptDefines.h | 325 | ||||
-rw-r--r-- | libs/rs/driver/rsdBcc.cpp | 332 | ||||
-rw-r--r-- | libs/rs/driver/rsdBcc.h | 61 | ||||
-rw-r--r-- | libs/rs/driver/rsdCore.cpp | 54 | ||||
-rw-r--r-- | libs/rs/driver/rsdCore.h | 47 | ||||
-rw-r--r-- | libs/rs/rs.spec | 12 | ||||
-rw-r--r-- | libs/rs/rsAllocation.cpp | 176 | ||||
-rw-r--r-- | libs/rs/rsAllocation.h | 43 | ||||
-rw-r--r-- | libs/rs/rsContext.cpp | 4 | ||||
-rw-r--r-- | libs/rs/rsContext.h | 14 | ||||
-rw-r--r-- | libs/rs/rsScript.cpp | 47 | ||||
-rw-r--r-- | libs/rs/rsScript.h | 49 | ||||
-rw-r--r-- | libs/rs/rsScriptC.cpp | 300 | ||||
-rw-r--r-- | libs/rs/rsScriptC.h | 21 | ||||
-rw-r--r-- | libs/rs/rsScriptC_Lib.cpp | 156 | ||||
-rw-r--r-- | libs/rs/rs_hal.h | 94 |
21 files changed, 1286 insertions, 826 deletions
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index b51279ab544c..f57753268e73 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -457,20 +457,11 @@ public class RenderScript { rsnScriptSetVarObj(mContext, id, slot, val); } - native void rsnScriptCBegin(int con); - synchronized void nScriptCBegin() { + native int rsnScriptCCreate(int con, String resName, String cacheDir, + byte[] script, int length); + synchronized int nScriptCCreate(String resName, String cacheDir, byte[] script, int length) { validate(); - rsnScriptCBegin(mContext); - } - native void rsnScriptCSetScript(int con, byte[] script, int offset, int length); - synchronized void nScriptCSetScript(byte[] script, int offset, int length) { - validate(); - rsnScriptCSetScript(mContext, script, offset, length); - } - native int rsnScriptCCreate(int con, String packageName, String resName, String cacheDir); - synchronized int nScriptCCreate(String packageName, String resName, String cacheDir) { - validate(); - return rsnScriptCCreate(mContext, packageName, resName, cacheDir); + return rsnScriptCCreate(mContext, resName, cacheDir, script, length); } native void rsnSamplerBegin(int con); diff --git a/graphics/java/android/renderscript/ScriptC.java b/graphics/java/android/renderscript/ScriptC.java index 94452834623f..f8657531cf67 100644 --- a/graphics/java/android/renderscript/ScriptC.java +++ b/graphics/java/android/renderscript/ScriptC.java @@ -92,16 +92,13 @@ public class ScriptC extends Script { throw new Resources.NotFoundException(); } - rs.nScriptCBegin(); - rs.nScriptCSetScript(pgm, 0, pgmLength); - // E.g, /system/apps/Fountain.apk - String packageName = rs.getApplicationContext().getPackageResourcePath(); + //String packageName = rs.getApplicationContext().getPackageResourcePath(); // For res/raw/fountain.bc, it wil be /com.android.fountain:raw/fountain String resName = resources.getResourceName(resourceID); String cacheDir = rs.getApplicationContext().getCacheDir().toString(); Log.v(TAG, "Create script for resource = " + resName); - return rs.nScriptCCreate(packageName, resName, cacheDir); + return rs.nScriptCCreate(resName, cacheDir, pgm, pgmLength); } } diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index 2afd74ce13a0..c7f480920c53 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -848,65 +848,51 @@ nScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slo // ----------------------------------- -static void -nScriptCBegin(JNIEnv *_env, jobject _this, RsContext con) +static jint +nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con, + jstring resName, jstring cacheDir, + jbyteArray scriptRef, jint length) { - LOG_API("nScriptCBegin, con(%p)", con); - rsScriptCBegin(con); -} + LOG_API("nScriptCCreate, con(%p)", con); + + AutoJavaStringToUTF8 resNameUTF(_env, resName); + AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); + jint ret = 0; -static void -nScriptCSetScript(JNIEnv *_env, jobject _this, RsContext con, jbyteArray scriptRef, - jint offset, jint length) -{ - LOG_API("!!! nScriptCSetScript, con(%p)", con); jint _exception = 0; jint remaining; - jbyte* script_base = 0; jbyte* script_ptr; if (!scriptRef) { _exception = 1; //_env->ThrowNew(IAEClass, "script == null"); goto exit; } - if (offset < 0) { - _exception = 1; - //_env->ThrowNew(IAEClass, "offset < 0"); - goto exit; - } if (length < 0) { _exception = 1; //_env->ThrowNew(IAEClass, "length < 0"); goto exit; } - remaining = _env->GetArrayLength(scriptRef) - offset; + remaining = _env->GetArrayLength(scriptRef); if (remaining < length) { _exception = 1; //_env->ThrowNew(IAEClass, "length > script.length - offset"); goto exit; } - script_base = (jbyte *) + script_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0); - script_ptr = script_base + offset; - rsScriptCSetText(con, (const char *)script_ptr, length); + //rsScriptCSetText(con, (const char *)script_ptr, length); + + ret = (jint)rsScriptCCreate(con, resNameUTF.c_str(), cacheDirUTF.c_str(), + (const char *)script_ptr, length); exit: - if (script_base) { - _env->ReleasePrimitiveArrayCritical(scriptRef, script_base, + if (script_ptr) { + _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr, _exception ? JNI_ABORT: 0); } -} -static jint -nScriptCCreate(JNIEnv *_env, jobject _this, RsContext con, jstring packageName, jstring resName, jstring cacheDir) -{ - LOG_API("nScriptCCreate, con(%p)", con); - AutoJavaStringToUTF8 packageNameUTF(_env, packageName); - AutoJavaStringToUTF8 resNameUTF(_env, resName); - AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); - jint i = (jint)rsScriptCCreate(con, packageNameUTF.c_str(), resNameUTF.c_str(), cacheDirUTF.c_str()); - return i; + return ret; } // --------------------------------------------------------------------------- @@ -1282,9 +1268,7 @@ static JNINativeMethod methods[] = { {"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV }, {"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj }, -{"rsnScriptCBegin", "(I)V", (void*)nScriptCBegin }, -{"rsnScriptCSetScript", "(I[BII)V", (void*)nScriptCSetScript }, -{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", (void*)nScriptCCreate }, +{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate }, {"rsnProgramStoreBegin", "(III)V", (void*)nProgramStoreBegin }, {"rsnProgramStoreDepthFunc", "(II)V", (void*)nProgramStoreDepthFunc }, diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk index 5520315458e1..14152d865946 100644 --- a/libs/rs/Android.mk +++ b/libs/rs/Android.mk @@ -113,7 +113,9 @@ LOCAL_SRC_FILES:= \ rsStream.cpp \ rsThreadIO.cpp \ rsType.cpp \ - rsVertexArray.cpp + rsVertexArray.cpp \ + driver/rsdBcc.cpp \ + driver/rsdCore.cpp LOCAL_SHARED_LIBRARIES += libz libcutils libutils libEGL libGLESv1_CM libGLESv2 libui libbcc diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h index ffa9a8c8b74b..cb6d7e05ebdb 100644 --- a/libs/rs/RenderScript.h +++ b/libs/rs/RenderScript.h @@ -24,52 +24,7 @@ extern "C" { #endif -////////////////////////////////////////////////////// -// - -typedef void * RsAsyncVoidPtr; - -typedef void * RsAdapter1D; -typedef void * RsAdapter2D; -typedef void * RsAllocation; -typedef void * RsAnimation; -typedef void * RsContext; -typedef void * RsDevice; -typedef void * RsElement; -typedef void * RsFile; -typedef void * RsFont; -typedef void * RsSampler; -typedef void * RsScript; -typedef void * RsMesh; -typedef void * RsType; -typedef void * RsObjectBase; - -typedef void * RsProgram; -typedef void * RsProgramVertex; -typedef void * RsProgramFragment; -typedef void * RsProgramStore; -typedef void * RsProgramRaster; - -typedef void (* RsBitmapCallback_t)(void *); - -enum RsDeviceParam { - RS_DEVICE_PARAM_FORCE_SOFTWARE_GL, - RS_DEVICE_PARAM_COUNT -}; - -typedef struct { - uint32_t colorMin; - uint32_t colorPref; - uint32_t alphaMin; - uint32_t alphaPref; - uint32_t depthMin; - uint32_t depthPref; - uint32_t stencilMin; - uint32_t stencilPref; - uint32_t samplesMin; - uint32_t samplesPref; - float samplesQ; -} RsSurfaceConfig; +#include "RenderScriptDefines.h" RsDevice rsDeviceCreate(); void rsDeviceDestroy(RsDevice); @@ -80,258 +35,12 @@ RsContext rsContextCreateGL(RsDevice, uint32_t version, RsSurfaceConfig sc, uint32_t dpi); void rsContextDestroy(RsContext); -enum RsMessageToClientType { - RS_MESSAGE_TO_CLIENT_NONE = 0, - RS_MESSAGE_TO_CLIENT_EXCEPTION = 1, - RS_MESSAGE_TO_CLIENT_RESIZE = 2, - RS_MESSAGE_TO_CLIENT_ERROR = 3, - RS_MESSAGE_TO_CLIENT_USER = 4 -}; - RsMessageToClientType rsContextGetMessage(RsContext vrsc, void *data, size_t *receiveLen, uint32_t *subID, size_t bufferLen, bool wait); RsMessageToClientType rsContextPeekMessage(RsContext vrsc, size_t *receiveLen, uint32_t *subID, bool wait); void rsContextInitToClient(RsContext); void rsContextDeinitToClient(RsContext); -#define RS_MAX_TEXTURE 2 -#define RS_MAX_ATTRIBS 16 - - -enum RsAllocationUsageType { - RS_ALLOCATION_USAGE_SCRIPT = 0x0001, - RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE = 0x0002, - RS_ALLOCATION_USAGE_GRAPHICS_VERTEX = 0x0004, - RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS = 0x0008, - - RS_ALLOCATION_USAGE_ALL = 0x000F -}; - -enum RsAllocationMipmapControl { - RS_ALLOCATION_MIPMAP_NONE = 0, - RS_ALLOCATION_MIPMAP_FULL = 1, - RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE = 2 -}; - -enum RsAllocationCubemapFace { - RS_ALLOCATION_CUBMAP_FACE_POSITVE_X = 0, - RS_ALLOCATION_CUBMAP_FACE_NEGATIVE_X = 1, - RS_ALLOCATION_CUBMAP_FACE_POSITVE_Y = 2, - RS_ALLOCATION_CUBMAP_FACE_NEGATIVE_Y = 3, - RS_ALLOCATION_CUBMAP_FACE_POSITVE_Z = 4, - RS_ALLOCATION_CUBMAP_FACE_NEGATIVE_Z = 5 -}; - -enum RsDataType { - RS_TYPE_NONE, - RS_TYPE_FLOAT_16, - RS_TYPE_FLOAT_32, - RS_TYPE_FLOAT_64, - RS_TYPE_SIGNED_8, - RS_TYPE_SIGNED_16, - RS_TYPE_SIGNED_32, - RS_TYPE_SIGNED_64, - RS_TYPE_UNSIGNED_8, - RS_TYPE_UNSIGNED_16, - RS_TYPE_UNSIGNED_32, - RS_TYPE_UNSIGNED_64, - - RS_TYPE_BOOLEAN, - - RS_TYPE_UNSIGNED_5_6_5, - RS_TYPE_UNSIGNED_5_5_5_1, - RS_TYPE_UNSIGNED_4_4_4_4, - - RS_TYPE_MATRIX_4X4, - RS_TYPE_MATRIX_3X3, - RS_TYPE_MATRIX_2X2, - - RS_TYPE_ELEMENT = 1000, - RS_TYPE_TYPE, - RS_TYPE_ALLOCATION, - RS_TYPE_SAMPLER, - RS_TYPE_SCRIPT, - RS_TYPE_MESH, - RS_TYPE_PROGRAM_FRAGMENT, - RS_TYPE_PROGRAM_VERTEX, - RS_TYPE_PROGRAM_RASTER, - RS_TYPE_PROGRAM_STORE, -}; - -enum RsDataKind { - RS_KIND_USER, - - RS_KIND_PIXEL_L = 7, - RS_KIND_PIXEL_A, - RS_KIND_PIXEL_LA, - RS_KIND_PIXEL_RGB, - RS_KIND_PIXEL_RGBA, -}; - -enum RsSamplerParam { - RS_SAMPLER_MIN_FILTER, - RS_SAMPLER_MAG_FILTER, - RS_SAMPLER_WRAP_S, - RS_SAMPLER_WRAP_T, - RS_SAMPLER_WRAP_R, - RS_SAMPLER_ANISO -}; - -enum RsSamplerValue { - RS_SAMPLER_NEAREST, - RS_SAMPLER_LINEAR, - RS_SAMPLER_LINEAR_MIP_LINEAR, - RS_SAMPLER_WRAP, - RS_SAMPLER_CLAMP, - RS_SAMPLER_LINEAR_MIP_NEAREST, -}; - -enum RsTextureTarget { - RS_TEXTURE_2D, - RS_TEXTURE_CUBE -}; - -enum RsDimension { - RS_DIMENSION_X, - RS_DIMENSION_Y, - RS_DIMENSION_Z, - RS_DIMENSION_LOD, - RS_DIMENSION_FACE, - - RS_DIMENSION_ARRAY_0 = 100, - RS_DIMENSION_ARRAY_1, - RS_DIMENSION_ARRAY_2, - RS_DIMENSION_ARRAY_3, - RS_DIMENSION_MAX = RS_DIMENSION_ARRAY_3 -}; - -enum RsDepthFunc { - RS_DEPTH_FUNC_ALWAYS, - RS_DEPTH_FUNC_LESS, - RS_DEPTH_FUNC_LEQUAL, - RS_DEPTH_FUNC_GREATER, - RS_DEPTH_FUNC_GEQUAL, - RS_DEPTH_FUNC_EQUAL, - RS_DEPTH_FUNC_NOTEQUAL -}; - -enum RsBlendSrcFunc { - RS_BLEND_SRC_ZERO, // 0 - RS_BLEND_SRC_ONE, // 1 - RS_BLEND_SRC_DST_COLOR, // 2 - RS_BLEND_SRC_ONE_MINUS_DST_COLOR, // 3 - RS_BLEND_SRC_SRC_ALPHA, // 4 - RS_BLEND_SRC_ONE_MINUS_SRC_ALPHA, // 5 - RS_BLEND_SRC_DST_ALPHA, // 6 - RS_BLEND_SRC_ONE_MINUS_DST_ALPHA, // 7 - RS_BLEND_SRC_SRC_ALPHA_SATURATE // 8 -}; - -enum RsBlendDstFunc { - RS_BLEND_DST_ZERO, // 0 - RS_BLEND_DST_ONE, // 1 - RS_BLEND_DST_SRC_COLOR, // 2 - RS_BLEND_DST_ONE_MINUS_SRC_COLOR, // 3 - RS_BLEND_DST_SRC_ALPHA, // 4 - RS_BLEND_DST_ONE_MINUS_SRC_ALPHA, // 5 - RS_BLEND_DST_DST_ALPHA, // 6 - RS_BLEND_DST_ONE_MINUS_DST_ALPHA // 7 -}; - -enum RsTexEnvMode { - RS_TEX_ENV_MODE_NONE, - RS_TEX_ENV_MODE_REPLACE, - RS_TEX_ENV_MODE_MODULATE, - RS_TEX_ENV_MODE_DECAL -}; - -enum RsProgramParam { - RS_PROGRAM_PARAM_INPUT, - RS_PROGRAM_PARAM_OUTPUT, - RS_PROGRAM_PARAM_CONSTANT, - RS_PROGRAM_PARAM_TEXTURE_TYPE, -}; - -enum RsPrimitive { - RS_PRIMITIVE_POINT, - RS_PRIMITIVE_LINE, - RS_PRIMITIVE_LINE_STRIP, - RS_PRIMITIVE_TRIANGLE, - RS_PRIMITIVE_TRIANGLE_STRIP, - RS_PRIMITIVE_TRIANGLE_FAN -}; - -enum RsError { - RS_ERROR_NONE = 0, - RS_ERROR_BAD_SHADER = 1, - RS_ERROR_BAD_SCRIPT = 2, - RS_ERROR_BAD_VALUE = 3, - RS_ERROR_OUT_OF_MEMORY = 4, - RS_ERROR_DRIVER = 5, - - RS_ERROR_FATAL_UNKNOWN = 0x1000, - RS_ERROR_FATAL_DRIVER = 0x1001, - RS_ERROR_FATAL_PROGRAM_LINK = 0x1002 -}; - -enum RsAnimationInterpolation { - RS_ANIMATION_INTERPOLATION_STEP, - RS_ANIMATION_INTERPOLATION_LINEAR, - RS_ANIMATION_INTERPOLATION_BEZIER, - RS_ANIMATION_INTERPOLATION_CARDINAL, - RS_ANIMATION_INTERPOLATION_HERMITE, - RS_ANIMATION_INTERPOLATION_BSPLINE -}; - -enum RsAnimationEdge { - RS_ANIMATION_EDGE_UNDEFINED, - RS_ANIMATION_EDGE_CONSTANT, - RS_ANIMATION_EDGE_GRADIENT, - RS_ANIMATION_EDGE_CYCLE, - RS_ANIMATION_EDGE_OSCILLATE, - RS_ANIMATION_EDGE_CYLE_RELATIVE -}; - -enum RsA3DClassID { - RS_A3D_CLASS_ID_UNKNOWN, - RS_A3D_CLASS_ID_MESH, - RS_A3D_CLASS_ID_TYPE, - RS_A3D_CLASS_ID_ELEMENT, - RS_A3D_CLASS_ID_ALLOCATION, - RS_A3D_CLASS_ID_PROGRAM_VERTEX, - RS_A3D_CLASS_ID_PROGRAM_RASTER, - RS_A3D_CLASS_ID_PROGRAM_FRAGMENT, - RS_A3D_CLASS_ID_PROGRAM_STORE, - RS_A3D_CLASS_ID_SAMPLER, - RS_A3D_CLASS_ID_ANIMATION, - RS_A3D_CLASS_ID_ADAPTER_1D, - RS_A3D_CLASS_ID_ADAPTER_2D, - RS_A3D_CLASS_ID_SCRIPT_C -}; - -enum RsCullMode { - RS_CULL_BACK, - RS_CULL_FRONT, - RS_CULL_NONE -}; - -typedef struct { - RsA3DClassID classID; - const char* objectName; -} RsFileIndexEntry; - -// Script to Script -typedef struct { - uint32_t xStart; - uint32_t xEnd; - uint32_t yStart; - uint32_t yEnd; - uint32_t zStart; - uint32_t zEnd; - uint32_t arrayStart; - uint32_t arrayEnd; - -} RsScriptCall; - +// // A3D loading and object update code. // Should only be called at object creation, not thread safe RsObjectBase rsaFileA3DGetEntryByIndex(RsContext, uint32_t idx, RsFile); diff --git a/libs/rs/RenderScriptDefines.h b/libs/rs/RenderScriptDefines.h new file mode 100644 index 000000000000..4e1ac88094dd --- /dev/null +++ b/libs/rs/RenderScriptDefines.h @@ -0,0 +1,325 @@ +/* + * Copyright (C) 2007 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. + */ + +#ifndef RENDER_SCRIPT_DEFINES_H +#define RENDER_SCRIPT_DEFINES_H + +#include <stdint.h> +#include <sys/types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +////////////////////////////////////////////////////// +// + +typedef void * RsAsyncVoidPtr; + +typedef void * RsAdapter1D; +typedef void * RsAdapter2D; +typedef void * RsAllocation; +typedef void * RsAnimation; +typedef void * RsContext; +typedef void * RsDevice; +typedef void * RsElement; +typedef void * RsFile; +typedef void * RsFont; +typedef void * RsSampler; +typedef void * RsScript; +typedef void * RsMesh; +typedef void * RsType; +typedef void * RsObjectBase; + +typedef void * RsProgram; +typedef void * RsProgramVertex; +typedef void * RsProgramFragment; +typedef void * RsProgramStore; +typedef void * RsProgramRaster; + +typedef void (* RsBitmapCallback_t)(void *); + +enum RsDeviceParam { + RS_DEVICE_PARAM_FORCE_SOFTWARE_GL, + RS_DEVICE_PARAM_COUNT +}; + +typedef struct { + uint32_t colorMin; + uint32_t colorPref; + uint32_t alphaMin; + uint32_t alphaPref; + uint32_t depthMin; + uint32_t depthPref; + uint32_t stencilMin; + uint32_t stencilPref; + uint32_t samplesMin; + uint32_t samplesPref; + float samplesQ; +} RsSurfaceConfig; + +enum RsMessageToClientType { + RS_MESSAGE_TO_CLIENT_NONE = 0, + RS_MESSAGE_TO_CLIENT_EXCEPTION = 1, + RS_MESSAGE_TO_CLIENT_RESIZE = 2, + RS_MESSAGE_TO_CLIENT_ERROR = 3, + RS_MESSAGE_TO_CLIENT_USER = 4 +}; + +enum RsAllocationUsageType { + RS_ALLOCATION_USAGE_SCRIPT = 0x0001, + RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE = 0x0002, + RS_ALLOCATION_USAGE_GRAPHICS_VERTEX = 0x0004, + RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS = 0x0008, + + RS_ALLOCATION_USAGE_ALL = 0x000F +}; + +enum RsAllocationMipmapControl { + RS_ALLOCATION_MIPMAP_NONE = 0, + RS_ALLOCATION_MIPMAP_FULL = 1, + RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE = 2 +}; + +enum RsAllocationCubemapFace { + RS_ALLOCATION_CUBMAP_FACE_POSITVE_X = 0, + RS_ALLOCATION_CUBMAP_FACE_NEGATIVE_X = 1, + RS_ALLOCATION_CUBMAP_FACE_POSITVE_Y = 2, + RS_ALLOCATION_CUBMAP_FACE_NEGATIVE_Y = 3, + RS_ALLOCATION_CUBMAP_FACE_POSITVE_Z = 4, + RS_ALLOCATION_CUBMAP_FACE_NEGATIVE_Z = 5 +}; + +enum RsDataType { + RS_TYPE_NONE, + RS_TYPE_FLOAT_16, + RS_TYPE_FLOAT_32, + RS_TYPE_FLOAT_64, + RS_TYPE_SIGNED_8, + RS_TYPE_SIGNED_16, + RS_TYPE_SIGNED_32, + RS_TYPE_SIGNED_64, + RS_TYPE_UNSIGNED_8, + RS_TYPE_UNSIGNED_16, + RS_TYPE_UNSIGNED_32, + RS_TYPE_UNSIGNED_64, + + RS_TYPE_BOOLEAN, + + RS_TYPE_UNSIGNED_5_6_5, + RS_TYPE_UNSIGNED_5_5_5_1, + RS_TYPE_UNSIGNED_4_4_4_4, + + RS_TYPE_MATRIX_4X4, + RS_TYPE_MATRIX_3X3, + RS_TYPE_MATRIX_2X2, + + RS_TYPE_ELEMENT = 1000, + RS_TYPE_TYPE, + RS_TYPE_ALLOCATION, + RS_TYPE_SAMPLER, + RS_TYPE_SCRIPT, + RS_TYPE_MESH, + RS_TYPE_PROGRAM_FRAGMENT, + RS_TYPE_PROGRAM_VERTEX, + RS_TYPE_PROGRAM_RASTER, + RS_TYPE_PROGRAM_STORE, +}; + +enum RsDataKind { + RS_KIND_USER, + + RS_KIND_PIXEL_L = 7, + RS_KIND_PIXEL_A, + RS_KIND_PIXEL_LA, + RS_KIND_PIXEL_RGB, + RS_KIND_PIXEL_RGBA, +}; + +enum RsSamplerParam { + RS_SAMPLER_MIN_FILTER, + RS_SAMPLER_MAG_FILTER, + RS_SAMPLER_WRAP_S, + RS_SAMPLER_WRAP_T, + RS_SAMPLER_WRAP_R, + RS_SAMPLER_ANISO +}; + +enum RsSamplerValue { + RS_SAMPLER_NEAREST, + RS_SAMPLER_LINEAR, + RS_SAMPLER_LINEAR_MIP_LINEAR, + RS_SAMPLER_WRAP, + RS_SAMPLER_CLAMP, + RS_SAMPLER_LINEAR_MIP_NEAREST, +}; + +enum RsTextureTarget { + RS_TEXTURE_2D, + RS_TEXTURE_CUBE +}; + +enum RsDimension { + RS_DIMENSION_X, + RS_DIMENSION_Y, + RS_DIMENSION_Z, + RS_DIMENSION_LOD, + RS_DIMENSION_FACE, + + RS_DIMENSION_ARRAY_0 = 100, + RS_DIMENSION_ARRAY_1, + RS_DIMENSION_ARRAY_2, + RS_DIMENSION_ARRAY_3, + RS_DIMENSION_MAX = RS_DIMENSION_ARRAY_3 +}; + +enum RsDepthFunc { + RS_DEPTH_FUNC_ALWAYS, + RS_DEPTH_FUNC_LESS, + RS_DEPTH_FUNC_LEQUAL, + RS_DEPTH_FUNC_GREATER, + RS_DEPTH_FUNC_GEQUAL, + RS_DEPTH_FUNC_EQUAL, + RS_DEPTH_FUNC_NOTEQUAL +}; + +enum RsBlendSrcFunc { + RS_BLEND_SRC_ZERO, // 0 + RS_BLEND_SRC_ONE, // 1 + RS_BLEND_SRC_DST_COLOR, // 2 + RS_BLEND_SRC_ONE_MINUS_DST_COLOR, // 3 + RS_BLEND_SRC_SRC_ALPHA, // 4 + RS_BLEND_SRC_ONE_MINUS_SRC_ALPHA, // 5 + RS_BLEND_SRC_DST_ALPHA, // 6 + RS_BLEND_SRC_ONE_MINUS_DST_ALPHA, // 7 + RS_BLEND_SRC_SRC_ALPHA_SATURATE // 8 +}; + +enum RsBlendDstFunc { + RS_BLEND_DST_ZERO, // 0 + RS_BLEND_DST_ONE, // 1 + RS_BLEND_DST_SRC_COLOR, // 2 + RS_BLEND_DST_ONE_MINUS_SRC_COLOR, // 3 + RS_BLEND_DST_SRC_ALPHA, // 4 + RS_BLEND_DST_ONE_MINUS_SRC_ALPHA, // 5 + RS_BLEND_DST_DST_ALPHA, // 6 + RS_BLEND_DST_ONE_MINUS_DST_ALPHA // 7 +}; + +enum RsTexEnvMode { + RS_TEX_ENV_MODE_NONE, + RS_TEX_ENV_MODE_REPLACE, + RS_TEX_ENV_MODE_MODULATE, + RS_TEX_ENV_MODE_DECAL +}; + +enum RsProgramParam { + RS_PROGRAM_PARAM_INPUT, + RS_PROGRAM_PARAM_OUTPUT, + RS_PROGRAM_PARAM_CONSTANT, + RS_PROGRAM_PARAM_TEXTURE_TYPE, +}; + +enum RsPrimitive { + RS_PRIMITIVE_POINT, + RS_PRIMITIVE_LINE, + RS_PRIMITIVE_LINE_STRIP, + RS_PRIMITIVE_TRIANGLE, + RS_PRIMITIVE_TRIANGLE_STRIP, + RS_PRIMITIVE_TRIANGLE_FAN +}; + +enum RsError { + RS_ERROR_NONE = 0, + RS_ERROR_BAD_SHADER = 1, + RS_ERROR_BAD_SCRIPT = 2, + RS_ERROR_BAD_VALUE = 3, + RS_ERROR_OUT_OF_MEMORY = 4, + RS_ERROR_DRIVER = 5, + + RS_ERROR_FATAL_UNKNOWN = 0x1000, + RS_ERROR_FATAL_DRIVER = 0x1001, + RS_ERROR_FATAL_PROGRAM_LINK = 0x1002 +}; + +enum RsAnimationInterpolation { + RS_ANIMATION_INTERPOLATION_STEP, + RS_ANIMATION_INTERPOLATION_LINEAR, + RS_ANIMATION_INTERPOLATION_BEZIER, + RS_ANIMATION_INTERPOLATION_CARDINAL, + RS_ANIMATION_INTERPOLATION_HERMITE, + RS_ANIMATION_INTERPOLATION_BSPLINE +}; + +enum RsAnimationEdge { + RS_ANIMATION_EDGE_UNDEFINED, + RS_ANIMATION_EDGE_CONSTANT, + RS_ANIMATION_EDGE_GRADIENT, + RS_ANIMATION_EDGE_CYCLE, + RS_ANIMATION_EDGE_OSCILLATE, + RS_ANIMATION_EDGE_CYLE_RELATIVE +}; + +enum RsA3DClassID { + RS_A3D_CLASS_ID_UNKNOWN, + RS_A3D_CLASS_ID_MESH, + RS_A3D_CLASS_ID_TYPE, + RS_A3D_CLASS_ID_ELEMENT, + RS_A3D_CLASS_ID_ALLOCATION, + RS_A3D_CLASS_ID_PROGRAM_VERTEX, + RS_A3D_CLASS_ID_PROGRAM_RASTER, + RS_A3D_CLASS_ID_PROGRAM_FRAGMENT, + RS_A3D_CLASS_ID_PROGRAM_STORE, + RS_A3D_CLASS_ID_SAMPLER, + RS_A3D_CLASS_ID_ANIMATION, + RS_A3D_CLASS_ID_ADAPTER_1D, + RS_A3D_CLASS_ID_ADAPTER_2D, + RS_A3D_CLASS_ID_SCRIPT_C +}; + +enum RsCullMode { + RS_CULL_BACK, + RS_CULL_FRONT, + RS_CULL_NONE +}; + +typedef struct { + RsA3DClassID classID; + const char* objectName; +} RsFileIndexEntry; + +// Script to Script +typedef struct { + uint32_t xStart; + uint32_t xEnd; + uint32_t yStart; + uint32_t yEnd; + uint32_t zStart; + uint32_t zEnd; + uint32_t arrayStart; + uint32_t arrayEnd; + +} RsScriptCall; + +#ifdef __cplusplus +}; +#endif + +#endif // RENDER_SCRIPT_DEFINES_H + + + + diff --git a/libs/rs/driver/rsdBcc.cpp b/libs/rs/driver/rsdBcc.cpp new file mode 100644 index 000000000000..36a4b0173097 --- /dev/null +++ b/libs/rs/driver/rsdBcc.cpp @@ -0,0 +1,332 @@ +/* + * 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. + */ + + +#include "rsdCore.h" +#include "rsdBcc.h" + +#include "rsContext.h" +#include "rsScriptC.h" + +#include "utils/Timers.h" +#include "utils/StopWatch.h" +extern "C" { +#include "libdex/ZipArchive.h" +} + + +using namespace android; +using namespace android::renderscript; + +struct DrvScript { + int (*mRoot)(); + void (*mInit)(); + + BCCScriptRef mBccScript; + + uint32_t mInvokeFunctionCount; + InvokeFunc_t *mInvokeFunctions; + uint32_t mFieldCount; + void ** mFieldAddress; + bool * mFieldIsObject; + + const uint8_t * mScriptText; + uint32_t mScriptTextLength; + + //uint32_t * mObjectSlots; + //uint32_t mObjectSlotCount; + + uint32_t mPragmaCount; + const char ** mPragmaKeys; + const char ** mPragmaValues; + +}; + +// Input: cacheDir +// Input: resName +// Input: extName +// +// Note: cacheFile = resName + extName +// +// Output: Returns cachePath == cacheDir + cacheFile +static char *genCacheFileName(const char *cacheDir, + const char *resName, + const char *extName) { + char cachePath[512]; + char cacheFile[sizeof(cachePath)]; + const size_t kBufLen = sizeof(cachePath) - 1; + + cacheFile[0] = '\0'; + // Note: resName today is usually something like + // "/com.android.fountain:raw/fountain" + if (resName[0] != '/') { + // Get the absolute path of the raw/***.bc file. + + // Generate the absolute path. This doesn't do everything it + // should, e.g. if resName is "./out/whatever" it doesn't crunch + // the leading "./" out because this if-block is not triggered, + // but it'll make do. + // + if (getcwd(cacheFile, kBufLen) == NULL) { + LOGE("Can't get CWD while opening raw/***.bc file\n"); + return NULL; + } + // Append "/" at the end of cacheFile so far. + strncat(cacheFile, "/", kBufLen); + } + + // cacheFile = resName + extName + // + strncat(cacheFile, resName, kBufLen); + if (extName != NULL) { + // TODO(srhines): strncat() is a bit dangerous + strncat(cacheFile, extName, kBufLen); + } + + // Turn the path into a flat filename by replacing + // any slashes after the first one with '@' characters. + char *cp = cacheFile + 1; + while (*cp != '\0') { + if (*cp == '/') { + *cp = '@'; + } + cp++; + } + + // Tack on the file name for the actual cache file path. + strncpy(cachePath, cacheDir, kBufLen); + strncat(cachePath, cacheFile, kBufLen); + + LOGV("Cache file for '%s' '%s' is '%s'\n", resName, extName, cachePath); + return strdup(cachePath); +} + +bool rsdScriptInit(const Context *rsc, + ScriptC *script, + char const *resName, + char const *cacheDir, + uint8_t const *bitcode, + size_t bitcodeSize, + uint32_t flags, + RsHalSymbolLookupFunc lookupFunc) { + //LOGE("rsdScriptCreate %p %p %p %p %i %i %p", rsc, resName, cacheDir, bitcode, bitcodeSize, flags, lookupFunc); + + char *cachePath = NULL; + uint32_t objectSlotCount = 0; + + DrvScript *drv = (DrvScript *)calloc(1, sizeof(DrvScript)); + if (drv == NULL) { + return false; + } + script->mHal.drv = drv; + + drv->mBccScript = bccCreateScript(); + script->mHal.info.isThreadable = true; + drv->mScriptText = bitcode; + drv->mScriptTextLength = bitcodeSize; + + //LOGE("mBccScript %p", script->mBccScript); + + if (bccRegisterSymbolCallback(drv->mBccScript, lookupFunc, script) != 0) { + LOGE("bcc: FAILS to register symbol callback"); + goto error; + } + + if (bccReadBC(drv->mBccScript, + resName, + (char const *)drv->mScriptText, + drv->mScriptTextLength, 0) != 0) { + LOGE("bcc: FAILS to read bitcode"); + return NULL; + } + +#if 1 + if (bccLinkFile(drv->mBccScript, "/system/lib/libclcore.bc", 0) != 0) { + LOGE("bcc: FAILS to link bitcode"); + return NULL; + } +#endif + cachePath = genCacheFileName(cacheDir, resName, ".oBCC"); + + if (bccPrepareExecutable(drv->mBccScript, cachePath, 0) != 0) { + LOGE("bcc: FAILS to prepare executable"); + return NULL; + } + + free(cachePath); + + drv->mRoot = reinterpret_cast<int (*)()>(bccGetFuncAddr(drv->mBccScript, "root")); + drv->mInit = reinterpret_cast<void (*)()>(bccGetFuncAddr(drv->mBccScript, "init")); + + drv->mInvokeFunctionCount = bccGetExportFuncCount(drv->mBccScript); + if (drv->mInvokeFunctionCount <= 0) + drv->mInvokeFunctions = NULL; + else { + drv->mInvokeFunctions = (InvokeFunc_t*) calloc(drv->mInvokeFunctionCount, sizeof(InvokeFunc_t)); + bccGetExportFuncList(drv->mBccScript, drv->mInvokeFunctionCount, (void **) drv->mInvokeFunctions); + } + + drv->mFieldCount = bccGetExportVarCount(drv->mBccScript); + if (drv->mFieldCount <= 0) { + drv->mFieldAddress = NULL; + drv->mFieldIsObject = NULL; + } else { + drv->mFieldAddress = (void **) calloc(drv->mFieldCount, sizeof(void *)); + drv->mFieldIsObject = (bool *) calloc(drv->mFieldCount, sizeof(bool)); + bccGetExportVarList(drv->mBccScript, drv->mFieldCount, (void **) drv->mFieldAddress); + } + + objectSlotCount = bccGetObjectSlotCount(drv->mBccScript); + if (objectSlotCount) { + uint32_t * slots = new uint32_t[objectSlotCount]; + bccGetObjectSlotList(drv->mBccScript, objectSlotCount, slots); + for (uint32_t ct=0; ct < objectSlotCount; ct++) { + drv->mFieldIsObject[slots[ct]] = true; + } + delete [] slots; + } + + uint32_t mPragmaCount; + const char ** mPragmaKeys; + const char ** mPragmaValues; + + const static int pragmaMax = 16; + drv->mPragmaCount = bccGetPragmaCount(drv->mBccScript); + if (drv->mPragmaCount <= 0) { + drv->mPragmaKeys = NULL; + drv->mPragmaValues = NULL; + } else { + drv->mPragmaKeys = (const char **) calloc(drv->mFieldCount, sizeof(const char *)); + drv->mPragmaValues = (const char **) calloc(drv->mFieldCount, sizeof(const char *)); + bccGetPragmaList(drv->mBccScript, drv->mPragmaCount, drv->mPragmaKeys, drv->mPragmaValues); + } + + + + // Copy info over to runtime + script->mHal.info.exportedFunctionCount = drv->mInvokeFunctionCount; + script->mHal.info.exportedVariableCount = drv->mFieldCount; + script->mHal.info.exportedPragmaCount = drv->mPragmaCount; + script->mHal.info.exportedPragmaKeyList = drv->mPragmaKeys; + script->mHal.info.exportedPragmaValueList = drv->mPragmaValues; + script->mHal.info.root = drv->mRoot; + + + return true; + +error: + + free(drv); + return false; + +} + + +int rsdScriptInvokeRoot(const Context *dc, const Script *script) { + DrvScript *drv = (DrvScript *)script->mHal.drv; + return drv->mRoot(); +} + +void rsdScriptInvokeInit(const Context *dc, const Script *script) { + DrvScript *drv = (DrvScript *)script->mHal.drv; + + if (drv->mInit) { + drv->mInit(); + } +} + + +void rsdScriptInvokeFunction(const Context *dc, const Script *script, + uint32_t slot, + const void *params, + size_t paramLength) { + DrvScript *drv = (DrvScript *)script->mHal.drv; + //LOGE("invoke %p %p %i %p %i", dc, script, slot, params, paramLength); + + ((void (*)(const void *, uint32_t)) + drv->mInvokeFunctions[slot])(params, paramLength); +} + +void rsdScriptSetGlobalVar(const Context *dc, const Script *script, + uint32_t slot, void *data, size_t dataLength) { + DrvScript *drv = (DrvScript *)script->mHal.drv; + //rsAssert(!script->mFieldIsObject[slot]); + //LOGE("setGlobalVar %p %p %i %p %i", dc, script, slot, data, dataLength); + + int32_t *destPtr = ((int32_t **)drv->mFieldAddress)[slot]; + if (!destPtr) { + //LOGV("Calling setVar on slot = %i which is null", slot); + return; + } + + memcpy(destPtr, data, dataLength); +} + +void rsdScriptSetGlobalBind(const Context *dc, const Script *script, uint32_t slot, void *data) { + DrvScript *drv = (DrvScript *)script->mHal.drv; + //rsAssert(!script->mFieldIsObject[slot]); + //LOGE("setGlobalBind %p %p %i %p", dc, script, slot, data); + + int32_t *destPtr = ((int32_t **)drv->mFieldAddress)[slot]; + if (!destPtr) { + //LOGV("Calling setVar on slot = %i which is null", slot); + return; + } + + memcpy(destPtr, &data, sizeof(void *)); +} + +void rsdScriptSetGlobalObj(const Context *dc, const Script *script, uint32_t slot, ObjectBase *data) { + DrvScript *drv = (DrvScript *)script->mHal.drv; + //rsAssert(script->mFieldIsObject[slot]); + //LOGE("setGlobalObj %p %p %i %p", dc, script, slot, data); + + int32_t *destPtr = ((int32_t **)drv->mFieldAddress)[slot]; + if (!destPtr) { + //LOGV("Calling setVar on slot = %i which is null", slot); + return; + } + + rsiSetObject((ObjectBase **)destPtr, data); +} + +void rsdScriptDestroy(const Context *dc, Script *script) { + DrvScript *drv = (DrvScript *)script->mHal.drv; + + if (drv->mFieldAddress) { + for (size_t ct=0; ct < drv->mFieldCount; ct++) { + if (drv->mFieldIsObject[ct]) { + rsiClearObject((ObjectBase **)&drv->mFieldAddress[ct]); + } + } + delete [] drv->mFieldAddress; + delete [] drv->mFieldIsObject; + drv->mFieldAddress = NULL; + drv->mFieldIsObject = NULL; + drv->mFieldCount = 0; + } + + if (drv->mInvokeFunctions) { + delete [] drv->mInvokeFunctions; + drv->mInvokeFunctions = NULL; + drv->mInvokeFunctionCount = 0; + } + free(drv); + script->mHal.drv = NULL; + +} + + diff --git a/libs/rs/driver/rsdBcc.h b/libs/rs/driver/rsdBcc.h new file mode 100644 index 000000000000..f697f293d32e --- /dev/null +++ b/libs/rs/driver/rsdBcc.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2009 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. + */ + +#ifndef RSD_BCC_H +#define RSD_BCC_H + +#include <rs_hal.h> + + +bool rsdScriptInit(const android::renderscript::Context *, android::renderscript::ScriptC *, + char const *resName, char const *cacheDir, + uint8_t const *bitcode, size_t bitcodeSize, + uint32_t flags, android::renderscript::RsHalSymbolLookupFunc lookupFunc); +void rsdScriptInvokeFunction(const android::renderscript::Context *dc, + const android::renderscript::Script *script, + uint32_t slot, + const void *params, + size_t paramLength); +int rsdScriptInvokeRoot(const android::renderscript::Context *dc, + const android::renderscript::Script *script); +void rsdScriptInvokeInit(const android::renderscript::Context *dc, + const android::renderscript::Script *script); + +void rsdScriptSetGlobalVar(const android::renderscript::Context *, + const android::renderscript::Script *, + uint32_t slot, void *data, size_t dataLen); +void rsdScriptSetGlobalBind(const android::renderscript::Context *, + const android::renderscript::Script *, + uint32_t slot, void *data); +void rsdScriptSetGlobalObj(const android::renderscript::Context *, + const android::renderscript::Script *, + uint32_t slot, android::renderscript::ObjectBase *data); + +void rsdScriptSetGlobal(const android::renderscript::Context *dc, + const android::renderscript::Script *script, + uint32_t slot, + void *data, + size_t dataLength); +void rsdScriptGetGlobal(const android::renderscript::Context *dc, + const android::renderscript::Script *script, + uint32_t slot, + void *data, + size_t dataLength); +void rsdScriptDestroy(const android::renderscript::Context *dc, + android::renderscript::Script *script); + + +#endif diff --git a/libs/rs/driver/rsdCore.cpp b/libs/rs/driver/rsdCore.cpp new file mode 100644 index 000000000000..79fcab5d6d2b --- /dev/null +++ b/libs/rs/driver/rsdCore.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2009 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. + */ + +#include "rsdCore.h" +#include "rsdBcc.h" + +#include <malloc.h> +#include "rsContext.h" + +using namespace android; +using namespace android::renderscript; + +static RsdHalFunctions FunctionTable = { + NULL, + NULL, + { + rsdScriptInit, + rsdScriptInvokeFunction, + rsdScriptInvokeRoot, + rsdScriptInvokeInit, + rsdScriptSetGlobalVar, + rsdScriptSetGlobalBind, + rsdScriptSetGlobalObj, + rsdScriptDestroy + } +}; + + +bool rsdHalInit(Context *rsc, uint32_t version_major, uint32_t version_minor) { + rsc->mHal.funcs = FunctionTable; + + /* + rsc->mHal.drv = (RsHal *)calloc(1, sizeof(RsHal)); + if (!rsc->mHal.drv) { + return false; + } + */ + + return true; +} + diff --git a/libs/rs/driver/rsdCore.h b/libs/rs/driver/rsdCore.h new file mode 100644 index 000000000000..78596a1689f4 --- /dev/null +++ b/libs/rs/driver/rsdCore.h @@ -0,0 +1,47 @@ +/* + * 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. + */ + +#ifndef RSD_CORE_H +#define RSD_CORE_H + +#include <rs_hal.h> +#include <bcc/bcc.h> + +typedef void (* InvokeFunc_t)(void); + +struct RsHalRec { + uint32_t version_major; + uint32_t version_minor; +}; + +struct RsHalProgramStoreRec { +}; + +struct RsHalProgramRasterRec { +}; + +struct RsHalProgramVertexRec { +}; + +struct RsHalProgramFragmentRec { + +}; + + + + +#endif + diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec index 7e23cec90805..bbb62007b13f 100644 --- a/libs/rs/rs.spec +++ b/libs/rs/rs.spec @@ -181,10 +181,6 @@ ScriptBindAllocation { } -ScriptCBegin { - } - - ScriptSetTimeZone { param RsScript s param const char * timeZone @@ -246,15 +242,11 @@ ScriptSetVarV { } -ScriptCSetText { - param const char * text - param uint32_t length - } - ScriptCCreate { - param const char * packageName param const char * resName param const char * cacheDir + param const char * text + param uint32_t length ret RsScript } diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp index ec03a158871f..b8ddb0b7cac2 100644 --- a/libs/rs/rsAllocation.cpp +++ b/libs/rs/rsAllocation.cpp @@ -29,21 +29,22 @@ Allocation::Allocation(Context *rsc, const Type *type, uint32_t usages, : ObjectBase(rsc) { init(rsc, type); - mUsageFlags = usages; - mMipmapControl = mc; + mHal.state.usageFlags = usages; + mHal.state.mipmapControl = mc; allocScriptMemory(); - if (mType->getElement()->getHasReferences()) { - memset(mPtr, 0, mType->getSizeBytes()); + if (mHal.state.type->getElement()->getHasReferences()) { + memset(mHal.state.mallocPtr, 0, mHal.state.type->getSizeBytes()); } - if (!mPtr) { + if (!mHal.state.mallocPtr) { LOGE("Allocation::Allocation, alloc failure"); } } void Allocation::init(Context *rsc, const Type *type) { - mPtr = NULL; + memset(&mHal, 0, sizeof(mHal)); + mHal.state.mipmapControl = RS_ALLOCATION_MIPMAP_NONE; mCpuWrite = false; mCpuRead = false; @@ -52,8 +53,6 @@ void Allocation::init(Context *rsc, const Type *type) { mReadWriteRatio = 0; mUpdateSize = 0; - mUsageFlags = 0; - mMipmapControl = RS_ALLOCATION_MIPMAP_NONE; mTextureID = 0; mBufferID = 0; @@ -62,16 +61,25 @@ void Allocation::init(Context *rsc, const Type *type) { mUserBitmapCallback = NULL; mUserBitmapCallbackData = NULL; - mType.set(type); - rsAssert(type); + mHal.state.type.set(type); + updateCache(); +} - mPtr = NULL; +void Allocation::updateCache() { + const Type *type = mHal.state.type.get(); + mHal.state.dimensionX = type->getDimX(); + mHal.state.dimensionY = type->getDimY(); + mHal.state.dimensionZ = type->getDimZ(); + mHal.state.hasFaces = type->getDimFaces(); + mHal.state.hasMipmaps = type->getDimLOD(); + mHal.state.elementSizeBytes = type->getElementSizeBytes(); + mHal.state.hasReferences = mHal.state.type->getElement()->getHasReferences(); } Allocation::~Allocation() { if (mUserBitmapCallback != NULL) { mUserBitmapCallback(mUserBitmapCallbackData); - mPtr = NULL; + mHal.state.mallocPtr = NULL; } freeScriptMemory(); #ifndef ANDROID_RS_SERIALIZE @@ -105,14 +113,14 @@ bool Allocation::fixAllocation() { } void Allocation::deferedUploadToTexture(const Context *rsc) { - mUsageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; + mHal.state.usageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; mUploadDefered = true; } uint32_t Allocation::getGLTarget() const { #ifndef ANDROID_RS_SERIALIZE if (getIsTexture()) { - if (mType->getDimFaces()) { + if (mHal.state.type->getDimFaces()) { return GL_TEXTURE_CUBE_MAP; } else { return GL_TEXTURE_2D; @@ -126,14 +134,14 @@ uint32_t Allocation::getGLTarget() const { } void Allocation::allocScriptMemory() { - rsAssert(!mPtr); - mPtr = malloc(mType->getSizeBytes()); + rsAssert(!mHal.state.mallocPtr); + mHal.state.mallocPtr = malloc(mHal.state.type->getSizeBytes()); } void Allocation::freeScriptMemory() { - if (mPtr) { - free(mPtr); - mPtr = NULL; + if (mHal.state.mallocPtr) { + free(mHal.state.mallocPtr); + mHal.state.mallocPtr = NULL; } } @@ -153,15 +161,15 @@ void Allocation::syncAll(Context *rsc, RsAllocationUsageType src) { void Allocation::uploadToTexture(const Context *rsc) { #ifndef ANDROID_RS_SERIALIZE - mUsageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; - GLenum type = mType->getElement()->getComponent().getGLType(); - GLenum format = mType->getElement()->getComponent().getGLFormat(); + mHal.state.usageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE; + GLenum type = mHal.state.type->getElement()->getComponent().getGLType(); + GLenum format = mHal.state.type->getElement()->getComponent().getGLFormat(); if (!type || !format) { return; } - if (!mPtr) { + if (!mHal.state.mallocPtr) { return; } @@ -184,7 +192,7 @@ void Allocation::uploadToTexture(const Context *rsc) { upload2DTexture(isFirstUpload); - if (!(mUsageFlags & RS_ALLOCATION_USAGE_SCRIPT)) { + if (!(mHal.state.usageFlags & RS_ALLOCATION_USAGE_SCRIPT)) { freeScriptMemory(); } @@ -207,14 +215,14 @@ void Allocation::update2DTexture(const void *ptr, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face, uint32_t w, uint32_t h) { #ifndef ANDROID_RS_SERIALIZE - GLenum type = mType->getElement()->getComponent().getGLType(); - GLenum format = mType->getElement()->getComponent().getGLFormat(); + GLenum type = mHal.state.type->getElement()->getComponent().getGLType(); + GLenum format = mHal.state.type->getElement()->getComponent().getGLFormat(); GLenum target = (GLenum)getGLTarget(); rsAssert(mTextureID); glBindTexture(target, mTextureID); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); GLenum t = GL_TEXTURE_2D; - if (mType->getDimFaces()) { + if (mHal.state.hasFaces) { t = gFaceOrder[face]; } glTexSubImage2D(t, lod, xoff, yoff, w, h, format, type, ptr); @@ -223,57 +231,57 @@ void Allocation::update2DTexture(const void *ptr, uint32_t xoff, uint32_t yoff, void Allocation::upload2DTexture(bool isFirstUpload) { #ifndef ANDROID_RS_SERIALIZE - GLenum type = mType->getElement()->getComponent().getGLType(); - GLenum format = mType->getElement()->getComponent().getGLFormat(); + GLenum type = mHal.state.type->getElement()->getComponent().getGLType(); + GLenum format = mHal.state.type->getElement()->getComponent().getGLFormat(); GLenum target = (GLenum)getGLTarget(); glBindTexture(target, mTextureID); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); uint32_t faceCount = 1; - if (mType->getDimFaces()) { + if (mHal.state.hasFaces) { faceCount = 6; } for (uint32_t face = 0; face < faceCount; face ++) { - for (uint32_t lod = 0; lod < mType->getLODCount(); lod++) { - const uint8_t *p = (const uint8_t *)mPtr; - p += mType->getLODFaceOffset(lod, (RsAllocationCubemapFace)face, 0, 0); + for (uint32_t lod = 0; lod < mHal.state.type->getLODCount(); lod++) { + const uint8_t *p = (const uint8_t *)mHal.state.mallocPtr; + p += mHal.state.type->getLODFaceOffset(lod, (RsAllocationCubemapFace)face, 0, 0); GLenum t = GL_TEXTURE_2D; - if (mType->getDimFaces()) { + if (mHal.state.hasFaces) { t = gFaceOrder[face]; } if (isFirstUpload) { glTexImage2D(t, lod, format, - mType->getLODDimX(lod), mType->getLODDimY(lod), + mHal.state.type->getLODDimX(lod), mHal.state.type->getLODDimY(lod), 0, format, type, p); } else { glTexSubImage2D(t, lod, 0, 0, - mType->getLODDimX(lod), mType->getLODDimY(lod), + mHal.state.type->getLODDimX(lod), mHal.state.type->getLODDimY(lod), format, type, p); } } } - if (mMipmapControl == RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE) { + if (mHal.state.mipmapControl == RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE) { glGenerateMipmap(target); } #endif //ANDROID_RS_SERIALIZE } void Allocation::deferedUploadToBufferObject(const Context *rsc) { - mUsageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_VERTEX; + mHal.state.usageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_VERTEX; mUploadDefered = true; } void Allocation::uploadToBufferObject(const Context *rsc) { #ifndef ANDROID_RS_SERIALIZE - rsAssert(!mType->getDimY()); - rsAssert(!mType->getDimZ()); + rsAssert(!mHal.state.type->getDimY()); + rsAssert(!mHal.state.type->getDimZ()); - mUsageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_VERTEX; + mHal.state.usageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_VERTEX; if (!mBufferID) { glGenBuffers(1, &mBufferID); @@ -285,7 +293,7 @@ void Allocation::uploadToBufferObject(const Context *rsc) { } GLenum target = (GLenum)getGLTarget(); glBindBuffer(target, mBufferID); - glBufferData(target, mType->getSizeBytes(), getPtr(), GL_DYNAMIC_DRAW); + glBufferData(target, mHal.state.type->getSizeBytes(), getPtr(), GL_DYNAMIC_DRAW); glBindBuffer(target, 0); rsc->checkError("Allocation::uploadToBufferObject"); #endif //ANDROID_RS_SERIALIZE @@ -298,23 +306,23 @@ void Allocation::uploadCheck(Context *rsc) { } void Allocation::read(void *data) { - memcpy(data, mPtr, mType->getSizeBytes()); + memcpy(data, mHal.state.mallocPtr, mHal.state.type->getSizeBytes()); } void Allocation::data(Context *rsc, uint32_t xoff, uint32_t lod, uint32_t count, const void *data, uint32_t sizeBytes) { - uint32_t eSize = mType->getElementSizeBytes(); - uint8_t * ptr = static_cast<uint8_t *>(mPtr); + uint32_t eSize = mHal.state.type->getElementSizeBytes(); + uint8_t * ptr = static_cast<uint8_t *>(mHal.state.mallocPtr); ptr += eSize * xoff; uint32_t size = count * eSize; if (size != sizeBytes) { LOGE("Allocation::subData called with mismatched size expected %i, got %i", size, sizeBytes); - mType->dumpLOGV("type info"); + mHal.state.type->dumpLOGV("type info"); return; } - if (mType->getElement()->getHasReferences()) { + if (mHal.state.hasReferences) { incRefs(data, count); decRefs(ptr, count); } @@ -326,9 +334,9 @@ void Allocation::data(Context *rsc, uint32_t xoff, uint32_t lod, void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face, uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes) { - uint32_t eSize = mType->getElementSizeBytes(); + uint32_t eSize = mHal.state.elementSizeBytes; uint32_t lineSize = eSize * w; - uint32_t destW = mType->getDimX(); + uint32_t destW = mHal.state.dimensionX; //LOGE("data2d %p, %i %i %i %i %i %i %p %i", this, xoff, yoff, lod, face, w, h, data, sizeBytes); @@ -338,14 +346,14 @@ void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, return; } - if (mPtr) { + if (mHal.state.mallocPtr) { const uint8_t *src = static_cast<const uint8_t *>(data); - uint8_t *dst = static_cast<uint8_t *>(mPtr); - dst += mType->getLODFaceOffset(lod, face, xoff, yoff); + uint8_t *dst = static_cast<uint8_t *>(mHal.state.mallocPtr); + dst += mHal.state.type->getLODFaceOffset(lod, face, xoff, yoff); //LOGE(" %p %p %i ", dst, src, eSize); for (uint32_t line=yoff; line < (yoff+h); line++) { - if (mType->getElement()->getHasReferences()) { + if (mHal.state.hasReferences) { incRefs(src, w); decRefs(dst, w); } @@ -367,24 +375,24 @@ void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, void Allocation::elementData(Context *rsc, uint32_t x, const void *data, uint32_t cIdx, uint32_t sizeBytes) { - uint32_t eSize = mType->getElementSizeBytes(); - uint8_t * ptr = static_cast<uint8_t *>(mPtr); + uint32_t eSize = mHal.state.elementSizeBytes; + uint8_t * ptr = static_cast<uint8_t *>(mHal.state.mallocPtr); ptr += eSize * x; - if (cIdx >= mType->getElement()->getFieldCount()) { + if (cIdx >= mHal.state.type->getElement()->getFieldCount()) { LOGE("Error Allocation::subElementData component %i out of range.", cIdx); rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range."); return; } - if (x >= mType->getDimX()) { + if (x >= mHal.state.dimensionX) { LOGE("Error Allocation::subElementData X offset %i out of range.", x); rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range."); return; } - const Element * e = mType->getElement()->getField(cIdx); - ptr += mType->getElement()->getFieldOffsetBytes(cIdx); + const Element * e = mHal.state.type->getElement()->getField(cIdx); + ptr += mHal.state.type->getElement()->getFieldOffsetBytes(cIdx); if (sizeBytes != e->getSizeBytes()) { LOGE("Error Allocation::subElementData data size %i does not match field size %zu.", sizeBytes, e->getSizeBytes()); @@ -404,30 +412,30 @@ void Allocation::elementData(Context *rsc, uint32_t x, const void *data, void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y, const void *data, uint32_t cIdx, uint32_t sizeBytes) { - uint32_t eSize = mType->getElementSizeBytes(); - uint8_t * ptr = static_cast<uint8_t *>(mPtr); - ptr += eSize * (x + y * mType->getDimX()); + uint32_t eSize = mHal.state.elementSizeBytes; + uint8_t * ptr = static_cast<uint8_t *>(mHal.state.mallocPtr); + ptr += eSize * (x + y * mHal.state.dimensionX); - if (x >= mType->getDimX()) { + if (x >= mHal.state.dimensionX) { LOGE("Error Allocation::subElementData X offset %i out of range.", x); rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range."); return; } - if (y >= mType->getDimY()) { + if (y >= mHal.state.dimensionY) { LOGE("Error Allocation::subElementData X offset %i out of range.", x); rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range."); return; } - if (cIdx >= mType->getElement()->getFieldCount()) { + if (cIdx >= mHal.state.type->getElement()->getFieldCount()) { LOGE("Error Allocation::subElementData component %i out of range.", cIdx); rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range."); return; } - const Element * e = mType->getElement()->getField(cIdx); - ptr += mType->getElement()->getFieldOffsetBytes(cIdx); + const Element * e = mHal.state.type->getElement()->getField(cIdx); + ptr += mHal.state.type->getElement()->getFieldOffsetBytes(cIdx); if (sizeBytes != e->getSizeBytes()) { LOGE("Error Allocation::subElementData data size %i does not match field size %zu.", sizeBytes, e->getSizeBytes()); @@ -468,15 +476,15 @@ void Allocation::dumpLOGV(const char *prefix) const { String8 s(prefix); s.append(" type "); - if (mType.get()) { - mType->dumpLOGV(s.string()); + if (mHal.state.type.get()) { + mHal.state.type->dumpLOGV(s.string()); } LOGV("%s allocation ptr=%p mCpuWrite=%i, mCpuRead=%i, mGpuWrite=%i, mGpuRead=%i", - prefix, mPtr, mCpuWrite, mCpuRead, mGpuWrite, mGpuRead); + prefix, mHal.state.mallocPtr, mCpuWrite, mCpuRead, mGpuWrite, mGpuRead); LOGV("%s allocation mUsageFlags=0x04%x, mMipmapControl=0x%04x, mTextureID=%i, mBufferID=%i", - prefix, mUsageFlags, mMipmapControl, mTextureID, mBufferID); + prefix, mHal.state.usageFlags, mHal.state.mipmapControl, mTextureID, mBufferID); } void Allocation::serialize(OStream *stream) const { @@ -488,13 +496,13 @@ void Allocation::serialize(OStream *stream) const { // First thing we need to serialize is the type object since it will be needed // to initialize the class - mType->serialize(stream); + mHal.state.type->serialize(stream); - uint32_t dataSize = mType->getSizeBytes(); + uint32_t dataSize = mHal.state.type->getSizeBytes(); // Write how much data we are storing stream->addU32(dataSize); // Now write the data - stream->addByteArray(mPtr, dataSize); + stream->addByteArray(mHal.state.mallocPtr, dataSize); } Allocation *Allocation::createFromStream(Context *rsc, IStream *stream) { @@ -544,7 +552,7 @@ void Allocation::sendDirty() const { void Allocation::incRefs(const void *ptr, size_t ct, size_t startOff) const { const uint8_t *p = static_cast<const uint8_t *>(ptr); - const Element *e = mType->getElement(); + const Element *e = mHal.state.type->getElement(); uint32_t stride = e->getSizeBytes(); p += stride * startOff; @@ -557,7 +565,7 @@ void Allocation::incRefs(const void *ptr, size_t ct, size_t startOff) const { void Allocation::decRefs(const void *ptr, size_t ct, size_t startOff) const { const uint8_t *p = static_cast<const uint8_t *>(ptr); - const Element *e = mType->getElement(); + const Element *e = mHal.state.type->getElement(); uint32_t stride = e->getSizeBytes(); p += stride * startOff; @@ -572,24 +580,26 @@ void Allocation::copyRange1D(Context *rsc, const Allocation *src, int32_t srcOff } void Allocation::resize1D(Context *rsc, uint32_t dimX) { - Type *t = mType->cloneAndResize1D(rsc, dimX); + Type *t = mHal.state.type->cloneAndResize1D(rsc, dimX); - uint32_t oldDimX = mType->getDimX(); + uint32_t oldDimX = mHal.state.dimensionX; if (dimX == oldDimX) { return; } if (dimX < oldDimX) { - decRefs(mPtr, oldDimX - dimX, dimX); + decRefs(mHal.state.mallocPtr, oldDimX - dimX, dimX); } - mPtr = realloc(mPtr, t->getSizeBytes()); + mHal.state.mallocPtr = realloc(mHal.state.mallocPtr, t->getSizeBytes()); if (dimX > oldDimX) { - const Element *e = mType->getElement(); + const Element *e = mHal.state.type->getElement(); uint32_t stride = e->getSizeBytes(); - memset(((uint8_t *)mPtr) + stride * oldDimX, 0, stride * (dimX - oldDimX)); + memset(((uint8_t *)mHal.state.mallocPtr) + stride * oldDimX, 0, stride * (dimX - oldDimX)); } - mType.set(t); + + mHal.state.type.set(t); + updateCache(); } void Allocation::resize2D(Context *rsc, uint32_t dimX, uint32_t dimY) { diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h index 4f5d5a8e351f..e63140c78666 100644 --- a/libs/rs/rsAllocation.h +++ b/libs/rs/rsAllocation.h @@ -29,10 +29,35 @@ class Allocation : public ObjectBase { // The graphics equilivent of malloc. The allocation contains a structure of elements. public: + struct Hal { + void * drv; + + struct State { + ObjectBaseRef<const Type> type; + void * mallocPtr; + + uint32_t usageFlags; + RsAllocationMipmapControl mipmapControl; + + // Cached fields from the Type and Element + // to prevent pointer chasing in critical loops. + uint32_t dimensionX; + uint32_t dimensionY; + uint32_t dimensionZ; + uint32_t elementSizeBytes; + bool hasMipmaps; + bool hasFaces; + bool hasReferences; + }; + State state; + }; + Hal mHal; + Allocation(Context *rsc, const Type *, uint32_t usages, RsAllocationMipmapControl mc = RS_ALLOCATION_MIPMAP_NONE); virtual ~Allocation(); + void updateCache(); void setCpuWritable(bool); void setGpuWritable(bool); @@ -41,8 +66,8 @@ public: bool fixAllocation(); - void * getPtr() const {return mPtr;} - const Type * getType() const {return mType.get();} + void * getPtr() const {return mHal.state.mallocPtr;} + const Type * getType() const {return mHal.state.type.get();} void syncAll(Context *rsc, RsAllocationUsageType src); @@ -88,13 +113,13 @@ public: virtual void uploadCheck(Context *rsc); bool getIsScript() const { - return (mUsageFlags & RS_ALLOCATION_USAGE_SCRIPT) != 0; + return (mHal.state.usageFlags & RS_ALLOCATION_USAGE_SCRIPT) != 0; } bool getIsTexture() const { - return (mUsageFlags & RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE) != 0; + return (mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE) != 0; } bool getIsBufferObject() const { - return (mUsageFlags & RS_ALLOCATION_USAGE_GRAPHICS_VERTEX) != 0; + return (mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_VERTEX) != 0; } void incRefs(const void *ptr, size_t ct, size_t startOff = 0) const; @@ -102,14 +127,11 @@ public: void sendDirty() const; bool getHasGraphicsMipmaps() const { - return mMipmapControl != RS_ALLOCATION_MIPMAP_NONE; + return mHal.state.mipmapControl != RS_ALLOCATION_MIPMAP_NONE; } protected: - ObjectBaseRef<const Type> mType; - void * mPtr; - Vector<const Program *> mToDirtyList; // Is we have a non-null user bitmap callback we do not own the bits and @@ -123,9 +145,6 @@ protected: bool mGpuWrite; bool mGpuRead; - uint32_t mUsageFlags; - RsAllocationMipmapControl mMipmapControl; - // more usage hint data from the application // which can be used by a driver to pick the best memory type. // Likely ignored for now diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index a7c0180336a2..7dc26d23a6a3 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -688,6 +688,10 @@ bool Context::initContext(Device *dev, const RsSurfaceConfig *sc) { timerInit(); timerSet(RS_TIMER_INTERNAL); + if (!rsdHalInit(this, 0, 0)) { + return false; + } + int cpu = sysconf(_SC_NPROCESSORS_ONLN); LOGV("RS Launching thread(s), reported CPU count %i", cpu); if (cpu < 2) cpu = 0; diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h index 50f63df44401..dee16d6ebd25 100644 --- a/libs/rs/rsContext.h +++ b/libs/rs/rsContext.h @@ -22,6 +22,8 @@ #include "rsAllocation.h" #include "rsMesh.h" +#include "rs_hal.h" + #ifndef ANDROID_RS_SERIALIZE #include "rsMutex.h" #include "rsThreadIO.h" @@ -41,6 +43,7 @@ #include "rsgApiStructs.h" #include "rsLocklessFifo.h" + #include <ui/egl/android_natives.h> #endif // ANDROID_RS_SERIALIZE @@ -71,6 +74,13 @@ namespace renderscript { class Context { public: + struct Hal { + void * drv; + + RsdHalFunctions funcs; + }; + Hal mHal; + static Context * createContext(Device *, const RsSurfaceConfig *sc); ~Context(); @@ -86,6 +96,10 @@ public: Script * mScript; }; + //const RsHalComputeFunctions *mHalComputeFuncs; + //const RsHalGraphicsFunctions *mHalGraphicsFuncs; + //RsHal *mHal; + class PushState { public: PushState(Context *); diff --git a/libs/rs/rsScript.cpp b/libs/rs/rsScript.cpp index afee2a314809..b84014fa31d4 100644 --- a/libs/rs/rsScript.cpp +++ b/libs/rs/rsScript.cpp @@ -21,6 +21,7 @@ using namespace android::renderscript; Script::Script(Context *rsc) : ObjectBase(rsc) { memset(&mEnviroment, 0, sizeof(mEnviroment)); + memset(&mHal, 0, sizeof(mHal)); mSlots = NULL; mTypes = NULL; @@ -37,48 +38,38 @@ Script::~Script() { } } -void Script::initSlots() { - if (mEnviroment.mFieldCount > 0) { - mSlots = new ObjectBaseRef<Allocation>[mEnviroment.mFieldCount]; - mTypes = new ObjectBaseRef<const Type>[mEnviroment.mFieldCount]; - } -} - void Script::setSlot(uint32_t slot, Allocation *a) { - if (slot >= mEnviroment.mFieldCount) { + //LOGE("setSlot %i %p", slot, a); + if (slot >= mHal.info.exportedVariableCount) { LOGE("Script::setSlot unable to set allocation, invalid slot index"); return; } mSlots[slot].set(a); + if (a != NULL) { + mRSC->mHal.funcs.script.setGlobalBind(mRSC, this, slot, a->getPtr()); + } else { + mRSC->mHal.funcs.script.setGlobalBind(mRSC, this, slot, NULL); + } } void Script::setVar(uint32_t slot, const void *val, uint32_t len) { - int32_t *destPtr = ((int32_t **)mEnviroment.mFieldAddress)[slot]; - if (destPtr) { - //LOGE("setVar f1 %f", ((const float *)destPtr)[0]); - //LOGE("setVar %p %i", destPtr, len); - memcpy(destPtr, val, len); - //LOGE("setVar f2 %f", ((const float *)destPtr)[0]); - } else { - //if (rsc->props.mLogScripts) { - LOGV("Calling setVar on slot = %i which is null", slot); - //} + //LOGE("setVar %i %p %i", slot, val, len); + if (slot >= mHal.info.exportedVariableCount) { + LOGE("Script::setVar unable to set allocation, invalid slot index"); + return; } + mRSC->mHal.funcs.script.setGlobalVar(mRSC, this, slot, (void *)val, len); } void Script::setVarObj(uint32_t slot, ObjectBase *val) { - ObjectBase **destPtr = ((ObjectBase ***)mEnviroment.mFieldAddress)[slot]; - - if (destPtr) { - if (val != NULL) { - val->incSysRef(); - } - if (*destPtr) { - (*destPtr)->decSysRef(); - } - *destPtr = val; + //LOGE("setVarObj %i %p", slot, val); + if (slot >= mHal.info.exportedVariableCount) { + LOGE("Script::setVarObj unable to set allocation, invalid slot index"); + return; } + //LOGE("setvarobj %i %p", slot, val); + mRSC->mHal.funcs.script.setGlobalObj(mRSC, this, slot, val); } namespace android { diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h index bad095bcfcdf..671fbe6746f4 100644 --- a/libs/rs/rsScript.h +++ b/libs/rs/rsScript.h @@ -31,6 +31,45 @@ class ProgramStore; class Script : public ObjectBase { public: + struct Hal { + void * drv; + + struct State { + ObjectBaseRef<const Type> type; + void * mallocPtr; + + uint32_t usageFlags; + RsAllocationMipmapControl mipmapControl; + + // Cached fields from the Type and Element + // to prevent pointer chasing in critical loops. + uint32_t dimensionX; + uint32_t dimensionY; + uint32_t dimensionZ; + uint32_t elementSizeBytes; + bool hasMipmaps; + bool hasFaces; + bool hasReferences; + }; + State state; + + struct DriverInfo { + int mVersionMajor; + int mVersionMinor; + + size_t exportedVariableCount; + size_t exportedFunctionCount; + size_t exportedPragmaCount; + char const **exportedPragmaKeyList; + char const **exportedPragmaValueList; + + int (* root)(); + bool isThreadable; + }; + DriverInfo info; + }; + Hal mHal; + typedef void (* InvokeFunc_t)(void); Script(Context *); @@ -45,16 +84,6 @@ public: ObjectBaseRef<ProgramFragment> mFragment; ObjectBaseRef<ProgramRaster> mRaster; ObjectBaseRef<ProgramStore> mFragmentStore; - - uint32_t mInvokeFunctionCount; - InvokeFunc_t *mInvokeFunctions; - uint32_t mFieldCount; - void ** mFieldAddress; - - char * mScriptText; - uint32_t mScriptTextLength; - - bool mIsThreadable; }; Enviroment_t mEnviroment; diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp index e12926b0a641..f99534fa8e08 100644 --- a/libs/rs/rsScriptC.cpp +++ b/libs/rs/rsScriptC.cpp @@ -19,9 +19,6 @@ #include "rsMatrix.h" #include "utils/Timers.h" #include "utils/StopWatch.h" -extern "C" { -#include "libdex/ZipArchive.h" -} #include <GLES/gl.h> #include <GLES/glext.h> @@ -36,94 +33,21 @@ using namespace android::renderscript; Context * rsc = tls->mContext; \ ScriptC * sc = (ScriptC *) tls->mScript -// Input: cacheDir -// Input: resName -// Input: extName -// -// Note: cacheFile = resName + extName -// -// Output: Returns cachePath == cacheDir + cacheFile -char *genCacheFileName(const char *cacheDir, - const char *resName, - const char *extName) { - char cachePath[512]; - char cacheFile[sizeof(cachePath)]; - const size_t kBufLen = sizeof(cachePath) - 1; - - cacheFile[0] = '\0'; - // Note: resName today is usually something like - // "/com.android.fountain:raw/fountain" - if (resName[0] != '/') { - // Get the absolute path of the raw/***.bc file. - - // Generate the absolute path. This doesn't do everything it - // should, e.g. if resName is "./out/whatever" it doesn't crunch - // the leading "./" out because this if-block is not triggered, - // but it'll make do. - // - if (getcwd(cacheFile, kBufLen) == NULL) { - LOGE("Can't get CWD while opening raw/***.bc file\n"); - return NULL; - } - // Append "/" at the end of cacheFile so far. - strncat(cacheFile, "/", kBufLen); - } - - // cacheFile = resName + extName - // - strncat(cacheFile, resName, kBufLen); - if (extName != NULL) { - // TODO(srhines): strncat() is a bit dangerous - strncat(cacheFile, extName, kBufLen); - } - - // Turn the path into a flat filename by replacing - // any slashes after the first one with '@' characters. - char *cp = cacheFile + 1; - while (*cp != '\0') { - if (*cp == '/') { - *cp = '@'; - } - cp++; - } - - // Tack on the file name for the actual cache file path. - strncpy(cachePath, cacheDir, kBufLen); - strncat(cachePath, cacheFile, kBufLen); - - LOGV("Cache file for '%s' '%s' is '%s'\n", resName, extName, cachePath); - return strdup(cachePath); -} - ScriptC::ScriptC(Context *rsc) : Script(rsc) { - mBccScript = NULL; - memset(&mProgram, 0, sizeof(mProgram)); } ScriptC::~ScriptC() { - if (mBccScript) { - if (mProgram.mObjectSlotList) { - for (size_t ct=0; ct < mProgram.mObjectSlotCount; ct++) { - setVarObj(mProgram.mObjectSlotList[ct], NULL); - } - delete [] mProgram.mObjectSlotList; - mProgram.mObjectSlotList = NULL; - mProgram.mObjectSlotCount = 0; - } - + mRSC->mHal.funcs.script.destroy(mRSC, this); - LOGD(">>>> ~ScriptC bccDisposeScript(%p)", mBccScript); - bccDisposeScript(mBccScript); - } - free(mEnviroment.mScriptText); - mEnviroment.mScriptText = NULL; + //free(mEnviroment.mScriptText); + //mEnviroment.mScriptText = NULL; } void ScriptC::setupScript(Context *rsc) { mEnviroment.mStartTimeMillis = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)); - for (uint32_t ct=0; ct < mEnviroment.mFieldCount; ct++) { + for (uint32_t ct=0; ct < mHal.info.exportedVariableCount; ct++) { if (mSlots[ct].get() && !mTypes[ct].get()) { mTypes[ct].set(mSlots[ct]->getType()); } @@ -134,27 +58,17 @@ void ScriptC::setupScript(Context *rsc) { if (mSlots[ct].get()) { ptr = mSlots[ct]->getPtr(); } - void **dest = ((void ***)mEnviroment.mFieldAddress)[ct]; - - if (rsc->props.mLogScripts) { - if (mSlots[ct].get() != NULL) { - LOGV("%p ScriptC::setupScript slot=%i dst=%p src=%p type=%p", rsc, ct, dest, ptr, mSlots[ct]->getType()); - } else { - LOGV("%p ScriptC::setupScript slot=%i dst=%p src=%p type=null", rsc, ct, dest, ptr); - } - } - if (dest) { - *dest = ptr; - } + rsc->mHal.funcs.script.setGlobalBind(rsc, this, ct, ptr); } } const Allocation *ScriptC::ptrToAllocation(const void *ptr) const { + //LOGE("ptr to alloc %p", ptr); if (!ptr) { return NULL; } - for (uint32_t ct=0; ct < mEnviroment.mFieldCount; ct++) { + for (uint32_t ct=0; ct < mHal.info.exportedVariableCount; ct++) { if (!mSlots[ct].get()) continue; if (mSlots[ct]->getPtr() == ptr) { @@ -190,7 +104,7 @@ void ScriptC::setupGLState(Context *rsc) { } uint32_t ScriptC::run(Context *rsc) { - if (mProgram.mRoot == NULL) { + if (mHal.info.root == NULL) { rsc->setError(RS_ERROR_BAD_SCRIPT, "Attempted to run bad script"); return 0; } @@ -202,10 +116,10 @@ uint32_t ScriptC::run(Context *rsc) { Script * oldTLS = setTLS(this); if (rsc->props.mLogScripts) { - LOGV("%p ScriptC::run invoking root, ptr %p", rsc, mProgram.mRoot); + LOGV("%p ScriptC::run invoking root, ptr %p", rsc, mHal.info.root); } - ret = mProgram.mRoot(); + ret = mHal.info.root(); if (rsc->props.mLogScripts) { LOGV("%p ScriptC::run invoking complete, ret=%i", rsc, ret); @@ -266,7 +180,7 @@ static void wc_xy(void *usr, uint32_t idx) { const uint8_t *xPtrIn = mtls->ptrIn + (mtls->eStrideIn * offset); for (uint32_t x = mtls->xStart; x < mtls->xEnd; x++) { - ((rs_t)mtls->script->mProgram.mRoot) (xPtrIn, xPtrOut, mtls->usr, x, y, 0, 0); + ((rs_t)mtls->script->mHal.info.root) (xPtrIn, xPtrOut, mtls->usr, x, y, 0, 0); xPtrIn += mtls->eStrideIn; xPtrOut += mtls->eStrideOut; } @@ -291,7 +205,7 @@ static void wc_x(void *usr, uint32_t idx) { uint8_t *xPtrOut = mtls->ptrOut + (mtls->eStrideOut * xStart); const uint8_t *xPtrIn = mtls->ptrIn + (mtls->eStrideIn * xStart); for (uint32_t x = xStart; x < xEnd; x++) { - ((rs_t)mtls->script->mProgram.mRoot) (xPtrIn, xPtrOut, mtls->usr, x, 0, 0, 0); + ((rs_t)mtls->script->mHal.info.root) (xPtrIn, xPtrOut, mtls->usr, x, 0, 0, 0); xPtrIn += mtls->eStrideIn; xPtrOut += mtls->eStrideOut; } @@ -307,6 +221,7 @@ void ScriptC::runForEach(Context *rsc, memset(&mtls, 0, sizeof(mtls)); Context::PushState ps(rsc); + if (ain) { mtls.dimX = ain->getType()->getDimX(); mtls.dimY = ain->getType()->getDimY(); @@ -377,7 +292,7 @@ void ScriptC::runForEach(Context *rsc, mtls.eStrideOut = aout->getType()->getElementSizeBytes(); } - if ((rsc->getWorkerPoolSize() > 1) && mEnviroment.mIsThreadable) { + if ((rsc->getWorkerPoolSize() > 1) && mHal.info.isThreadable) { if (mtls.dimY > 1) { rsc->launchThreads(wc_xy, &mtls); } else { @@ -397,7 +312,7 @@ void ScriptC::runForEach(Context *rsc, const uint8_t *xPtrIn = mtls.ptrIn + (mtls.eStrideIn * offset); for (uint32_t x = mtls.xStart; x < mtls.xEnd; x++) { - ((rs_t)mProgram.mRoot) (xPtrIn, xPtrOut, usr, x, y, z, ar); + ((rs_t)mHal.info.root) (xPtrIn, xPtrOut, usr, x, y, z, ar); xPtrIn += mtls.eStrideIn; xPtrOut += mtls.eStrideOut; } @@ -410,8 +325,7 @@ void ScriptC::runForEach(Context *rsc, } void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len) { - if ((slot >= mEnviroment.mInvokeFunctionCount) || - (mEnviroment.mInvokeFunctions[slot] == NULL)) { + if (slot >= mHal.info.exportedFunctionCount) { rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script"); return; } @@ -419,13 +333,9 @@ void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len Script * oldTLS = setTLS(this); if (rsc->props.mLogScripts) { - LOGV("%p ScriptC::Invoke invoking slot %i, ptr %p", rsc, slot, mEnviroment.mInvokeFunctions[slot]); - } - ((void (*)(const void *, uint32_t)) - mEnviroment.mInvokeFunctions[slot])(data, len); - if (rsc->props.mLogScripts) { - LOGV("%p ScriptC::Invoke complete", rsc); + LOGV("%p ScriptC::Invoke invoking slot %i, ptr %p", rsc, slot, this); } + rsc->mHal.funcs.script.invokeFunction(rsc, this, slot, data, len); setTLS(oldTLS); } @@ -440,9 +350,9 @@ static void* symbolLookup(void* pContext, char const* name) { const ScriptCState::SymbolTable_t *sym; ScriptC *s = (ScriptC *)pContext; if (!strcmp(name, "__isThreadable")) { - return (void*) s->mEnviroment.mIsThreadable; + return (void*) s->mHal.info.isThreadable; } else if (!strcmp(name, "__clearThreadable")) { - s->mEnviroment.mIsThreadable = false; + s->mHal.info.isThreadable = false; return NULL; } sym = ScriptCState::lookupSymbol(name); @@ -453,7 +363,7 @@ static void* symbolLookup(void* pContext, char const* name) { sym = ScriptCState::lookupSymbolGL(name); } if (sym) { - s->mEnviroment.mIsThreadable &= sym->threadable; + s->mHal.info.isThreadable &= sym->threadable; return sym->mPtr; } LOGE("ScriptC sym lookup failed for %s", name); @@ -465,144 +375,86 @@ extern const char rs_runtime_lib_bc[]; extern unsigned rs_runtime_lib_bc_size; #endif -bool ScriptCState::runCompiler(Context *rsc, - ScriptC *s, - const char *resName, - const char *cacheDir) { - s->mBccScript = bccCreateScript(); - - s->mEnviroment.mIsThreadable = true; - - if (bccRegisterSymbolCallback(s->mBccScript, symbolLookup, s) != 0) { - LOGE("bcc: FAILS to register symbol callback"); - return false; - } - - if (bccReadBC(s->mBccScript, - resName, - s->mEnviroment.mScriptText, - s->mEnviroment.mScriptTextLength, 0) != 0) { - LOGE("bcc: FAILS to read bitcode"); - return false; - } - -#if 1 - if (bccLinkFile(s->mBccScript, "/system/lib/libclcore.bc", 0) != 0) { - LOGE("bcc: FAILS to link bitcode"); - return false; - } -#endif - char *cachePath = genCacheFileName(cacheDir, resName, ".oBCC"); - - if (bccPrepareExecutable(s->mBccScript, cachePath, 0) != 0) { - LOGE("bcc: FAILS to prepare executable"); - return false; - } - - free(cachePath); - - s->mProgram.mRoot = reinterpret_cast<int (*)()>(bccGetFuncAddr(s->mBccScript, "root")); - s->mProgram.mInit = reinterpret_cast<void (*)()>(bccGetFuncAddr(s->mBccScript, "init")); +bool ScriptC::runCompiler(Context *rsc, + const char *resName, + const char *cacheDir, + const uint8_t *bitcode, + size_t bitcodeLen) { - if (s->mProgram.mInit) { - s->mProgram.mInit(); - } + //LOGE("runCompiler %p %p %p %p %p %i", rsc, this, resName, cacheDir, bitcode, bitcodeLen); - s->mEnviroment.mInvokeFunctionCount = bccGetExportFuncCount(s->mBccScript); - if (s->mEnviroment.mInvokeFunctionCount <= 0) - s->mEnviroment.mInvokeFunctions = NULL; - else { - s->mEnviroment.mInvokeFunctions = (Script::InvokeFunc_t*) calloc(s->mEnviroment.mInvokeFunctionCount, sizeof(Script::InvokeFunc_t)); - bccGetExportFuncList(s->mBccScript, s->mEnviroment.mInvokeFunctionCount, (void **) s->mEnviroment.mInvokeFunctions); - } + rsc->mHal.funcs.script.scriptInit(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0, symbolLookup); - s->mEnviroment.mFieldCount = bccGetExportVarCount(s->mBccScript); - if (s->mEnviroment.mFieldCount <= 0) - s->mEnviroment.mFieldAddress = NULL; - else { - s->mEnviroment.mFieldAddress = (void **) calloc(s->mEnviroment.mFieldCount, sizeof(void *)); - bccGetExportVarList(s->mBccScript, s->mEnviroment.mFieldCount, (void **) s->mEnviroment.mFieldAddress); - s->initSlots(); - } + mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); + mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); + mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore()); + mEnviroment.mRaster.set(rsc->getDefaultProgramRaster()); - s->mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); - s->mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); - s->mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore()); - s->mEnviroment.mRaster.set(rsc->getDefaultProgramRaster()); + rsc->mHal.funcs.script.invokeInit(rsc, this); - const static int pragmaMax = 16; - size_t pragmaCount = bccGetPragmaCount(s->mBccScript); - char const *keys[pragmaMax]; - char const *values[pragmaMax]; - bccGetPragmaList(s->mBccScript, pragmaMax, keys, values); - - for (size_t i=0; i < pragmaCount; ++i) { + for (size_t i=0; i < mHal.info.exportedPragmaCount; ++i) { + const char * key = mHal.info.exportedPragmaKeyList[i]; + const char * value = mHal.info.exportedPragmaValueList[i]; //LOGE("pragma %s %s", keys[i], values[i]); - if (!strcmp(keys[i], "version")) { - if (!strcmp(values[i], "1")) { + if (!strcmp(key, "version")) { + if (!strcmp(value, "1")) { continue; } - LOGE("Invalid version pragma value: %s\n", values[i]); + LOGE("Invalid version pragma value: %s\n", value); return false; } - if (!strcmp(keys[i], "stateVertex")) { - if (!strcmp(values[i], "default")) { + if (!strcmp(key, "stateVertex")) { + if (!strcmp(value, "default")) { continue; } - if (!strcmp(values[i], "parent")) { - s->mEnviroment.mVertex.clear(); + if (!strcmp(value, "parent")) { + mEnviroment.mVertex.clear(); continue; } - LOGE("Unrecognized value %s passed to stateVertex", values[i]); + LOGE("Unrecognized value %s passed to stateVertex", value); return false; } - if (!strcmp(keys[i], "stateRaster")) { - if (!strcmp(values[i], "default")) { + if (!strcmp(key, "stateRaster")) { + if (!strcmp(value, "default")) { continue; } - if (!strcmp(values[i], "parent")) { - s->mEnviroment.mRaster.clear(); + if (!strcmp(value, "parent")) { + mEnviroment.mRaster.clear(); continue; } - LOGE("Unrecognized value %s passed to stateRaster", values[i]); + LOGE("Unrecognized value %s passed to stateRaster", value); return false; } - if (!strcmp(keys[i], "stateFragment")) { - if (!strcmp(values[i], "default")) { + if (!strcmp(key, "stateFragment")) { + if (!strcmp(value, "default")) { continue; } - if (!strcmp(values[i], "parent")) { - s->mEnviroment.mFragment.clear(); + if (!strcmp(value, "parent")) { + mEnviroment.mFragment.clear(); continue; } - LOGE("Unrecognized value %s passed to stateFragment", values[i]); + LOGE("Unrecognized value %s passed to stateFragment", value); return false; } - if (!strcmp(keys[i], "stateStore")) { - if (!strcmp(values[i], "default")) { + if (!strcmp(key, "stateStore")) { + if (!strcmp(value, "default")) { continue; } - if (!strcmp(values[i], "parent")) { - s->mEnviroment.mFragmentStore.clear(); + if (!strcmp(value, "parent")) { + mEnviroment.mFragmentStore.clear(); continue; } - LOGE("Unrecognized value %s passed to stateStore", values[i]); + LOGE("Unrecognized value %s passed to stateStore", value); return false; } } - size_t objectSlotCount = bccGetObjectSlotCount(s->mBccScript); - uint32_t *objectSlots = NULL; - if (objectSlotCount) { - objectSlots = new uint32_t[objectSlotCount]; - bccGetObjectSlotList(s->mBccScript, objectSlotCount, objectSlots); - s->mProgram.mObjectSlotList = objectSlots; - s->mProgram.mObjectSlotCount = objectSlotCount; - } + mSlots = new ObjectBaseRef<Allocation>[mHal.info.exportedVariableCount]; + mTypes = new ObjectBaseRef<const Type>[mHal.info.exportedVariableCount]; return true; } @@ -610,39 +462,19 @@ bool ScriptCState::runCompiler(Context *rsc, namespace android { namespace renderscript { -void rsi_ScriptCBegin(Context * rsc) { -} - -void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len) { - ScriptCState *ss = &rsc->mScriptC; - - char *t = (char *)malloc(len + 1); - memcpy(t, text, len); - t[len] = 0; - ss->mScriptText = t; - ss->mScriptLen = len; -} - - RsScript rsi_ScriptCCreate(Context *rsc, - const char *packageName /* deprecated */, - const char *resName, - const char *cacheDir) + const char *resName, const char *cacheDir, + const char *text, uint32_t len) { - ScriptCState *ss = &rsc->mScriptC; - ScriptC *s = new ScriptC(rsc); - s->mEnviroment.mScriptText = ss->mScriptText; - s->mEnviroment.mScriptTextLength = ss->mScriptLen; - ss->mScriptText = NULL; - ss->mScriptLen = 0; - s->incUserRef(); - if (!ss->runCompiler(rsc, s, resName, cacheDir)) { + if (!s->runCompiler(rsc, resName, cacheDir, (uint8_t *)text, len)) { // Error during compile, destroy s and return null. delete s; return NULL; } + + s->incUserRef(); return s; } diff --git a/libs/rs/rsScriptC.h b/libs/rs/rsScriptC.h index 2c74b5b3ef4e..da5cb2bc00f5 100644 --- a/libs/rs/rsScriptC.h +++ b/libs/rs/rsScriptC.h @@ -21,7 +21,6 @@ #include "RenderScriptEnv.h" -struct BCCOpaqueScript; // --------------------------------------------------------------------------- namespace android { @@ -36,21 +35,6 @@ public: ScriptC(Context *); virtual ~ScriptC(); - struct Program_t { - int mVersionMajor; - int mVersionMinor; - - RunScript_t mRoot; - VoidFunc_t mInit; - - uint32_t * mObjectSlotList; - uint32_t mObjectSlotCount; - }; - - - Program_t mProgram; - - BCCOpaqueScript *mBccScript; const Allocation *ptrToAllocation(const void *) const; @@ -69,6 +53,9 @@ public: virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SCRIPT_C; } static Type *createFromStream(Context *rsc, IStream *stream) { return NULL; } + bool runCompiler(Context *rsc, const char *resName, const char *cacheDir, + const uint8_t *bitcode, size_t bitcodeLen); + protected: void setupScript(Context *); void setupGLState(Context *); @@ -83,8 +70,6 @@ public: char * mScriptText; size_t mScriptLen; - bool runCompiler(Context *rsc, ScriptC *s, const char *resName, const char *cacheDir); - struct SymbolTable_t { const char * mName; void * mPtr; diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp index 23230a630809..8095f5a82665 100644 --- a/libs/rs/rsScriptC_Lib.cpp +++ b/libs/rs/rsScriptC_Lib.cpp @@ -141,90 +141,74 @@ static float SC_getDt() { // ////////////////////////////////////////////////////////////////////////////// -static uint32_t SC_allocGetDimX(RsAllocation va) { - const Allocation *a = static_cast<const Allocation *>(va); +static uint32_t SC_allocGetDimX(Allocation *a) { CHECK_OBJ(a); - //LOGE("SC_allocGetDimX a=%p type=%p", a, a->getType()); - return a->getType()->getDimX(); + return a->mHal.state.dimensionX; } -static uint32_t SC_allocGetDimY(RsAllocation va) { - const Allocation *a = static_cast<const Allocation *>(va); +static uint32_t SC_allocGetDimY(Allocation *a) { CHECK_OBJ(a); - return a->getType()->getDimY(); + return a->mHal.state.dimensionY; } -static uint32_t SC_allocGetDimZ(RsAllocation va) { - const Allocation *a = static_cast<const Allocation *>(va); +static uint32_t SC_allocGetDimZ(Allocation *a) { CHECK_OBJ(a); - return a->getType()->getDimZ(); + return a->mHal.state.dimensionZ; } -static uint32_t SC_allocGetDimLOD(RsAllocation va) { - const Allocation *a = static_cast<const Allocation *>(va); +static uint32_t SC_allocGetDimLOD(Allocation *a) { CHECK_OBJ(a); - return a->getType()->getDimLOD(); + return a->mHal.state.hasMipmaps; } -static uint32_t SC_allocGetDimFaces(RsAllocation va) { - const Allocation *a = static_cast<const Allocation *>(va); +static uint32_t SC_allocGetDimFaces(Allocation *a) { CHECK_OBJ(a); - return a->getType()->getDimFaces(); + return a->mHal.state.hasFaces; } -static const void * SC_getElementAtX(RsAllocation va, uint32_t x) { - const Allocation *a = static_cast<const Allocation *>(va); +static const void * SC_getElementAtX(Allocation *a, uint32_t x) { CHECK_OBJ(a); - const Type *t = a->getType(); - CHECK_OBJ(t); const uint8_t *p = (const uint8_t *)a->getPtr(); - return &p[t->getElementSizeBytes() * x]; + return &p[a->mHal.state.elementSizeBytes * x]; } -static const void * SC_getElementAtXY(RsAllocation va, uint32_t x, uint32_t y) { - const Allocation *a = static_cast<const Allocation *>(va); +static const void * SC_getElementAtXY(Allocation *a, uint32_t x, uint32_t y) { CHECK_OBJ(a); - const Type *t = a->getType(); - CHECK_OBJ(t); const uint8_t *p = (const uint8_t *)a->getPtr(); - return &p[t->getElementSizeBytes() * (x + y*t->getDimX())]; + return &p[a->mHal.state.elementSizeBytes * (x + y * a->mHal.state.dimensionX)]; } -static const void * SC_getElementAtXYZ(RsAllocation va, uint32_t x, uint32_t y, uint32_t z) { - const Allocation *a = static_cast<const Allocation *>(va); +static const void * SC_getElementAtXYZ(Allocation *a, uint32_t x, uint32_t y, uint32_t z) { CHECK_OBJ(a); - const Type *t = a->getType(); - CHECK_OBJ(t); const uint8_t *p = (const uint8_t *)a->getPtr(); - return &p[t->getElementSizeBytes() * (x + y*t->getDimX())]; + return &p[a->mHal.state.elementSizeBytes * (x + y * a->mHal.state.dimensionX + + z * a->mHal.state.dimensionX * a->mHal.state.dimensionY)]; } -static void SC_setObject(void **vdst, void * vsrc) { - //LOGE("SC_setObject %p,%p %p", vdst, *vdst, vsrc); - if (vsrc) { - CHECK_OBJ(vsrc); - static_cast<ObjectBase *>(vsrc)->incSysRef(); +void android::renderscript::rsiSetObject(ObjectBase **dst, ObjectBase * src) { + //LOGE("rsiSetObject %p,%p %p", vdst, *vdst, vsrc); + if (src) { + CHECK_OBJ(src); + src->incSysRef(); } - if (vdst[0]) { - CHECK_OBJ(vdst[0]); - static_cast<ObjectBase *>(vdst[0])->decSysRef(); + if (dst[0]) { + CHECK_OBJ(dst[0]); + dst[0]->decSysRef(); } - *vdst = vsrc; - //LOGE("SC_setObject *"); + *dst = src; } -static void SC_clearObject(void **vdst) { - //LOGE("SC_clearObject %p,%p", vdst, *vdst); - if (vdst[0]) { - CHECK_OBJ(vdst[0]); - static_cast<ObjectBase *>(vdst[0])->decSysRef(); +void android::renderscript::rsiClearObject(ObjectBase **dst) { + //LOGE("rsiClearObject %p,%p", vdst, *vdst); + if (dst[0]) { + CHECK_OBJ(dst[0]); + dst[0]->decSysRef(); } - *vdst = NULL; - //LOGE("SC_clearObject *"); + *dst = NULL; } -static bool SC_isObject(RsAllocation vsrc) { - return vsrc != NULL; +bool android::renderscript::rsiIsObject(const ObjectBase *src) { + return src != NULL; } static void SC_debugF(const char *s, float f) { @@ -873,49 +857,49 @@ static ScriptCState::SymbolTable_t gSyms[] = { { "_Z14rsGetElementAt13rs_allocationjj", (void *)&SC_getElementAtXY, true }, { "_Z14rsGetElementAt13rs_allocationjjj", (void *)&SC_getElementAtXYZ, true }, - { "_Z11rsSetObjectP10rs_elementS_", (void *)&SC_setObject, true }, - { "_Z13rsClearObjectP10rs_element", (void *)&SC_clearObject, true }, - { "_Z10rsIsObject10rs_element", (void *)&SC_isObject, true }, + { "_Z11rsSetObjectP10rs_elementS_", (void *)&rsiSetObject, true }, + { "_Z13rsClearObjectP10rs_element", (void *)&rsiClearObject, true }, + { "_Z10rsIsObject10rs_element", (void *)&rsiIsObject, true }, - { "_Z11rsSetObjectP7rs_typeS_", (void *)&SC_setObject, true }, - { "_Z13rsClearObjectP7rs_type", (void *)&SC_clearObject, true }, - { "_Z10rsIsObject7rs_type", (void *)&SC_isObject, true }, + { "_Z11rsSetObjectP7rs_typeS_", (void *)&rsiSetObject, true }, + { "_Z13rsClearObjectP7rs_type", (void *)&rsiClearObject, true }, + { "_Z10rsIsObject7rs_type", (void *)&rsiIsObject, true }, - { "_Z11rsSetObjectP13rs_allocationS_", (void *)&SC_setObject, true }, - { "_Z13rsClearObjectP13rs_allocation", (void *)&SC_clearObject, true }, - { "_Z10rsIsObject13rs_allocation", (void *)&SC_isObject, true }, + { "_Z11rsSetObjectP13rs_allocationS_", (void *)&rsiSetObject, true }, + { "_Z13rsClearObjectP13rs_allocation", (void *)&rsiClearObject, true }, + { "_Z10rsIsObject13rs_allocation", (void *)&rsiIsObject, true }, - { "_Z11rsSetObjectP10rs_samplerS_", (void *)&SC_setObject, true }, - { "_Z13rsClearObjectP10rs_sampler", (void *)&SC_clearObject, true }, - { "_Z10rsIsObject10rs_sampler", (void *)&SC_isObject, true }, + { "_Z11rsSetObjectP10rs_samplerS_", (void *)&rsiSetObject, true }, + { "_Z13rsClearObjectP10rs_sampler", (void *)&rsiClearObject, true }, + { "_Z10rsIsObject10rs_sampler", (void *)&rsiIsObject, true }, - { "_Z11rsSetObjectP9rs_scriptS_", (void *)&SC_setObject, true }, - { "_Z13rsClearObjectP9rs_script", (void *)&SC_clearObject, true }, - { "_Z10rsIsObject9rs_script", (void *)&SC_isObject, true }, + { "_Z11rsSetObjectP9rs_scriptS_", (void *)&rsiSetObject, true }, + { "_Z13rsClearObjectP9rs_script", (void *)&rsiClearObject, true }, + { "_Z10rsIsObject9rs_script", (void *)&rsiIsObject, true }, - { "_Z11rsSetObjectP7rs_meshS_", (void *)&SC_setObject, true }, - { "_Z13rsClearObjectP7rs_mesh", (void *)&SC_clearObject, true }, - { "_Z10rsIsObject7rs_mesh", (void *)&SC_isObject, true }, + { "_Z11rsSetObjectP7rs_meshS_", (void *)&rsiSetObject, true }, + { "_Z13rsClearObjectP7rs_mesh", (void *)&rsiClearObject, true }, + { "_Z10rsIsObject7rs_mesh", (void *)&rsiIsObject, true }, - { "_Z11rsSetObjectP19rs_program_fragmentS_", (void *)&SC_setObject, true }, - { "_Z13rsClearObjectP19rs_program_fragment", (void *)&SC_clearObject, true }, - { "_Z10rsIsObject19rs_program_fragment", (void *)&SC_isObject, true }, + { "_Z11rsSetObjectP19rs_program_fragmentS_", (void *)&rsiSetObject, true }, + { "_Z13rsClearObjectP19rs_program_fragment", (void *)&rsiClearObject, true }, + { "_Z10rsIsObject19rs_program_fragment", (void *)&rsiIsObject, true }, - { "_Z11rsSetObjectP17rs_program_vertexS_", (void *)&SC_setObject, true }, - { "_Z13rsClearObjectP17rs_program_vertex", (void *)&SC_clearObject, true }, - { "_Z10rsIsObject17rs_program_vertex", (void *)&SC_isObject, true }, + { "_Z11rsSetObjectP17rs_program_vertexS_", (void *)&rsiSetObject, true }, + { "_Z13rsClearObjectP17rs_program_vertex", (void *)&rsiClearObject, true }, + { "_Z10rsIsObject17rs_program_vertex", (void *)&rsiIsObject, true }, - { "_Z11rsSetObjectP17rs_program_rasterS_", (void *)&SC_setObject, true }, - { "_Z13rsClearObjectP17rs_program_raster", (void *)&SC_clearObject, true }, - { "_Z10rsIsObject17rs_program_raster", (void *)&SC_isObject, true }, + { "_Z11rsSetObjectP17rs_program_rasterS_", (void *)&rsiSetObject, true }, + { "_Z13rsClearObjectP17rs_program_raster", (void *)&rsiClearObject, true }, + { "_Z10rsIsObject17rs_program_raster", (void *)&rsiIsObject, true }, - { "_Z11rsSetObjectP16rs_program_storeS_", (void *)&SC_setObject, true }, - { "_Z13rsClearObjectP16rs_program_store", (void *)&SC_clearObject, true }, - { "_Z10rsIsObject16rs_program_store", (void *)&SC_isObject, true }, + { "_Z11rsSetObjectP16rs_program_storeS_", (void *)&rsiSetObject, true }, + { "_Z13rsClearObjectP16rs_program_store", (void *)&rsiClearObject, true }, + { "_Z10rsIsObject16rs_program_store", (void *)&rsiIsObject, true }, - { "_Z11rsSetObjectP7rs_fontS_", (void *)&SC_setObject, true }, - { "_Z13rsClearObjectP7rs_font", (void *)&SC_clearObject, true }, - { "_Z10rsIsObject7rs_font", (void *)&SC_isObject, true }, + { "_Z11rsSetObjectP7rs_fontS_", (void *)&rsiSetObject, true }, + { "_Z13rsClearObjectP7rs_font", (void *)&rsiClearObject, true }, + { "_Z10rsIsObject7rs_font", (void *)&rsiIsObject, true }, { "_Z21rsAllocationMarkDirty13rs_allocation", (void *)&SC_allocationMarkDirty, true }, @@ -1000,7 +984,7 @@ static ScriptCState::SymbolTable_t gSyms[] = { { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_2x2, true }, { "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach, false }, - //{ "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach2, true }, + //{ "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach2, false }, //////////////////////////////////////////////////////////////////// @@ -1021,3 +1005,7 @@ const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym) } return NULL; } + + + + diff --git a/libs/rs/rs_hal.h b/libs/rs/rs_hal.h new file mode 100644 index 000000000000..48e3f369f3c1 --- /dev/null +++ b/libs/rs/rs_hal.h @@ -0,0 +1,94 @@ +/* + * 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. + */ + +#ifndef RS_HAL_H +#define RS_HAL_H + +#include <RenderScriptDefines.h> + +namespace android { +namespace renderscript { + +class Context; +class ObjectBase; +class Element; +class Type; +class Allocation; +class Script; +class ScriptC; + + +typedef struct RsHalRec RsHal; + +typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName); + + + +/** + * Script management functions + */ +typedef struct { + void (*shutdownDriver)(RsHal dc); + void (*getVersion)(unsigned int *major, unsigned int *minor); + + + + struct { + bool (*scriptInit)(const Context *rsc, ScriptC *s, + char const *resName, + char const *cacheDir, + uint8_t const *bitcode, + size_t bitcodeSize, + uint32_t flags, + RsHalSymbolLookupFunc lookupFunc); + + void (*invokeFunction)(const Context *rsc, const Script *s, + uint32_t slot, + const void *params, + size_t paramLength); + int (*invokeRoot)(const Context *rsc, const Script *s); + void (*invokeInit)(const Context *rsc, const Script *s); + + void (*setGlobalVar)(const Context *rsc, const Script *s, + uint32_t slot, + void *data, + size_t dataLength); + void (*setGlobalBind)(const Context *rsc, const Script *s, + uint32_t slot, + void *data); + void (*setGlobalObj)(const Context *rsc, const Script *s, + uint32_t slot, + ObjectBase *data); + + void (*destroy)(const Context *rsc, Script *s); + } script; + + + +} RsdHalFunctions; + +void rsiSetObject(ObjectBase **vdst, ObjectBase * vsrc); +void rsiClearObject(ObjectBase **vdst); +bool rsiIsObject(const ObjectBase *vdst); + +} +} + + +bool rsdHalInit(android::renderscript::Context *, uint32_t version_major, uint32_t version_minor); + +#endif + |