From 87fe59a2f4d4c74539bfa0bff5f9a7e320e99415 Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Wed, 20 Apr 2011 15:09:01 -0700 Subject: Create runtime stubs for compute driver. Change-Id: I8e0250a642844a2ad3ff6efc38e385445b7da032 --- rsScriptC_LibGL.cpp | 363 +++++++++++++--------------------------------------- 1 file changed, 91 insertions(+), 272 deletions(-) (limited to 'rsScriptC_LibGL.cpp') diff --git a/rsScriptC_LibGL.cpp b/rsScriptC_LibGL.cpp index 1ed0f31b..71f1312d 100644 --- a/rsScriptC_LibGL.cpp +++ b/rsScriptC_LibGL.cpp @@ -16,7 +16,9 @@ #include "rsContext.h" #include "rsScriptC.h" -#include "rsMatrix.h" +#include "rsMatrix4x4.h" +#include "rsMatrix3x3.h" +#include "rsMatrix2x2.h" #include "utils/Timers.h" @@ -32,84 +34,64 @@ using namespace android; using namespace android::renderscript; -#define GET_TLS() ScriptTLSStruct * tls = \ - (ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \ - Context * rsc = tls->mContext; \ - ScriptC * sc = (ScriptC *) tls->mScript - +namespace android { +namespace renderscript { ////////////////////////////////////////////////////////////////////////////// // Context ////////////////////////////////////////////////////////////////////////////// -static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va) { - CHECK_OBJ_OR_NULL(va); - CHECK_OBJ(vpf); - GET_TLS(); - rsi_ProgramBindTexture(rsc, - static_cast(vpf), - slot, - static_cast(va)); +void rsrBindTexture(Context *rsc, Script *sc, ProgramFragment *pf, uint32_t slot, Allocation *a) { + CHECK_OBJ_OR_NULL(a); + CHECK_OBJ(pf); + pf->bindTexture(rsc, slot, a); } -static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs) { +void rsrBindSampler(Context *rsc, Script *sc, ProgramFragment *pf, uint32_t slot, Sampler *s) { CHECK_OBJ_OR_NULL(vs); CHECK_OBJ(vpf); - GET_TLS(); - rsi_ProgramBindSampler(rsc, - static_cast(vpf), - slot, - static_cast(vs)); + pf->bindSampler(rsc, slot, s); } -static void SC_bindProgramStore(RsProgramStore pfs) { - CHECK_OBJ_OR_NULL(pfs); - GET_TLS(); - rsi_ContextBindProgramStore(rsc, pfs); +void rsrBindProgramStore(Context *rsc, Script *sc, ProgramStore *ps) { + CHECK_OBJ_OR_NULL(ps); + rsc->setProgramStore(ps); } -static void SC_bindProgramFragment(RsProgramFragment pf) { +void rsrBindProgramFragment(Context *rsc, Script *sc, ProgramFragment *pf) { CHECK_OBJ_OR_NULL(pf); - GET_TLS(); - rsi_ContextBindProgramFragment(rsc, pf); + rsc->setProgramFragment(pf); } -static void SC_bindProgramVertex(RsProgramVertex pv) { +void rsrBindProgramVertex(Context *rsc, Script *sc, ProgramVertex *pv) { CHECK_OBJ_OR_NULL(pv); - GET_TLS(); - rsi_ContextBindProgramVertex(rsc, pv); + rsc->setProgramVertex(pv); } -static void SC_bindProgramRaster(RsProgramRaster pv) { - CHECK_OBJ_OR_NULL(pv); - GET_TLS(); - rsi_ContextBindProgramRaster(rsc, pv); +void rsrBindProgramRaster(Context *rsc, Script *sc, ProgramRaster *pr) { + CHECK_OBJ_OR_NULL(pr); + rsc->setProgramRaster(pr); } -static void SC_bindFrameBufferObjectColorTarget(RsAllocation va, uint32_t slot) { +void rsrBindFrameBufferObjectColorTarget(Context *rsc, Script *sc, Allocation *a, uint32_t slot) { CHECK_OBJ(va); - GET_TLS(); - rsc->mFBOCache.bindColorTarget(rsc, static_cast(va), slot); + rsc->mFBOCache.bindColorTarget(rsc, a, slot); } -static void SC_bindFrameBufferObjectDepthTarget(RsAllocation va) { +void rsrBindFrameBufferObjectDepthTarget(Context *rsc, Script *sc, Allocation *a) { CHECK_OBJ(va); - GET_TLS(); - rsc->mFBOCache.bindDepthTarget(rsc, static_cast(va)); + rsc->mFBOCache.bindDepthTarget(rsc, a); } -static void SC_clearFrameBufferObjectColorTarget(uint32_t slot) { - GET_TLS(); +void rsrClearFrameBufferObjectColorTarget(Context *rsc, Script *sc, uint32_t slot) { rsc->mFBOCache.bindColorTarget(rsc, NULL, slot); } -static void SC_clearFrameBufferObjectDepthTarget() { - GET_TLS(); +void rsrClearFrameBufferObjectDepthTarget(Context *rsc, Script *sc) { rsc->mFBOCache.bindDepthTarget(rsc, NULL); } -static void SC_clearFrameBufferObjectTargets() { - GET_TLS(); +void rsrClearFrameBufferObjectTargets(Context *rsc, Script *sc) { rsc->mFBOCache.resetAll(rsc); } @@ -117,30 +99,25 @@ static void SC_clearFrameBufferObjectTargets() { // VP ////////////////////////////////////////////////////////////////////////////// -static void SC_vpLoadProjectionMatrix(const rsc_Matrix *m) { - GET_TLS(); +void rsrVpLoadProjectionMatrix(Context *rsc, Script *sc, const rsc_Matrix *m) { rsc->getProgramVertex()->setProjectionMatrix(rsc, m); } -static void SC_vpLoadModelMatrix(const rsc_Matrix *m) { - GET_TLS(); +void rsrVpLoadModelMatrix(Context *rsc, Script *sc, const rsc_Matrix *m) { rsc->getProgramVertex()->setModelviewMatrix(rsc, m); } -static void SC_vpLoadTextureMatrix(const rsc_Matrix *m) { - GET_TLS(); +void rsrVpLoadTextureMatrix(Context *rsc, Script *sc, const rsc_Matrix *m) { rsc->getProgramVertex()->setTextureMatrix(rsc, m); } -static void SC_pfConstantColor(RsProgramFragment vpf, float r, float g, float b, float a) { - GET_TLS(); - CHECK_OBJ(vpf); - ProgramFragment *pf = static_cast(vpf); +void rsrPfConstantColor(Context *rsc, Script *sc, ProgramFragment *pf, + float r, float g, float b, float a) { + CHECK_OBJ(pf); pf->setConstantColor(rsc, r, g, b, a); } -static void SC_vpGetProjectionMatrix(rsc_Matrix *m) { - GET_TLS(); +void rsrVpGetProjectionMatrix(Context *rsc, Script *sc, rsc_Matrix *m) { rsc->getProgramVertex()->getProjectionMatrix(rsc, m); } @@ -148,15 +125,11 @@ static void SC_vpGetProjectionMatrix(rsc_Matrix *m) { // Drawing ////////////////////////////////////////////////////////////////////////////// -static void SC_drawQuadTexCoords(float x1, float y1, float z1, - float u1, float v1, - float x2, float y2, float z2, - float u2, float v2, - float x3, float y3, float z3, - float u3, float v3, - float x4, float y4, float z4, - float u4, float v4) { - GET_TLS(); +void rsrDrawQuadTexCoords(Context *rsc, Script *sc, + float x1, float y1, float z1, float u1, float v1, + float x2, float y2, float z2, float u2, float v2, + float x3, float y3, float z3, float u3, float v3, + float x4, float y4, float z4, float u4, float v4) { if (!rsc->setupCheck()) { return; } @@ -180,18 +153,19 @@ static void SC_drawQuadTexCoords(float x1, float y1, float z1, glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } -static void SC_drawQuad(float x1, float y1, float z1, - float x2, float y2, float z2, - float x3, float y3, float z3, - float x4, float y4, float z4) { - SC_drawQuadTexCoords(x1, y1, z1, 0, 1, - x2, y2, z2, 1, 1, - x3, y3, z3, 1, 0, - x4, y4, z4, 0, 0); +void rsrDrawQuad(Context *rsc, Script *sc, + float x1, float y1, float z1, + float x2, float y2, float z2, + float x3, float y3, float z3, + float x4, float y4, float z4) { + rsrDrawQuadTexCoords(rsc, sc, x1, y1, z1, 0, 1, + x2, y2, z2, 1, 1, + x3, y3, z3, 1, 0, + x4, y4, z4, 0, 0); } -static void SC_drawSpriteScreenspace(float x, float y, float z, float w, float h) { - GET_TLS(); +void rsrDrawSpriteScreenspace(Context *rsc, Script *sc, + float x, float y, float z, float w, float h) { ObjectBaseRef tmp(rsc->getProgramVertex()); rsc->setProgramVertex(rsc->getDefaultProgramVertex()); //rsc->setupCheck(); @@ -200,87 +174,48 @@ static void SC_drawSpriteScreenspace(float x, float y, float z, float w, float h float sh = rsc->getHeight(); - SC_drawQuad(x, sh - y, z, + rsrDrawQuad(rsc, sc, + x, sh - y, z, x+w, sh - y, z, x+w, sh - (y+h), z, x, sh - (y+h), z); rsc->setProgramVertex((ProgramVertex *)tmp.get()); } -/* -static void SC_drawSprite(float x, float y, float z, float w, float h) -{ - GET_TLS(); - float vin[3] = {x, y, z}; - float vout[4]; - - //LOGE("ds in %f %f %f", x, y, z); - rsc->getVertex()->transformToScreen(rsc, vout, vin); - //LOGE("ds out %f %f %f %f", vout[0], vout[1], vout[2], vout[3]); - vout[0] /= vout[3]; - vout[1] /= vout[3]; - vout[2] /= vout[3]; - - vout[0] *= rsc->getWidth() / 2; - vout[1] *= rsc->getHeight() / 2; - vout[0] += rsc->getWidth() / 2; - vout[1] += rsc->getHeight() / 2; - - vout[0] -= w/2; - vout[1] -= h/2; - - //LOGE("ds out2 %f %f %f", vout[0], vout[1], vout[2]); - - // U, V, W, H - SC_drawSpriteScreenspace(vout[0], vout[1], z, h, w); - //rsc->setupCheck(); -} -*/ -static void SC_drawRect(float x1, float y1, - float x2, float y2, float z) { +void rsrDrawRect(Context *rsc, Script *sc, float x1, float y1, float x2, float y2, float z) { //LOGE("SC_drawRect %f,%f %f,%f %f", x1, y1, x2, y2, z); - SC_drawQuad(x1, y2, z, - x2, y2, z, - x2, y1, z, - x1, y1, z); + rsrDrawQuad(rsc, sc, x1, y2, z, x2, y2, z, x2, y1, z, x1, y1, z); } -static void SC_drawMesh(RsMesh vsm) { - CHECK_OBJ(vsm); - GET_TLS(); - Mesh *sm = static_cast(vsm); +void rsrDrawMesh(Context *rsc, Script *sc, Mesh *sm) { + CHECK_OBJ(sm); if (!rsc->setupCheck()) { return; } sm->render(rsc); } -static void SC_drawMeshPrimitive(RsMesh vsm, uint32_t primIndex) { - CHECK_OBJ(vsm); - GET_TLS(); - Mesh *sm = static_cast(vsm); +void rsrDrawMeshPrimitive(Context *rsc, Script *sc, Mesh *sm, uint32_t primIndex) { + CHECK_OBJ(sm); if (!rsc->setupCheck()) { return; } sm->renderPrimitive(rsc, primIndex); } -static void SC_drawMeshPrimitiveRange(RsMesh vsm, uint32_t primIndex, uint32_t start, uint32_t len) { - CHECK_OBJ(vsm); - GET_TLS(); - Mesh *sm = static_cast(vsm); +void rsrDrawMeshPrimitiveRange(Context *rsc, Script *sc, Mesh *sm, uint32_t primIndex, + uint32_t start, uint32_t len) { + CHECK_OBJ(sm); if (!rsc->setupCheck()) { return; } sm->renderPrimitiveRange(rsc, primIndex, start, len); } -static void SC_meshComputeBoundingBox(RsMesh vsm, - float *minX, float *minY, float *minZ, - float *maxX, float *maxY, float *maxZ) { - CHECK_OBJ(vsm); - GET_TLS(); - Mesh *sm = static_cast(vsm); +void rsrMeshComputeBoundingBox(Context *rsc, Script *sc, Mesh *sm, + float *minX, float *minY, float *minZ, + float *maxX, float *maxY, float *maxZ) { + CHECK_OBJ(sm); sm->computeBBox(); *minX = sm->mBBoxMin[0]; *minY = sm->mBBoxMin[1]; @@ -296,32 +231,17 @@ static void SC_meshComputeBoundingBox(RsMesh vsm, ////////////////////////////////////////////////////////////////////////////// -static void SC_color(float r, float g, float b, float a) { - GET_TLS(); - ProgramFragment *pf = (ProgramFragment *)rsc->getProgramFragment(); +void rsrColor(Context *rsc, Script *sc, float r, float g, float b, float a) { + ProgramFragment *pf = rsc->getProgramFragment(); pf->setConstantColor(rsc, r, g, b, a); } -static void SC_finish() { +void rsrFinish(Context *rsc, Script *sc) { glFinish(); } -static void SC_allocationSyncAll(RsAllocation va) { - CHECK_OBJ(va); - GET_TLS(); - static_cast(va)->syncAll(rsc, RS_ALLOCATION_USAGE_SCRIPT); -} - -#if 0 -static void SC_allocationSyncAll2(RsAllocation va, RsAllocationUsageType source) { - CHECK_OBJ(va); - GET_TLS(); - static_cast(va)->syncAll(rsc, source); -} -#endif -static void SC_ClearColor(float r, float g, float b, float a) { - GET_TLS(); +void rsrClearColor(Context *rsc, Script *sc, float r, float g, float b, float a) { rsc->mFBOCache.setupGL2(rsc); rsc->setupProgramStore(); @@ -329,8 +249,7 @@ static void SC_ClearColor(float r, float g, float b, float a) { glClear(GL_COLOR_BUFFER_BIT); } -static void SC_ClearDepth(float v) { - GET_TLS(); +void rsrClearDepth(Context *rsc, Script *sc, float v) { rsc->mFBOCache.setupGL2(rsc); rsc->setupProgramStore(); @@ -338,34 +257,27 @@ static void SC_ClearDepth(float v) { glClear(GL_DEPTH_BUFFER_BIT); } -static uint32_t SC_getWidth() { - GET_TLS(); +uint32_t rsrGetWidth(Context *rsc, Script *sc) { return rsc->getWidth(); } -static uint32_t SC_getHeight() { - GET_TLS(); +uint32_t rsrGetHeight(Context *rsc, Script *sc) { return rsc->getHeight(); } -static void SC_DrawTextAlloc(RsAllocation va, int x, int y) { - CHECK_OBJ(va); - GET_TLS(); - Allocation *alloc = static_cast(va); - const char *text = (const char *)alloc->getPtr(); - size_t allocSize = alloc->getType()->getSizeBytes(); +void rsrDrawTextAlloc(Context *rsc, Script *sc, Allocation *a, int x, int y) { + const char *text = (const char *)a->getPtr(); + size_t allocSize = a->getType()->getSizeBytes(); rsc->mStateFont.renderText(text, allocSize, x, y); } -static void SC_DrawText(const char *text, int x, int y) { - GET_TLS(); +void rsrDrawText(Context *rsc, Script *sc, const char *text, int x, int y) { size_t textLen = strlen(text); rsc->mStateFont.renderText(text, textLen, x, y); } -static void SC_setMetrics(Font::Rect *metrics, - int32_t *left, int32_t *right, - int32_t *top, int32_t *bottom) { +static void SetMetrics(Font::Rect *metrics, + int32_t *left, int32_t *right, int32_t *top, int32_t *bottom) { if (left) { *left = metrics->left; } @@ -380,125 +292,32 @@ static void SC_setMetrics(Font::Rect *metrics, } } -static void SC_MeasureTextAlloc(RsAllocation va, - int32_t *left, int32_t *right, - int32_t *top, int32_t *bottom) { - CHECK_OBJ(va); - GET_TLS(); - Allocation *alloc = static_cast(va); - const char *text = (const char *)alloc->getPtr(); - size_t textLen = alloc->getType()->getSizeBytes(); +void rsrMeasureTextAlloc(Context *rsc, Script *sc, Allocation *a, + int32_t *left, int32_t *right, int32_t *top, int32_t *bottom) { + CHECK_OBJ(a); + const char *text = (const char *)a->getPtr(); + size_t textLen = a->getType()->getSizeBytes(); Font::Rect metrics; rsc->mStateFont.measureText(text, textLen, &metrics); - SC_setMetrics(&metrics, left, right, top, bottom); + SetMetrics(&metrics, left, right, top, bottom); } -static void SC_MeasureText(const char *text, - int32_t *left, int32_t *right, - int32_t *top, int32_t *bottom) { - GET_TLS(); +void rsrMeasureText(Context *rsc, Script *sc, const char *text, + int32_t *left, int32_t *right, int32_t *top, int32_t *bottom) { size_t textLen = strlen(text); Font::Rect metrics; rsc->mStateFont.measureText(text, textLen, &metrics); - SC_setMetrics(&metrics, left, right, top, bottom); + SetMetrics(&metrics, left, right, top, bottom); } -static void SC_BindFont(RsFont font) { +void rsrBindFont(Context *rsc, Script *sc, Font *font) { CHECK_OBJ(font); - GET_TLS(); rsi_ContextBindFont(rsc, font); } -static void SC_FontColor(float r, float g, float b, float a) { - GET_TLS(); +void rsrFontColor(Context *rsc, Script *sc, float r, float g, float b, float a) { rsc->mStateFont.setFontColor(r, g, b, a); } -////////////////////////////////////////////////////////////////////////////// -// Class implementation -////////////////////////////////////////////////////////////////////////////// - -// llvm name mangling ref -// ::= v # void -// ::= b # bool -// ::= c # char -// ::= a # signed char -// ::= h # unsigned char -// ::= s # short -// ::= t # unsigned short -// ::= i # int -// ::= j # unsigned int -// ::= l # long -// ::= m # unsigned long -// ::= x # long long, __int64 -// ::= y # unsigned long long, __int64 -// ::= f # float -// ::= d # double - -static ScriptCState::SymbolTable_t gSyms[] = { - { "_Z22rsgBindProgramFragment19rs_program_fragment", (void *)&SC_bindProgramFragment, false }, - { "_Z19rsgBindProgramStore16rs_program_store", (void *)&SC_bindProgramStore, false }, - { "_Z20rsgBindProgramVertex17rs_program_vertex", (void *)&SC_bindProgramVertex, false }, - { "_Z20rsgBindProgramRaster17rs_program_raster", (void *)&SC_bindProgramRaster, false }, - { "_Z14rsgBindSampler19rs_program_fragmentj10rs_sampler", (void *)&SC_bindSampler, false }, - { "_Z14rsgBindTexture19rs_program_fragmentj13rs_allocation", (void *)&SC_bindTexture, false }, - - { "_Z36rsgProgramVertexLoadProjectionMatrixPK12rs_matrix4x4", (void *)&SC_vpLoadProjectionMatrix, false }, - { "_Z31rsgProgramVertexLoadModelMatrixPK12rs_matrix4x4", (void *)&SC_vpLoadModelMatrix, false }, - { "_Z33rsgProgramVertexLoadTextureMatrixPK12rs_matrix4x4", (void *)&SC_vpLoadTextureMatrix, false }, - - { "_Z35rsgProgramVertexGetProjectionMatrixP12rs_matrix4x4", (void *)&SC_vpGetProjectionMatrix, false }, - - { "_Z31rsgProgramFragmentConstantColor19rs_program_fragmentffff", (void *)&SC_pfConstantColor, false }, - - { "_Z11rsgGetWidthv", (void *)&SC_getWidth, false }, - { "_Z12rsgGetHeightv", (void *)&SC_getHeight, false }, - - { "_Z20rsgAllocationSyncAll13rs_allocation", (void *)&SC_allocationSyncAll, false }, - - { "_Z11rsgDrawRectfffff", (void *)&SC_drawRect, false }, - { "_Z11rsgDrawQuadffffffffffff", (void *)&SC_drawQuad, false }, - { "_Z20rsgDrawQuadTexCoordsffffffffffffffffffff", (void *)&SC_drawQuadTexCoords, false }, - { "_Z24rsgDrawSpriteScreenspacefffff", (void *)&SC_drawSpriteScreenspace, false }, - - { "_Z11rsgDrawMesh7rs_mesh", (void *)&SC_drawMesh, false }, - { "_Z11rsgDrawMesh7rs_meshj", (void *)&SC_drawMeshPrimitive, false }, - { "_Z11rsgDrawMesh7rs_meshjjj", (void *)&SC_drawMeshPrimitiveRange, false }, - { "_Z25rsgMeshComputeBoundingBox7rs_meshPfS0_S0_S0_S0_S0_", (void *)&SC_meshComputeBoundingBox, false }, - - { "_Z13rsgClearColorffff", (void *)&SC_ClearColor, false }, - { "_Z13rsgClearDepthf", (void *)&SC_ClearDepth, false }, - - { "_Z11rsgDrawTextPKcii", (void *)&SC_DrawText, false }, - { "_Z11rsgDrawText13rs_allocationii", (void *)&SC_DrawTextAlloc, false }, - { "_Z14rsgMeasureTextPKcPiS1_S1_S1_", (void *)&SC_MeasureText, false }, - { "_Z14rsgMeasureText13rs_allocationPiS0_S0_S0_", (void *)&SC_MeasureTextAlloc, false }, - - { "_Z11rsgBindFont7rs_font", (void *)&SC_BindFont, false }, - { "_Z12rsgFontColorffff", (void *)&SC_FontColor, false }, - - { "_Z18rsgBindColorTarget13rs_allocationj", (void *)&SC_bindFrameBufferObjectColorTarget, false }, - { "_Z18rsgBindDepthTarget13rs_allocation", (void *)&SC_bindFrameBufferObjectDepthTarget, false }, - { "_Z19rsgClearColorTargetj", (void *)&SC_clearFrameBufferObjectColorTarget, false }, - { "_Z19rsgClearDepthTargetv", (void *)&SC_clearFrameBufferObjectDepthTarget, false }, - { "_Z24rsgClearAllRenderTargetsv", (void *)&SC_clearFrameBufferObjectTargets, false }, - - // misc - { "_Z5colorffff", (void *)&SC_color, false }, - { "_Z9rsgFinishv", (void *)&SC_finish, false }, - - { NULL, NULL, false } -}; - -const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbolGL(const char *sym) { - ScriptCState::SymbolTable_t *syms = gSyms; - - while (syms->mPtr) { - if (!strcmp(syms->mName, sym)) { - return syms; - } - syms++; - } - return NULL; } - +} -- cgit v1.2.3