summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Li <davidxli@google.com>2011-04-01 12:36:39 -0700
committerDavid Li <davidxli@google.com>2011-04-01 12:37:29 -0700
commitd1e2ad94efa128450a3ea93a11c72bc6e4a749ba (patch)
tree230f193365bb00f7e414dd97242c97862eb64c93
parentf9de39d5647571bea3e5ee126538c3458962bc04 (diff)
Fix build problems for Mac.
strnlen not available on Mac OS X. Fix worker thread synchronization. Change-Id: I774ecb9f39753a9da35073a0121af0fd2cdecd01 Signed-off-by: David Li <davidxli@google.com>
-rw-r--r--Android.mk5
-rw-r--r--src/pixelflinger2/pixelflinger2.cpp24
-rw-r--r--src/pixelflinger2/pixelflinger2.h35
-rw-r--r--src/pixelflinger2/raster.cpp97
-rw-r--r--src/pixelflinger2/shader.cpp2
-rw-r--r--src/talloc/hieralloc.c9
-rw-r--r--test/Android.mk9
7 files changed, 109 insertions, 72 deletions
diff --git a/Android.mk b/Android.mk
index 01044e3..6dd3223 100644
--- a/Android.mk
+++ b/Android.mk
@@ -149,9 +149,8 @@ endif
LOCAL_C_INCLUDES := $(libMesa_C_INCLUDES)
-# libMesa only builds on Linux host for now
-#include $(LLVM_ROOT_PATH)/llvm-host-build.mk
-#include $(BUILD_HOST_STATIC_LIBRARY)
+include $(LLVM_ROOT_PATH)/llvm-host-build.mk
+include $(BUILD_HOST_STATIC_LIBRARY)
# Static library for target
diff --git a/src/pixelflinger2/pixelflinger2.cpp b/src/pixelflinger2/pixelflinger2.cpp
index c5ee3a6..9c41ca9 100644
--- a/src/pixelflinger2/pixelflinger2.cpp
+++ b/src/pixelflinger2/pixelflinger2.cpp
@@ -185,6 +185,9 @@ static void EnableDisable(GGLInterface * iface, GLenum cap, GLboolean enable)
void InitializeGGLState(GGLInterface * iface)
{
+#if USE_DUAL_THREAD
+ reinterpret_cast<GGLContext *>(iface)->worker = GGLContext::Worker();
+#endif
iface->DepthRangef = DepthRangef;
iface->Viewport = Viewport;
iface->CullFace = CullFace;
@@ -220,7 +223,7 @@ void InitializeGGLState(GGLInterface * iface)
for (unsigned i = 0; i < GGL_MAXCOMBINEDTEXTUREIMAGEUNITS; i++)
iface->SetSampler(iface, i, NULL);
-
+
iface->SetBuffer(iface, GL_COLOR_BUFFER_BIT, NULL);
iface->SetBuffer(iface, GL_DEPTH_BUFFER_BIT, NULL);
iface->SetBuffer(iface, GL_STENCIL_BUFFER_BIT, NULL);
@@ -230,12 +233,10 @@ void InitializeGGLState(GGLInterface * iface)
GGLInterface * CreateGGLInterface()
{
- //GGLContext * ctx = (GGLContext *)calloc(1, sizeof(GGLContext) + sizeof(__GLcontextRec));
- GGLContext * ctx = (GGLContext *)calloc(1, sizeof(GGLContext));
+ GGLContext * const ctx = (GGLContext *)calloc(1, sizeof(GGLContext));
if (!ctx)
return NULL;
assert((void *)ctx == (void *)&ctx->interface);
- //ctx->glCtx = (GLcontext *)((char *)ctx + sizeof(GGLContext));
//_glapi_set_context(ctx->glCtx);
//_mesa_init_constants(&Const);
@@ -247,19 +248,11 @@ GGLInterface * CreateGGLInterface()
void UninitializeGGLState(GGLInterface * iface)
{
- GGLContext * ctx = (GGLContext *)iface;
- assert((void *)ctx == (void *)iface);
-
#if USE_DUAL_THREAD
- ctx->worker.hasWork = false;
- ctx->worker.quit = true;
- pthread_mutex_lock(&ctx->worker.lock);
- pthread_cond_signal(&ctx->worker.cond);
- pthread_mutex_unlock(&ctx->worker.lock);
+ reinterpret_cast<GGLContext *>(iface)->worker.~Worker();
#endif
-
DestroyShaderFunctions(iface);
-
+
#if USE_LLVM_TEXTURE_SAMPLER
puts("USE_LLVM_TEXTURE_SAMPLER");
#endif
@@ -277,8 +270,7 @@ void UninitializeGGLState(GGLInterface * iface)
void DestroyGGLInterface(GGLInterface * iface)
{
- GGLContext * ctx = (GGLContext *)iface;
- assert((void *)ctx == (void *)iface);
+ GGLContext * const ctx = reinterpret_cast<GGLContext *>(iface);
UninitializeGGLState(iface);
free(ctx);
}
diff --git a/src/pixelflinger2/pixelflinger2.h b/src/pixelflinger2/pixelflinger2.h
index bd77a2e..f42bc78 100644
--- a/src/pixelflinger2/pixelflinger2.h
+++ b/src/pixelflinger2/pixelflinger2.h
@@ -108,14 +108,41 @@ struct GGLContext {
unsigned startY, endY, varyingCount;
VertexOutput bV, cV, bDx, cDx;
int width, height;
- volatile bool hasWork;
+ bool assignedWork; // only used by main; worker uses assignCond & quit
bool quit;
- pthread_cond_t cond;
- pthread_mutex_t lock;
+ pthread_cond_t assignCond;
+ pthread_mutex_t assignLock; // held by worker execpt for during cond_wait assign
+ pthread_cond_t finishCond;
+ pthread_mutex_t finishLock; // held by main except for during cond_wait finish
pthread_t thread;
- Worker() : cond(PTHREAD_COND_INITIALIZER), lock(PTHREAD_MUTEX_INITIALIZER), thread(NULL) {}
+ Worker() : assignedWork(false), quit(false), thread(0)
+ {
+ pthread_cond_init(&assignCond, NULL);
+ pthread_cond_init(&finishCond, NULL);
+ pthread_mutex_init(&assignLock, NULL);
+ pthread_mutex_init(&finishLock, NULL);
+ pthread_mutex_lock(&finishLock);
+ // actual thread is created later in raster.cpp
+ }
+ ~Worker()
+ {
+ if (0 != thread)
+ {
+ pthread_mutex_lock(&assignLock);
+ quit = true;
+ pthread_cond_signal(&assignCond); // signal thread to quit
+ pthread_mutex_unlock(&assignLock);
+ pthread_join(thread, NULL);
+ }
+ pthread_mutex_unlock(&finishLock);
+
+ pthread_cond_destroy(&assignCond);
+ pthread_cond_destroy(&finishCond);
+ pthread_mutex_destroy(&assignLock);
+ pthread_mutex_destroy(&finishLock);
+ }
} worker;
#endif
diff --git a/src/pixelflinger2/raster.cpp b/src/pixelflinger2/raster.cpp
index bd69f59..07cdc0e 100644
--- a/src/pixelflinger2/raster.cpp
+++ b/src/pixelflinger2/raster.cpp
@@ -91,16 +91,21 @@ static void * RasterTrapezoidWorker(void * threadArgs)
{
GGLContext::Worker * args = (GGLContext::Worker *)threadArgs;
VertexOutput clip0, clip1, * left, * right;
- while (!args->quit) {
- pthread_mutex_lock(&args->lock);
- while (!args->hasWork && !args->quit)
- pthread_cond_wait(&args->cond, &args->lock);
- pthread_mutex_unlock(&args->lock);
-
+
+ pthread_mutex_lock(&args->finishLock);
+ pthread_mutex_lock(&args->assignLock);
+ pthread_cond_signal(&args->finishCond);
+ pthread_mutex_unlock(&args->finishLock);
+
+ while (true) {
+ pthread_cond_wait(&args->assignCond, &args->assignLock);
if (args->quit)
+ {
+ pthread_mutex_unlock(&args->assignLock);
break;
-// if (!args->hasWork)
-// continue;
+ }
+ else
+ assert(args->assignedWork);
for (unsigned y = args->startY; y <= args->endY; y += 2) {
do {
@@ -133,7 +138,10 @@ static void * RasterTrapezoidWorker(void * threadArgs)
args->bV.frontFacingPointCoord += args->bDx.frontFacingPointCoord;
args->cV.frontFacingPointCoord += args->cDx.frontFacingPointCoord;
}
- args->hasWork = false;
+
+ pthread_mutex_lock(&args->finishLock);
+ pthread_cond_signal(&args->finishCond);
+ pthread_mutex_unlock(&args->finishLock);
}
pthread_exit(NULL);
return NULL;
@@ -159,6 +167,7 @@ static void RasterTrapezoid(const GGLInterface * iface, const VertexOutput * tl,
VertexOutput tmp;
// vertically clip
+
if ((int)tlv.position.y < 0) {
InterpolateVertex(&tlv, &blv, (0 - tlv.position.y) / (blv.position.y - tlv.position.y),
&tmp, varyingCount);
@@ -240,38 +249,45 @@ static void RasterTrapezoid(const GGLInterface * iface, const VertexOutput * tl,
#if USE_DUAL_THREAD
GGLContext::Worker & args = ctx->worker;
if (!ctx->worker.thread) {
- int rc = pthread_create(&ctx->worker.thread, NULL, RasterTrapezoidWorker, &args);
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+ int rc = pthread_create(&ctx->worker.thread, &attr, RasterTrapezoidWorker, &args);
assert(!rc);
+ // wait for worker to start
+ pthread_cond_wait(&args.finishCond, &args.finishLock);
}
- args.bV = bV;
- args.cV = cV;
- for (unsigned i = 0; i < varyingCount; i++) {
- args.bV.varyings[i] += bDx.varyings[i];
- bDx.varyings[i] += bDx.varyings[i];
- args.cV.varyings[i] += cDx.varyings[i];
- cDx.varyings[i] += cDx.varyings[i];
- }
- args.bV.position += bDx.position;
- bDx.position += bDx.position;
- args.cV.position += cDx.position;
- cDx.position += cDx.position;
- args.bV.frontFacingPointCoord += bDx.frontFacingPointCoord;
- bDx.frontFacingPointCoord += bDx.frontFacingPointCoord;
- args.cV.frontFacingPointCoord += cDx.frontFacingPointCoord;
- cDx.frontFacingPointCoord += cDx.frontFacingPointCoord;
- args.iface = iface;
- args.bDx = bDx;
- args.cDx = cDx;
- args.varyingCount = varyingCount;
args.startY = startY + 1;
args.endY = endY;
- args.width = width;
- args.height = height;
if (args.startY <= args.endY) {
- pthread_mutex_lock(&args.lock);
- args.hasWork = true;
- pthread_cond_signal(&args.cond);
- pthread_mutex_unlock(&args.lock);
+ pthread_mutex_lock(&args.assignLock);
+
+ args.bV = bV;
+ args.cV = cV;
+ for (unsigned i = 0; i < varyingCount; i++) {
+ args.bV.varyings[i] += bDx.varyings[i];
+ bDx.varyings[i] += bDx.varyings[i];
+ args.cV.varyings[i] += cDx.varyings[i];
+ cDx.varyings[i] += cDx.varyings[i];
+ }
+ args.bV.position += bDx.position;
+ bDx.position += bDx.position;
+ args.cV.position += cDx.position;
+ cDx.position += cDx.position;
+ args.bV.frontFacingPointCoord += bDx.frontFacingPointCoord;
+ bDx.frontFacingPointCoord += bDx.frontFacingPointCoord;
+ args.cV.frontFacingPointCoord += cDx.frontFacingPointCoord;
+ cDx.frontFacingPointCoord += cDx.frontFacingPointCoord;
+ args.iface = iface;
+ args.bDx = bDx;
+ args.cDx = cDx;
+ args.varyingCount = varyingCount;
+ args.width = width;
+ args.height = height;
+ args.assignedWork = true;
+
+ pthread_cond_signal(&args.assignCond);
+ pthread_mutex_unlock(&args.assignLock);
}
#endif
@@ -309,8 +325,11 @@ static void RasterTrapezoid(const GGLInterface * iface, const VertexOutput * tl,
}
#if USE_DUAL_THREAD
- while (args.hasWork)
- ; // wait
+ if (args.assignedWork)
+ {
+ pthread_cond_wait(&args.finishCond, &args.finishLock);
+ args.assignedWork = false;
+ }
#endif
}
@@ -373,8 +392,6 @@ static void DrawTriangle(const GGLInterface * iface, const VertexInput * vin1,
// LOGD("pf2: DrawTriangle");
- const gl_shader_program * program = ctx->CurrentProgram;
-
// if (!strstr(program->Shaders[MESA_SHADER_FRAGMENT]->Source,
// "gl_FragColor = color * texture2D(sampler, outTexCoords).a;"))
// return;
diff --git a/src/pixelflinger2/shader.cpp b/src/pixelflinger2/shader.cpp
index 5cca627..ed1da57 100644
--- a/src/pixelflinger2/shader.cpp
+++ b/src/pixelflinger2/shader.cpp
@@ -336,7 +336,7 @@ static void GetShaderKeyString(const GLenum type, const ShaderKey * key,
*str++ = '\0';
}
-static const unsigned SCANLINE_KEY_STRING_LEN = 2 * sizeof(ShaderKey::scanLineKey) + 3 + SHADER_KEY_STRING_LEN;
+static const unsigned SCANLINE_KEY_STRING_LEN = 2 * sizeof(ShaderKey::ScanLineKey) + 3 + SHADER_KEY_STRING_LEN;
static char * GetScanlineKeyString(const ShaderKey * key, char * buffer,
const unsigned bufferSize)
diff --git a/src/talloc/hieralloc.c b/src/talloc/hieralloc.c
index 48b8179..ba6e6f7 100644
--- a/src/talloc/hieralloc.c
+++ b/src/talloc/hieralloc.c
@@ -339,8 +339,9 @@ char * hieralloc_strndup(const void * ctx, const char * str, unsigned len)
if (!str)
return NULL;
- len = strnlen(str, len);
- char * ret = (char *)hieralloc_allocate(ctx, len + 1, str);
+ const char *p = (const char *)memchr(str, '\0', len);
+ len = (p ? p - str : len);
+ char * ret = (char *)hieralloc_allocate(ctx, len + 1, str);
if (!ret)
return NULL;
memcpy(ret, str, len);
@@ -389,7 +390,9 @@ char * hieralloc_strndup_append(char * str, const char * append, unsigned len)
return hieralloc_strdup(NULL, append);
if (!append)
return str;
- return _hieralloc_strlendup_append(str, strlen(str), append, strnlen(append, len));
+ const char *p = (const char *)memchr(append, '\0', len);
+ len = (p ? p - append : len);
+ return _hieralloc_strlendup_append(str, strlen(str), append, len);
}
// allocate and vsprintf
diff --git a/test/Android.mk b/test/Android.mk
index 68df587..bf6728f 100644
--- a/test/Android.mk
+++ b/test/Android.mk
@@ -22,7 +22,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
ifeq ($(DEBUG_BUILD),true)
-LOCAL_CFLAGS += -DDEBUG -UNDEBUG -O0 -g
+LOCAL_CFLAGS += -DDEBUG -UNDEBUG -O0 -g
endif
LOCAL_MODULE := mesa
@@ -31,9 +31,8 @@ LOCAL_STATIC_LIBRARIES := libMesa
LOCAL_SHARED_LIBRARIES := libbcc
LOCAL_C_INCLUDES := $(mesa_C_INCLUDES)
-# libMesa only builds on Linux host for now
-#include $(LLVM_ROOT_PATH)/llvm-host-build.mk
-#include $(BUILD_HOST_EXECUTABLE)
+include $(LLVM_ROOT_PATH)/llvm-host-build.mk
+include $(BUILD_HOST_EXECUTABLE)
# Executable for target
# ========================================================
@@ -42,7 +41,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
ifeq ($(DEBUG_BUILD),true)
-LOCAL_CFLAGS += -DDEBUG -UNDEBUG -O0 -g
+LOCAL_CFLAGS += -DDEBUG -UNDEBUG -O0 -g
endif
LOCAL_MODULE := mesa