From 8f8a5724bee0f958ef81a7154e4fd40fb6f07a49 Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Thu, 15 Jul 2010 17:11:13 -0700 Subject: [PATCH] 1st cut of ForEach and test. Change-Id: I6534569c8d26db8b9691666134a555c8bf94184e --- libs/rs/RenderScript.h | 13 ++ .../res/raw/horizontal_blur.rs | 43 ++++++ .../res/raw/horizontal_blur_bc.bc | Bin 0 -> 1324 bytes libs/rs/java/ImageProcessing/res/raw/ip.rsh | 15 +++ .../java/ImageProcessing/res/raw/threshold.rs | 127 ++++-------------- .../ImageProcessing/res/raw/threshold_bc.bc | Bin 8596 -> 7208 bytes .../ImageProcessing/res/raw/vertical_blur.rs | 51 +++++++ .../res/raw/vertical_blur_bc.bc | Bin 0 -> 1464 bytes .../rs/image/ImageProcessingActivity.java | 11 ++ .../rs/image/ScriptC_Horizontal_blur.java | 42 ++++++ .../android/rs/image/ScriptC_Threshold.java | 22 +++ .../rs/image/ScriptC_Vertical_blur.java | 42 ++++++ libs/rs/rsScript.h | 8 +- libs/rs/rsScriptC.cpp | 117 +++++++++------- libs/rs/rsScriptC.h | 8 +- libs/rs/rsScriptC_Lib.cpp | 63 +++------ libs/rs/scriptc/rs_math.rsh | 25 ++-- 17 files changed, 377 insertions(+), 210 deletions(-) create mode 100644 libs/rs/java/ImageProcessing/res/raw/horizontal_blur.rs create mode 100644 libs/rs/java/ImageProcessing/res/raw/horizontal_blur_bc.bc create mode 100644 libs/rs/java/ImageProcessing/res/raw/ip.rsh create mode 100644 libs/rs/java/ImageProcessing/res/raw/vertical_blur.rs create mode 100644 libs/rs/java/ImageProcessing/res/raw/vertical_blur_bc.bc create mode 100644 libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Horizontal_blur.java create mode 100644 libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Vertical_blur.java diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h index 745df95e445a8..6636fef57d359 100644 --- a/libs/rs/RenderScript.h +++ b/libs/rs/RenderScript.h @@ -255,6 +255,19 @@ typedef struct { 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; + #ifndef NO_RS_FUNCS #include "rsgApiFuncDecl.h" #endif diff --git a/libs/rs/java/ImageProcessing/res/raw/horizontal_blur.rs b/libs/rs/java/ImageProcessing/res/raw/horizontal_blur.rs new file mode 100644 index 0000000000000..7b0e6bcc68fbb --- /dev/null +++ b/libs/rs/java/ImageProcessing/res/raw/horizontal_blur.rs @@ -0,0 +1,43 @@ +#pragma version(1) + +#include "../../../../scriptc/rs_types.rsh" +#include "../../../../scriptc/rs_math.rsh" + +#include "ip.rsh" + +uchar4 * ScratchPixel; + +#pragma rs export_var(ScratchPixel) + +void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32_t y) { + uchar4 *output = (uchar4 *)v_out; + const uchar4 *input = (uchar4 *)v_in; + const FilterStruct *fs = (const FilterStruct *)usrData; + + float4 blurredPixel = 0; + float4 currentPixel = 0; + for(int r = -fs->radius; r <= fs->radius; r ++) { + // Stepping left and right away from the pixel + int validW = x + r; + // Clamp to zero and width max() isn't exposed for ints yet + if(validW < 0) { + validW = 0; + } + if(validW > fs->width - 1) { + validW = fs->width - 1; + } + //int validW = rsClamp(w + r, 0, width - 1); + + float weight = fs->gaussian[r + fs->radius]; + currentPixel.x = (float)(input[validW].x); + currentPixel.y = (float)(input[validW].y); + currentPixel.z = (float)(input[validW].z); + //currentPixel.w = (float)(input->a); + + blurredPixel += currentPixel * weight; + } + + output->x = (uint8_t)blurredPixel.x; + output->y = (uint8_t)blurredPixel.y; + output->z = (uint8_t)blurredPixel.z; +} diff --git a/libs/rs/java/ImageProcessing/res/raw/horizontal_blur_bc.bc b/libs/rs/java/ImageProcessing/res/raw/horizontal_blur_bc.bc new file mode 100644 index 0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ZIBhd zDsk+yL$3LXl#~7x&MX>^SfVXtE4vS&+7D#7HDfu9+4+v?*)f0NK-C t3T;ljj)?UU--{H=;(>rZv7iSX%(Hu(&N_}1>%f#!ZB*32V~aLo`wuEtx4QrU literal 0 HcmV?d00001 diff --git a/libs/rs/java/ImageProcessing/res/raw/ip.rsh b/libs/rs/java/ImageProcessing/res/raw/ip.rsh new file mode 100644 index 0000000000000..4073304f6490f --- /dev/null +++ b/libs/rs/java/ImageProcessing/res/raw/ip.rsh @@ -0,0 +1,15 @@ +#pragma rs java_package_name(com.android.rs.image) + +#define MAX_RADIUS 25 + +typedef struct { + float *gaussian; //[MAX_RADIUS * 2 + 1]; + rs_matrix3x3 colorMat; + + int height; + int width; + int radius; + +} FilterStruct; + + diff --git a/libs/rs/java/ImageProcessing/res/raw/threshold.rs b/libs/rs/java/ImageProcessing/res/raw/threshold.rs index 9585e92e89248..ecbfac4631e61 100644 --- a/libs/rs/java/ImageProcessing/res/raw/threshold.rs +++ b/libs/rs/java/ImageProcessing/res/raw/threshold.rs @@ -2,12 +2,8 @@ #include "../../../../scriptc/rs_types.rsh" #include "../../../../scriptc/rs_math.rsh" -#include "../../../../scriptc/rs_graphics.rsh" -#pragma rs java_package_name(com.android.rs.image) - - -#define MAX_RADIUS 25 +#include "ip.rsh" int height; int width; @@ -28,11 +24,15 @@ float saturation; static float inWMinInB; static float outWMinOutB; static float overInWMinInB; -//static float3 gammaV; +static FilterStruct filterStruct; -#pragma rs export_var(height, width, radius, InPixel, OutPixel, ScratchPixel, inBlack, outBlack, inWhite, outWhite, gamma, saturation, InPixel, OutPixel, ScratchPixel) +#pragma rs export_var(height, width, radius, InPixel, OutPixel, ScratchPixel, inBlack, outBlack, inWhite, outWhite, gamma, saturation, InPixel, OutPixel, ScratchPixel, vBlurScript, hBlurScript) #pragma rs export_func(filter, filterBenchmark); +rs_script vBlurScript; +rs_script hBlurScript; + + // Store our coefficients here static float gaussian[MAX_RADIUS * 2 + 1]; static rs_matrix3x3 colorMat; @@ -145,48 +145,6 @@ static void processNoBlur() { rsSendToClient(&count, 1, 4, 0); } -static void horizontalBlur() { - float4 blurredPixel = 0; - float4 currentPixel = 0; - // Horizontal blur - int w, h, r; - for(h = 0; h < height; h ++) { - uchar4 *input = InPixel + h*width; - uchar4 *output = ScratchPixel + h*width; - - for(w = 0; w < width; w ++) { - blurredPixel = 0; - - for(r = -radius; r <= radius; r ++) { - // Stepping left and right away from the pixel - int validW = w + r; - // Clamp to zero and width max() isn't exposed for ints yet - if(validW < 0) { - validW = 0; - } - if(validW > width - 1) { - validW = width - 1; - } - //int validW = rsClamp(w + r, 0, width - 1); - - float weight = gaussian[r + radius]; - currentPixel.x = (float)(input[validW].x); - currentPixel.y = (float)(input[validW].y); - currentPixel.z = (float)(input[validW].z); - //currentPixel.w = (float)(input->a); - - blurredPixel += currentPixel*weight; - } - - output->x = (uint8_t)blurredPixel.x; - output->y = (uint8_t)blurredPixel.y; - output->z = (uint8_t)blurredPixel.z; - //output->a = (uint8_t)blurredPixel.w; - output++; - } - } -} - static void horizontalBlurLevels() { float4 blurredPixel = 0; float4 currentPixel = 0; @@ -232,52 +190,11 @@ static void horizontalBlurLevels() { } } -static void verticalBlur() { - float4 blurredPixel = 0; - float4 currentPixel = 0; - // Vertical blur - int w, h, r; - for(h = 0; h < height; h ++) { - uchar4 *output = OutPixel + h*width; - - for(w = 0; w < width; w ++) { - - blurredPixel = 0; - for(r = -radius; r <= radius; r ++) { -#if 1 - int validH = h + r; - // Clamp to zero and width - if(validH < 0) { - validH = 0; - } - if(validH > height - 1) { - validH = height - 1; - } - - uchar4 *input = ScratchPixel + validH*width + w; - - float weight = gaussian[r + radius]; - - currentPixel.x = (float)(input->x); - currentPixel.y = (float)(input->y); - currentPixel.z = (float)(input->z); - - blurredPixel.xyz += currentPixel.xyz * weight; -#else - int validH = rsClamp(h + r, 0, height - 1); - uchar4 *input = ScratchPixel + validH*width + w; - blurredPixel.xyz += convert_float3(input->xyz) * gaussian[r + radius]; -#endif - } - - //output->xyz = convert_uchar3(blurredPixel.xyz); - output->x = (uint8_t)blurredPixel.x; - output->y = (uint8_t)blurredPixel.y; - output->z = (uint8_t)blurredPixel.z; - //output->a = (uint8_t)blurredPixel.w; - output++; - } - } +static void initStructs() { + filterStruct.gaussian = gaussian; + filterStruct.width = width; + filterStruct.height = height; + filterStruct.radius = radius; } void filter() { @@ -285,6 +202,8 @@ void filter() { RS_DEBUG(width); RS_DEBUG(radius); + initStructs(); + computeColorMatrix(); if(radius == 0) { @@ -295,18 +214,30 @@ void filter() { computeGaussianWeights(); horizontalBlurLevels(); - verticalBlur(); + + rsForEach(vBlurScript, + rsGetAllocation(InPixel), + rsGetAllocation(OutPixel), + &filterStruct); int count = 0; rsSendToClient(&count, 1, 4, 0); } void filterBenchmark() { + initStructs(); computeGaussianWeights(); - horizontalBlur(); - verticalBlur(); + rsForEach(hBlurScript, + rsGetAllocation(InPixel), + rsGetAllocation(OutPixel), + &filterStruct); + + rsForEach(vBlurScript, + rsGetAllocation(InPixel), + rsGetAllocation(OutPixel), + &filterStruct); int count = 0; rsSendToClient(&count, 1, 4, 0); diff --git a/libs/rs/java/ImageProcessing/res/raw/threshold_bc.bc b/libs/rs/java/ImageProcessing/res/raw/threshold_bc.bc index 95dcd8d61aef67fc5dad78ecfbd6f6e16b578e48..8f37fdc349ccb75016b1c773b8531e9b320d4b58 100644 GIT binary patch literal 7208 zcmZ8l3tUrI(myw^n?MK&1PqX10*GL-y#dsKsCn_KfB^zx@ex2MyKQ0w!AI5R!K+Fw zBDJ*Wx6#_J-LLk;Dq7daCW4f$L8GGLVk=Z?wc4un-MZ~JCrEeO`%C7`IrrST=g!QT z`Oi^noL|Yf2$3X01RtRQ1iUqJv#O7g$>PT+wGwsQNlbP~IAdd}MU+ZYxB9Ak`0+vo zTa@V&uZ_y^X^}QTyXvawlmMiKp+P@HJ71^u}j(IY@36v(lv!48$5ynJIyVP zwVjPKE9om&kt<^wryCkqm>btP8>cJCmAf0O*y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ktN{1+B zZ|dMTFYe|qUiB;cXEExZo3l)?IY+Rq*B*9xLuZk=r(d0RFD9VrKfMD#Q71=ipBC;< zX9;LoMxp;E)x4&UW5Q$g)s9?sjEsT%>^hqxy`WZ$FL6nxdgBC1+R-T{TZ00I%`GsM z@HdpCr)XYY7G5tm*?Mpyzn8fb)rZOyg+ZOO9&c-(f(E7BrQYOaI~gS?@0Vm$F3X4} zE*#fv`&jyG?OaVv;AbVjly3IU$Prw6HhL2?y<)-5Uv4-d_4S5K7e8_R*_ j;Mud7F!;@DH|M`tB4Xar1biqB&~a*daqb_E%ya!8o$dvd diff --git a/libs/rs/java/ImageProcessing/res/raw/vertical_blur.rs b/libs/rs/java/ImageProcessing/res/raw/vertical_blur.rs new file mode 100644 index 0000000000000..846f515a4eb09 --- /dev/null +++ b/libs/rs/java/ImageProcessing/res/raw/vertical_blur.rs @@ -0,0 +1,51 @@ +#pragma version(1) + +#include "../../../../scriptc/rs_types.rsh" +#include "../../../../scriptc/rs_math.rsh" + +#include "ip.rsh" + +uchar4 * ScratchPixel; + +#pragma rs export_var(ScratchPixel) + +void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32_t y) { + uchar4 *output = (uchar4 *)v_out; + const uchar4 *input = (uchar4 *)v_in; + const FilterStruct *fs = (const FilterStruct *)usrData; + + float4 blurredPixel = 0; + float4 currentPixel = 0; + for(int r = -fs->radius; r <= fs->radius; r ++) { +#if 1 + int validH = y + r; + // Clamp to zero and width + if(validH < 0) { + validH = 0; + } + if(validH > fs->height - 1) { + validH = fs->height - 1; + } + + uchar4 *input = ScratchPixel + validH * fs->width + x; + + float weight = fs->gaussian[r + fs->radius]; + + currentPixel.x = (float)(input->x); + currentPixel.y = (float)(input->y); + currentPixel.z = (float)(input->z); + + blurredPixel.xyz += currentPixel.xyz * weight; +#else + int validH = rsClamp(y + r, 0, height - 1); + uchar4 *input = ScratchPixel + validH * width + x; + blurredPixel.xyz += convert_float3(input->xyz) * gaussian[r + fs->radius]; +#endif + } + + //output->xyz = convert_uchar3(blurredPixel.xyz); + output->x = (uint8_t)blurredPixel.x; + output->y = (uint8_t)blurredPixel.y; + output->z = (uint8_t)blurredPixel.z; +} + diff --git a/libs/rs/java/ImageProcessing/res/raw/vertical_blur_bc.bc b/libs/rs/java/ImageProcessing/res/raw/vertical_blur_bc.bc new file mode 100644 index 0000000000000000000000000000000000000000..af1cd8e097772e71214791fa9ad64b392a7b1195 GIT binary patch literal 1464 zcmZ9Le@s(X6vuCWyuR1=mA+cQHm&k%k>DiSQe;IX_9qsF(NZ)xjK1<~%%!eWR*(eq zY714UuEKOomaRBrh>NC1wz(~8wTN!3$cCFHMuotL;veF0^T(2H_vt^=oBKZZoO|#4 zp7YLq*JO_0QQ-i*#{z&w05A^#fcn)3j90kDJR-NCn-#w2^9y1)O7Lbmx2l z&j|oSItBp3)NNreCYO{%!u+hY!(6jT4d-^ky33h5V2kZRB$*QqtPXMt!vk zK`gP`EShmCM^(xxe@c0oXrXcja97ZQ0YBKQZHMi|(6NQe6nmwq`-rzyYcT({dll&g*5-VB= zYOpr?(~R)p8c$%2VVHPMeruPlxC{hGB4O2IzxSwS+kRK-I-|T+(>`;!CiWD_YYm9- zOQ#Ky*R}*^j&HCdvRVpRs({|c(GJB_To>3D;MU7|6KT9R*a8pY!d2;!p7z{9e*y39 zUZfVf-KX1gci>-ngg?kkIoTfz>!xKM~YTrAmN8~{Qy22Yq7VS_s>j_X))4# z??zFeBEB2%FRNOo)r!ycF&t5pLEcexX|-jg5AvN@()pywUUA-BdPt|aUTqitf~OJB zM2)4Wow%Cn;+12`u_x(PM3`nBiY%Ic>gnKlteaa2Mas7HG2FhDmT-5?DR~to$)3q{ zh7YrJhgSRHu0Dn*Z!sL{JEYQ={(5(~0wiLS9WdhQ zv3g>&kD$J0?7P1)d@#-Mp>NVwK|R@pSC&e{|O7_bV?AtuAzLf;{V9?ugkP7W`$-dG0D^ za(i+6B+F-)&TMXN(N>vX3?ax8E{y>JFQ*VOx*)XC=0z7a6 zm(KN;U$FnQrK(t~z1G&p@Pq=M*R``8c&sn(EE|rxJ+yLYLJ1nlm-jo}VA-#egM>h$ N;jiu7JjCo_+J9%!>`(vz literal 0 HcmV?d00001 diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java index 7bf6596205c06..21c3d7450096c 100644 --- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java +++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java @@ -42,6 +42,8 @@ public class ImageProcessingActivity extends Activity private Bitmap mBitmapOut; private Bitmap mBitmapScratch; private ScriptC_Threshold mScript; + private ScriptC_Vertical_blur mScriptVBlur; + private ScriptC_Horizontal_blur mScriptHBlur; private int mRadius = 0; private SeekBar mRadiusSeekBar; @@ -373,6 +375,12 @@ public class ImageProcessingActivity extends Activity mOutPixelsAllocation = Allocation.createBitmapRef(mRS, mBitmapOut); mScratchPixelsAllocation = Allocation.createBitmapRef(mRS, mBitmapScratch); + mScriptVBlur = new ScriptC_Vertical_blur(mRS, getResources(), R.raw.vertical_blur_bc, false); + mScriptVBlur.bind_ScratchPixel(mScratchPixelsAllocation); + + mScriptHBlur = new ScriptC_Horizontal_blur(mRS, getResources(), R.raw.horizontal_blur_bc, false); + mScriptHBlur.bind_ScratchPixel(mScratchPixelsAllocation); + mScript = new ScriptC_Threshold(mRS, getResources(), R.raw.threshold_bc, false); mScript.set_width(mBitmapIn.getWidth()); mScript.set_height(mBitmapIn.getHeight()); @@ -388,6 +396,9 @@ public class ImageProcessingActivity extends Activity mScript.bind_InPixel(mInPixelsAllocation); mScript.bind_OutPixel(mOutPixelsAllocation); mScript.bind_ScratchPixel(mScratchPixelsAllocation); + + mScript.set_vBlurScript(mScriptVBlur); + mScript.set_hBlurScript(mScriptHBlur); } private Bitmap loadBitmap(int resource) { diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Horizontal_blur.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Horizontal_blur.java new file mode 100644 index 0000000000000..8ee50a833aebd --- /dev/null +++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Horizontal_blur.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.image; + +import android.renderscript.*; +import android.content.res.Resources; +import android.util.Log; + +public class ScriptC_Horizontal_blur extends ScriptC { + // Constructor + public ScriptC_Horizontal_blur(RenderScript rs, Resources resources, int id, boolean isRoot) { + super(rs, resources, id, isRoot); + } + + private final static int mExportVarIdx_ScratchPixel = 0; + private Allocation mExportVar_ScratchPixel; + public void bind_ScratchPixel(Allocation v) { + mExportVar_ScratchPixel = v; + if(v == null) bindAllocation(null, mExportVarIdx_ScratchPixel); + else bindAllocation(v, mExportVarIdx_ScratchPixel); + } + + public Allocation get_ScratchPixel() { + return mExportVar_ScratchPixel; + } + +} + diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java index ea363d36caf57..c23dca1a0ad1b 100644 --- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java +++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java @@ -161,6 +161,28 @@ public class ScriptC_Threshold extends ScriptC { return mExportVar_saturation; } + private final static int mExportVarIdx_vBlurScript = 12; + private Script mExportVar_vBlurScript; + public void set_vBlurScript(Script v) { + mExportVar_vBlurScript = v; + setVar(mExportVarIdx_vBlurScript, (v == null) ? 0 : v.getID()); + } + + public Script get_vBlurScript() { + return mExportVar_vBlurScript; + } + + private final static int mExportVarIdx_hBlurScript = 13; + private Script mExportVar_hBlurScript; + public void set_hBlurScript(Script v) { + mExportVar_hBlurScript = v; + setVar(mExportVarIdx_hBlurScript, (v == null) ? 0 : v.getID()); + } + + public Script get_hBlurScript() { + return mExportVar_hBlurScript; + } + private final static int mExportFuncIdx_filter = 0; public void invoke_filter() { invoke(mExportFuncIdx_filter); diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Vertical_blur.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Vertical_blur.java new file mode 100644 index 0000000000000..0215f6067c96d --- /dev/null +++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Vertical_blur.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rs.image; + +import android.renderscript.*; +import android.content.res.Resources; +import android.util.Log; + +public class ScriptC_Vertical_blur extends ScriptC { + // Constructor + public ScriptC_Vertical_blur(RenderScript rs, Resources resources, int id, boolean isRoot) { + super(rs, resources, id, isRoot); + } + + private final static int mExportVarIdx_ScratchPixel = 0; + private Allocation mExportVar_ScratchPixel; + public void bind_ScratchPixel(Allocation v) { + mExportVar_ScratchPixel = v; + if(v == null) bindAllocation(null, mExportVarIdx_ScratchPixel); + else bindAllocation(v, mExportVarIdx_ScratchPixel); + } + + public Allocation get_ScratchPixel() { + return mExportVar_ScratchPixel; + } + +} + diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h index ea6aec5405be8..0717059fbd8ba 100644 --- a/libs/rs/rsScript.h +++ b/libs/rs/rsScript.h @@ -64,9 +64,11 @@ public: void setVar(uint32_t slot, const void *val, uint32_t len); - virtual void runForEach(Context *rsc, const Allocation *ain, Allocation *aout) = 0; - virtual void runForEach(Context *rsc, const Allocation *ain, Allocation *aout, uint32_t xStart, uint32_t xEnd) = 0; - virtual void runForEach(Context *rsc, const Allocation *ain, Allocation *aout, uint32_t xStart, uint32_t yStart, uint32_t xEnd, uint32_t yEnd) = 0; + virtual void runForEach(Context *rsc, + const Allocation * ain, + Allocation * aout, + const void * usr, + const RsScriptCall *sc = NULL) = 0; virtual void Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len) = 0; virtual void setupScript(Context *rsc) = 0; diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp index 975b7045cf33a..b87ac281dd515 100644 --- a/libs/rs/rsScriptC.cpp +++ b/libs/rs/rsScriptC.cpp @@ -136,55 +136,95 @@ uint32_t ScriptC::run(Context *rsc) return ret; } -void ScriptC::runForEach(Context *rsc, const Allocation *ain, Allocation *aout, - uint32_t xStart, uint32_t yStart, uint32_t xEnd, uint32_t yEnd) -{ - LOGE("ScriptC::runForEach not implemented"); -} -void ScriptC::runForEach(Context *rsc, const Allocation *ain, Allocation *aout, uint32_t xStart, uint32_t xEnd) +void ScriptC::runForEach(Context *rsc, + const Allocation * ain, + Allocation * aout, + const void * usr, + const RsScriptCall *sc) { uint32_t dimX = ain->getType()->getDimX(); - rsAssert(xStart < dimX); - rsAssert(xEnd <= dimX); - rsAssert(ain->getType()->getDimY() == 0); - rsAssert(ain->getType()->getDimZ() == 0); + uint32_t dimY = ain->getType()->getDimY(); + uint32_t dimZ = ain->getType()->getDimZ(); + uint32_t dimA = 0;//ain->getType()->getDimArray(); - if (xStart >= dimX) xStart = dimX - 1; - if (xEnd >= dimX) xEnd = dimX - 1; - if (xStart > xEnd) return; + uint32_t xStart = 0; + uint32_t xEnd = 0; + uint32_t yStart = 0; + uint32_t yEnd = 0; + uint32_t zStart = 0; + uint32_t zEnd = 0; + uint32_t arrayStart = 0; + uint32_t arrayEnd = 0; + + if (!sc || (sc->xEnd == 0)) { + xStart = 0; + xEnd = ain->getType()->getDimX(); + } else { + rsAssert(xStart < dimX); + rsAssert(xEnd <= dimX); + rsAssert(sc->xStart < sc->xEnd); + xStart = rsMin(dimX, sc->xStart); + xEnd = rsMin(dimX, sc->xEnd); + if (xStart >= xEnd) return; + } + + if (!sc || (sc->yEnd == 0)) { + yStart = 0; + yEnd = ain->getType()->getDimY(); + } else { + rsAssert(yStart < dimY); + rsAssert(yEnd <= dimY); + rsAssert(sc->yStart < sc->yEnd); + yStart = rsMin(dimY, sc->yStart); + yEnd = rsMin(dimY, sc->yEnd); + if (yStart >= yEnd) return; + } + + xEnd = rsMax((uint32_t)1, xEnd); + yEnd = rsMax((uint32_t)1, yEnd); + zEnd = rsMax((uint32_t)1, zEnd); + arrayEnd = rsMax((uint32_t)1, arrayEnd); + + rsAssert(ain->getType()->getDimZ() == 0); setupScript(rsc); Script * oldTLS = setTLS(this); - typedef int (*rs_t)(const void *, void *, uint32_t); + typedef int (*rs_t)(const void *, void *, const void *, uint32_t, uint32_t, uint32_t, uint32_t); + const uint8_t *ptrIn = (const uint8_t *)ain->getPtr(); - uint32_t strideIn = ain->getType()->getElementSizeBytes(); + uint32_t eStrideIn = ain->getType()->getElementSizeBytes(); uint8_t *ptrOut = NULL; - uint32_t strideOut = 0; + uint32_t eStrideOut = 0; if (aout) { ptrOut = (uint8_t *)aout->getPtr(); - strideOut = aout->getType()->getElementSizeBytes(); + eStrideOut = aout->getType()->getElementSizeBytes(); } - for (uint32_t ct=xStart; ct < xEnd; ct++) { - ((rs_t)mProgram.mRoot) (ptrIn + (strideIn * ct), ptrOut + (strideOut * ct), ct); + for (uint32_t ar = arrayStart; ar < arrayEnd; ar++) { + for (uint32_t z = zStart; z < zEnd; z++) { + for (uint32_t y = yStart; y < yEnd; y++) { + uint32_t offset = dimX * dimY * dimZ * ar + + dimX * dimY * z + + dimX * y; + uint8_t *xPtrOut = ptrOut + (eStrideOut * offset); + const uint8_t *xPtrIn = ptrIn + (eStrideIn * offset); + + for (uint32_t x = xStart; x < xEnd; x++) { + ((rs_t)mProgram.mRoot) (xPtrIn, xPtrOut, usr, x, y, z, ar); + xPtrIn += eStrideIn; + xPtrOut += eStrideOut; + } + } + } + } setTLS(oldTLS); } -void ScriptC::runForEach(Context *rsc, const Allocation *ain, Allocation *aout) -{ - if (ain->getType()->getDimY()) { - runForEach(rsc, ain, aout, 0, 0, 0xffffffff, 0xffffffff); - } else { - runForEach(rsc, ain, aout, 0, 0xffffffff); - } -} - - void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len) { //LOGE("rsi_ScriptInvoke %i", slot); @@ -246,7 +286,7 @@ static BCCvoid* symbolLookup(BCCvoid* pContext, const BCCchar* name) void ScriptCState::runCompiler(Context *rsc, ScriptC *s) { - LOGE("ScriptCState::runCompiler "); + LOGV("ScriptCState::runCompiler "); s->mBccScript = bccCreateScript(); bccScriptBitcode(s->mBccScript, s->mEnviroment.mScriptText, s->mEnviroment.mScriptTextLength); @@ -254,7 +294,7 @@ void ScriptCState::runCompiler(Context *rsc, ScriptC *s) bccCompileScript(s->mBccScript); bccGetScriptLabel(s->mBccScript, "root", (BCCvoid**) &s->mProgram.mRoot); bccGetScriptLabel(s->mBccScript, "init", (BCCvoid**) &s->mProgram.mInit); - LOGE("root %p, init %p", s->mProgram.mRoot, s->mProgram.mInit); + LOGV("root %p, init %p", s->mProgram.mRoot, s->mProgram.mInit); if (s->mProgram.mInit) { s->mProgram.mInit(); @@ -268,24 +308,9 @@ void ScriptCState::runCompiler(Context *rsc, ScriptC *s) bccGetExportFuncs(s->mBccScript, NULL, s->mEnviroment.mInvokeFunctionCount, (BCCvoid **) s->mEnviroment.mInvokeFunctions); } -// s->mEnviroment.mInvokeFunctions = (Script::InvokeFunc_t *)calloc(100, sizeof(void *)); -// BCCchar **labels = new char*[100]; -// bccGetFunctions(s->mBccScript, (BCCsizei *)&s->mEnviroment.mInvokeFunctionCount, -// 100, (BCCchar **)labels); - //LOGE("func count %i", s->mEnviroment.mInvokeFunctionCount); -// for (uint32_t i=0; i < s->mEnviroment.mInvokeFunctionCount; i++) { -// BCCsizei length; -// bccGetFunctionBinary(s->mBccScript, labels[i], (BCCvoid **)&(s->mEnviroment.mInvokeFunctions[i]), &length); - //LOGE("func %i %p", i, s->mEnviroment.mInvokeFunctions[i]); - // } - s->mEnviroment.mFieldAddress = (void **)calloc(100, sizeof(void *)); bccGetExportVars(s->mBccScript, (BCCsizei *)&s->mEnviroment.mFieldCount, 100, s->mEnviroment.mFieldAddress); - //LOGE("var count %i", s->mEnviroment.mFieldCount); - for (uint32_t i=0; i < s->mEnviroment.mFieldCount; i++) { - //LOGE("var %i %p", i, s->mEnviroment.mFieldAddress[i]); - } s->mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); s->mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); diff --git a/libs/rs/rsScriptC.h b/libs/rs/rsScriptC.h index 50e8a4ce1e549..9d09b0b52c524 100644 --- a/libs/rs/rsScriptC.h +++ b/libs/rs/rsScriptC.h @@ -57,9 +57,11 @@ public: virtual uint32_t run(Context *); - virtual void runForEach(Context *rsc, const Allocation *ain, Allocation *aout); - virtual void runForEach(Context *rsc, const Allocation *ain, Allocation *aout, uint32_t xStart, uint32_t xEnd); - virtual void runForEach(Context *rsc, const Allocation *ain, Allocation *aout, uint32_t xStart, uint32_t yStart, uint32_t xEnd, uint32_t yEnd); + virtual void runForEach(Context *rsc, + const Allocation * ain, + Allocation * aout, + const void * usr, + const RsScriptCall *sc = NULL); virtual void serialize(OStream *stream) const { } virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SCRIPT_C; } diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp index ea01134218e88..8d9ca9f0b5807 100644 --- a/libs/rs/rsScriptC_Lib.cpp +++ b/libs/rs/rsScriptC_Lib.cpp @@ -376,58 +376,31 @@ int SC_getAllocation(const void *ptr) } -void SC_ForEachii(RsScript vs, RsAllocation vin) +void SC_ForEach(RsScript vs, + RsAllocation vin, + RsAllocation vout, + const void *usr) { GET_TLS(); - Script *s = static_cast