Skip to content

Commit

Permalink
Revert "Migrate to use new libbcc APIs."
Browse files Browse the repository at this point in the history
This reverts commit 187673e.
  • Loading branch information
stephenhines committed May 3, 2012
1 parent 187673e commit 45d57d9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 72 deletions.
6 changes: 3 additions & 3 deletions src/pixelflinger2/pixelflinger2.h
Expand Up @@ -62,9 +62,9 @@
# define MAX2(a, b) ((a) > (b) ? (a) : (b))
#endif

namespace bcc
namespace llvm
{
class BCCContext;
class LLVMContext;
};

#if !USE_LLVM_SCANLINE
Expand All @@ -88,7 +88,7 @@ struct GGLContext {
GGLSurface depthSurface;
GGLSurface stencilSurface;

bcc::BCCContext * bccCtx;
llvm::LLVMContext * llvmCtx;

struct {
int depth; // assuming ieee 754 32 bit float and 32 bit 2's complement int; z_32
Expand Down
102 changes: 33 additions & 69 deletions src/pixelflinger2/shader.cpp
Expand Up @@ -22,18 +22,9 @@

#include <llvm/LLVMContext.h>
#include <llvm/Module.h>
#include <llvm/Support/raw_ostream.h>
#include <bcc/bcc.h>
#include <dlfcn.h>

#include <bcc/BCCContext.h>
#include <bcc/Compiler.h>
#include <bcc/ExecutionEngine/ObjectLoader.h>
#include <bcc/ExecutionEngine/SymbolResolvers.h>
#include <bcc/Script.h>
#include <bcc/Source.h>
#include <bcc/Support/Initialization.h>
#include <bcc/Support/TargetCompilerConfigs.h>


#include "src/talloc/hieralloc.h"
#include "src/mesa/main/shaderobj.h"
Expand Down Expand Up @@ -116,13 +107,15 @@ struct ShaderKey {
};

struct Instance {
bcc::Script * script;
llvm::SmallVector<char, 1024> resultObj;
bcc::ObjectLoader * exec;
llvm::Module * module;
struct BCCOpaqueScript * script;
void (* function)();
~Instance() {
delete script;
delete exec;
// TODO: check bccDisposeScript, which seems to dispose llvm::Module
if (script)
bccDisposeScript(script);
else if (module)
delete module;
}
};

Expand Down Expand Up @@ -393,45 +386,31 @@ static void* SymbolLookup(void* pContext, const char* name)
static void CodeGen(Instance * instance, const char * mainName, gl_shader * shader,
gl_shader_program * program, const GGLState * gglCtx)
{
bcc::Compiler compiler;
bcc::Compiler::ErrorCode compile_result;
llvm::raw_svector_ostream out(instance->resultObj);

// instance->module->dump();

compile_result = compiler.config(bcc::DefaultCompilerConfig());
if (compile_result != bcc::Compiler::kSuccess) {
ALOGD("failed config compiler (%s)", bcc::Compiler::GetErrorString(compile_result));
assert(0);
return;
}

compiler.enableLTO(/* pEnable */false); // Disable LTO passes execution.

compile_result = compiler.compile(*instance->script, out);
if (compile_result != bcc::Compiler::kSuccess) {
ALOGD("failed to compile (%s)", bcc::Compiler::GetErrorString(compile_result));
assert(0);
return;
}

SymbolLookupContext ctx = {gglCtx, program, shader};
bcc::LookupFunctionSymbolResolver<void*> resolver(SymbolLookup, &ctx);
int result = 0;

instance->exec = bcc::ObjectLoader::Load(instance->resultObj.begin(), instance->resultObj.size(),
/* pName */"glsl", resolver, /* pEnableGDBDebug */false);
// instance->module->dump();

if (!instance->exec) {
ALOGD("failed to load the result object");
BCCScriptRef & script = instance->script;
script = bccCreateScript();
result = bccReadModule(script, "glsl", (LLVMModuleRef)instance->module, 0);
assert(0 == result);
result = bccRegisterSymbolCallback(script, SymbolLookup, &ctx);
assert(0 == result);
result = bccPrepareExecutable(script, NULL, NULL, 0);

result = bccGetError(script);
if (result != 0) {
ALOGD("failed bcc_compile");
assert(0);
return;
}

instance->function = reinterpret_cast<void (*)()>(instance->exec->getSymbolAddress(mainName));
instance->function = (void (*)())bccGetFuncAddr(script, mainName);
assert(instance->function);
if (!instance->function) {
ALOGD("Could not find '%s'\n", mainName);
}
result = bccGetError(script);
if (result != BCC_NO_ERROR)
ALOGD("Could not find '%s': %d\n", mainName, result);
// else
// printf("bcc_compile %s=%p \n", mainName, instance->function);

Expand All @@ -441,7 +420,7 @@ static void CodeGen(Instance * instance, const char * mainName, gl_shader * shad
void GenerateScanLine(const GGLState * gglCtx, const gl_shader_program * program, llvm::Module * mod,
const char * shaderName, const char * scanlineName);

void GGLShaderUse(void * bccCtx, const GGLState * gglState, gl_shader_program * program)
void GGLShaderUse(void * llvmCtx, const GGLState * gglState, gl_shader_program * program)
{
// ALOGD("%s", program->Shaders[MESA_SHADER_FRAGMENT]->Source);
for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {
Expand All @@ -457,12 +436,10 @@ void GGLShaderUse(void * bccCtx, const GGLState * gglState, gl_shader_program *
ShaderKey shaderKey;
GetShaderKey(gglState, shader, &shaderKey);
Instance * instance = shader->executable->instances[shaderKey];
bcc::BCCContext * compilerCtx = reinterpret_cast<bcc::BCCContext *>(bccCtx);
if (!instance) {
// puts("begin jit new shader");
instance = hieralloc_zero(shader->executable, Instance);

llvm::Module * module = new llvm::Module("glsl", compilerCtx->getLLVMContext());
instance->module = new llvm::Module("glsl", *(llvm::LLVMContext *)llvmCtx);

char shaderName [SHADER_KEY_STRING_LEN] = {0};
GetShaderKeyString(shader->Type, &shaderKey, shaderName, sizeof shaderName / sizeof *shaderName);
Expand Down Expand Up @@ -491,20 +468,9 @@ void GGLShaderUse(void * bccCtx, const GGLState * gglState, gl_shader_program *
// }
// fclose(file);
//#endif
if (!glsl_ir_to_llvm_module(shader->ir, module, gglState, shaderName)) {
assert(0);
delete module;
}
bcc::Source * source = bcc::Source::CreateFromModule(*compilerCtx, *module);
if (!source) {
delete module;
llvm::Module * module = glsl_ir_to_llvm_module(shader->ir, instance->module, gglState, shaderName);
if (!module)
assert(0);
}
instance->script = new bcc::Script(*source);
if (!instance->script) {
delete source;
assert(0);
}
//#ifdef __arm__
// static const char fileName[] = "/data/pf2.txt";
// FILE * file = freopen(fileName, "w", stderr);
Expand Down Expand Up @@ -581,7 +547,7 @@ static void ShaderUse(GGLInterface * iface, gl_shader_program * program)
return;
}

GGLShaderUse(ctx->bccCtx, &ctx->state, program);
GGLShaderUse(ctx->llvmCtx, &ctx->state, program);
for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {
if (!program->_LinkedShaders[i])
continue;
Expand Down Expand Up @@ -967,9 +933,7 @@ void SetShaderVerifyFunctions(struct GGLInterface * iface)
void InitializeShaderFunctions(struct GGLInterface * iface)
{
GGL_GET_CONTEXT(ctx, iface);
bcc::init::Initialize();

ctx->bccCtx = new bcc::BCCContext();
ctx->llvmCtx = new llvm::LLVMContext();

iface->ShaderCreate = ShaderCreate;
iface->ShaderSource = GGLShaderSource;
Expand Down Expand Up @@ -1001,6 +965,6 @@ void DestroyShaderFunctions(GGLInterface * iface)
GGL_GET_CONTEXT(ctx, iface);
_mesa_glsl_release_types();
_mesa_glsl_release_functions();
delete ctx->bccCtx;
ctx->bccCtx = NULL;
delete ctx->llvmCtx;
ctx->llvmCtx = NULL;
}

0 comments on commit 45d57d9

Please sign in to comment.