summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Li <davidxli@google.com>2011-02-04 17:18:24 -0800
committerDavid Li <davidxli@google.com>2011-02-04 17:18:24 -0800
commit470970d77c095678830fc512dfe0e97c6bcab15b (patch)
treeeda62767b2ed614b89e3ad5819c47532d614b461
parentf9ad8a790398513a845d486f58566854f7eceee4 (diff)
Checkpoint: shader execution uses data pointers
Signed-off-by: David Li <davidxli@google.com>
-rw-r--r--include/pixelflinger2/pixelflinger2_interface.h51
-rw-r--r--src/glsl/ir_to_llvm.cpp153
-rw-r--r--src/pixelflinger2/llvm_scanline.cpp15
-rw-r--r--src/pixelflinger2/pixelflinger2.cpp7
-rw-r--r--src/pixelflinger2/pixelflinger2.h57
-rw-r--r--src/pixelflinger2/raster.cpp11
-rw-r--r--src/pixelflinger2/scanline.cpp35
-rw-r--r--src/pixelflinger2/shader.cpp29
-rw-r--r--test/main.cpp14
9 files changed, 239 insertions, 133 deletions
diff --git a/include/pixelflinger2/pixelflinger2_interface.h b/include/pixelflinger2/pixelflinger2_interface.h
index 4a23ce2..1be41c5 100644
--- a/include/pixelflinger2/pixelflinger2_interface.h
+++ b/include/pixelflinger2/pixelflinger2_interface.h
@@ -84,6 +84,57 @@ unsigned magFilter :
1; // GL_NEAREST = 0, GL_LINEAR
} GGLTexture_t;
+typedef struct GGLStencilState {
+ unsigned char ref, mask; // ref is masked during StencilFuncSeparate
+
+ // GL_NEVER = 0, GL_LESS, GL_EQUAL, GL_LEQUAL, GL_GREATER, GL_NOTEQUAL, GL_GEQUAL,
+ // GL_ALWAYS; value = GLenum & 0x7 (GLenum is 0x200-0x207)
+ unsigned char func; // compare function
+
+ // GL_ZERO = 0, GL_KEEP = 1, GL_REPLACE, GL_INCR, GL_DECR, GL_INVERT, GL_INCR_WRAP,
+ // GL_DECR_WRAP = 7; value = 0 | GLenum - GL_KEEP | GL_INVERT | GLenum - GL_INCR_WRAP
+ unsigned char sFail, dFail, dPass; // operations
+} StencilState_t;
+
+typedef struct GGLActiveStencilState { // do not change layout, used in GenerateScanLine
+ unsigned char face; // FRONT = 0, BACK = 1
+ unsigned char ref, mask;
+} ActiveStencilState_t;
+
+typedef struct GGLBufferState { // all affect scanline jit
+unsigned stencilTest :
+ 1;
+unsigned depthTest :
+ 1;
+ // same as sf/bFunc; GL_NEVER = 0, GL_LESS, GL_EQUAL, GL_LEQUAL, GL_GREATER, GL_NOTEQUAL,
+ // GL_GEQUAL, GL_ALWAYS = 7; value = GLenum & 0x7 (GLenum is 0x200-0x207)
+unsigned depthFunc :
+ 3;
+} BufferState_t;
+
+typedef struct GGLBlendState { // all values affect scanline jit
+ unsigned char color[4]; // rgba[0,255]
+
+unsigned scf :
+4, saf :
+4, dcf :
+4, daf :
+ 4; // GL_ZERO = 0, GL_ONE, GL_SRC_COLOR = 2,
+ // GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
+ // GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
+ // GL_SRC_ALPHA_SATURATE, GL_CONSTANT_COLOR = 11, GL_ONE_MINUS_CONSTANT_COLOR,
+ // GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA;
+ // value = 0,1 | GLenum - GL_SRC_COLOR + 2 | GLenum - GL_CONSTANT_COLOR + 11
+
+unsigned ce :
+3, ae :
+ 3; // GL_FUNC_ADD = 0, GL_FUNC_SUBTRACT = 4,
+ // GL_FUNC_REVERSE_SUBTRACT = 5; value = GLenum - GL_FUNC_ADD
+
+unsigned enable :
+ 1;
+} BlendState_t;
+
// most functions are according to GL ES 2.0 spec and uses GLenum values
// there is some error checking for invalid GLenum
typedef struct GGLInterface GGLInterface_t;
diff --git a/src/glsl/ir_to_llvm.cpp b/src/glsl/ir_to_llvm.cpp
index bb0c515..b0dd036 100644
--- a/src/glsl/ir_to_llvm.cpp
+++ b/src/glsl/ir_to_llvm.cpp
@@ -86,11 +86,28 @@ public:
const GGLContext * gglCtx;
const char * shaderSuffix;
+ llvm::Value * inputsPtr, * outputsPtr, * constantsPtr; // internal globals to store inputs/outputs/constants pointers
+ llvm::Value * inputs, * outputs, * constants;
ir_to_llvm_visitor(llvm::Module* p_mod, const GGLContext * GGLCtx, const char * suffix)
: ctx(p_mod->getContext()), mod(p_mod), fun(0), loop(std::make_pair((llvm::BasicBlock*)0,
- (llvm::BasicBlock*)0)), bb(0), bld(ctx), gglCtx(GGLCtx), shaderSuffix(suffix)
+ (llvm::BasicBlock*)0)), bb(0), bld(ctx), gglCtx(GGLCtx), shaderSuffix(suffix),
+ inputsPtr(NULL), outputsPtr(NULL), constantsPtr(NULL),
+ inputs(NULL), outputs(NULL), constants(NULL)
{
+ const llvm::PointerType * const floatVecPtrType = llvm::PointerType::get(llvm::VectorType::get(bld.getFloatTy(),4), 0);
+ llvm::Constant * const nullFloatVecPtr = llvm::Constant::getNullValue(floatVecPtrType);
+ // make input, output and consts global pointers so they can be used in
+ // different LLVM functions since the shader shares these "registers" across "functions"
+
+ inputsPtr = new llvm::GlobalVariable(*mod, floatVecPtrType, false,
+ llvm::GlobalValue::InternalLinkage, nullFloatVecPtr, "gl_inputPtr");
+
+ outputsPtr = new llvm::GlobalVariable(*mod, floatVecPtrType, false,
+ llvm::GlobalValue::InternalLinkage, nullFloatVecPtr, "gl_outputsPtr");
+
+ constantsPtr = new llvm::GlobalVariable(*mod, floatVecPtrType, false,
+ llvm::GlobalValue::InternalLinkage, nullFloatVecPtr, "gl_constantsPtr");
}
const llvm::Type* llvm_base_type(unsigned base_type)
@@ -156,33 +173,76 @@ public:
{
const llvm::Type* type = llvm_type(var->type);
- llvm::Value* v;
+ llvm::Value* v = NULL;
if(fun)
{
- if(bb == &fun->getEntryBlock())
- v = bld.CreateAlloca(type, 0, var->name);
+ if (ir_var_in == var->mode)
+ {
+ assert(var->location >= 0);
+ v = bld.CreateConstGEP1_32(inputs, var->location);
+ v = bld.CreateBitCast(v, llvm::PointerType::get(llvm_type(var->type), 0), var->name);
+ }
+ else if (ir_var_out == var->mode)
+ {
+ assert(var->location >= 0);
+ v = bld.CreateConstGEP1_32(outputs, var->location);
+ v = bld.CreateBitCast(v, llvm::PointerType::get(llvm_type(var->type), 0), var->name);
+ }
+ else if (ir_var_uniform == var->mode)
+ {
+ assert(var->location >= 0);
+ v = bld.CreateConstGEP1_32(constants, var->location);
+ v = bld.CreateBitCast(v, llvm::PointerType::get(llvm_type(var->type), 0), var->name);
+ }
else
- v = new llvm::AllocaInst(type, 0, var->name, fun->getEntryBlock().getTerminator());
+ {
+ if(bb == &fun->getEntryBlock())
+ v = bld.CreateAlloca(type, 0, var->name);
+ else
+ v = new llvm::AllocaInst(type, 0, var->name, fun->getEntryBlock().getTerminator());
+ }
}
else // TODO: can anything global be non-constant in GLSL?; fix linkage
{
- llvm::Function::LinkageTypes linkage;
- if(var->mode == ir_var_auto || var->mode == ir_var_temporary)
- linkage = llvm::GlobalValue::InternalLinkage;
- else
- linkage = llvm::GlobalValue::ExternalLinkage;
- llvm::Constant* init = 0;
- if(var->constant_value)
+ //printf("var '%s' mode=%d location=%d \n", var->name, var->mode, var->location);
+ switch(var->mode)
{
- init = llvm_constant(var->constant_value);
- // this constants need to be external (ie. written to output)
- if (llvm::GlobalValue::ExternalLinkage == linkage)
- linkage = llvm::GlobalValue::AvailableExternallyLinkage;
+ case ir_var_auto: // fall through
+ case ir_var_temporary:
+ {
+ llvm::Constant * init = llvm::UndefValue::get(llvm_type(var->type));
+ if(var->constant_value)
+ init = llvm_constant(var->constant_value);
+ v = new llvm::GlobalVariable(*mod, type, var->read_only, llvm::GlobalValue::InternalLinkage, init, var->name);
+ break;
+ }
+ case ir_var_in: // fall through
+ case ir_var_out: // fall through
+ case ir_var_uniform: // fall through
+ assert(var->location >= 0);
+ return NULL; // variable outside of function means declaration
+ default:
+ assert(0);
}
- else if(linkage == llvm::GlobalValue::InternalLinkage)
- init = llvm::UndefValue::get(llvm_type(var->type));
- v = new llvm::GlobalVariable(*mod, type, var->read_only, linkage, init, var->name);
+
+// llvm::Function::LinkageTypes linkage;
+// if(var->mode == ir_var_auto || var->mode == ir_var_temporary)
+// linkage = llvm::GlobalValue::InternalLinkage;
+// else
+// linkage = llvm::GlobalValue::ExternalLinkage;
+// llvm::Constant* init = 0;
+// if(var->constant_value)
+// {
+// init = llvm_constant(var->constant_value);
+// // this constants need to be external (ie. written to output)
+// if (llvm::GlobalValue::ExternalLinkage == linkage)
+// linkage = llvm::GlobalValue::AvailableExternallyLinkage;
+// }
+// else if(linkage == llvm::GlobalValue::InternalLinkage)
+// init = llvm::UndefValue::get(llvm_type(var->type));
+// v = new llvm::GlobalVariable(*mod, type, var->read_only, linkage, init, var->name);
}
+ assert(v);
llvm_variables[var] = v;
return v;
}
@@ -207,16 +267,23 @@ public:
else
{
llvm::Function::LinkageTypes linkage;
- if(!strcmp(name, "main") || !sig->is_defined)
- linkage = llvm::Function::ExternalLinkage;
- else
- linkage = llvm::Function::InternalLinkage;
std::vector<const llvm::Type*> params;
foreach_iter(exec_list_iterator, iter, sig->parameters) {
ir_variable* arg = (ir_variable*)iter.get();
params.push_back(llvm_type(arg->type));
}
-
+
+ if(!strcmp(name, "main") || !sig->is_defined)
+ {
+ linkage = llvm::Function::ExternalLinkage;
+ llvm::PointerType * vecPtrTy = llvm::PointerType::get(llvm::VectorType::get(bld.getFloatTy(), 4), 0);
+ assert(0 == params.size());
+ params.push_back(vecPtrTy); // inputs
+ params.push_back(vecPtrTy); // outputs
+ params.push_back(vecPtrTy); // constants
+ }
+ else
+ linkage = llvm::Function::InternalLinkage;
llvm::FunctionType* ft = llvm::FunctionType::get(llvm_type(sig->return_type), params, false);
function = llvm::Function::Create(ft, linkage, functionName, mod);
free(functionName);
@@ -826,7 +893,7 @@ public:
virtual void visit(class ir_dereference_variable *ir)
{
- result = bld.CreateLoad(llvm_pointer(ir));
+ result = bld.CreateLoad(llvm_pointer(ir), ir->variable_referenced()->name);
}
virtual void visit(class ir_texture * ir)
@@ -1235,12 +1302,36 @@ public:
bld.SetInsertPoint(bb);
llvm::Function::arg_iterator ai = fun->arg_begin();
- foreach_iter(exec_list_iterator, iter, sig->parameters) {
- ir_variable* arg = (ir_variable*)iter.get();
- ai->setName(arg->name);
- bld.CreateStore(ai, llvm_variable(arg));
- ++ai;
+ if (!strcmp("main",sig->function_name()))
+ {
+ assert(3 == fun->arg_size());
+ bld.CreateStore(ai, inputsPtr);
+ inputs = ai;
+ ai++;
+ bld.CreateStore(ai, outputsPtr);
+ outputs = ai;
+ ai++;
+ bld.CreateStore(ai, constantsPtr);
+ constants = ai;
+ ai++;
}
+ else
+ {
+ foreach_iter(exec_list_iterator, iter, sig->parameters) {
+ ir_variable* arg = (ir_variable*)iter.get();
+ ai->setName(arg->name);
+ bld.CreateStore(ai, llvm_variable(arg));
+ ++ai;
+ }
+ inputs = bld.CreateLoad(inputsPtr);
+ outputs = bld.CreateLoad(outputsPtr);
+ constants = bld.CreateLoad(constantsPtr);
+ }
+ inputs->setName("gl_inputs");
+ outputs->setName("gl_outputs");
+ constants->setName("gl_constants");
+
+
foreach_iter(exec_list_iterator, iter, sig->body) {
ir_instruction *ir = (ir_instruction *)iter.get();
@@ -1278,6 +1369,8 @@ glsl_ir_to_llvm_module(struct exec_list *ir, llvm::Module * mod,
// mod->dump();
if(llvm::verifyModule(*mod, llvm::PrintMessageAction, 0))
{
+ puts("**\n module verification failed **\n");
+ mod->dump();
assert(0);
return NULL;
}
diff --git a/src/pixelflinger2/llvm_scanline.cpp b/src/pixelflinger2/llvm_scanline.cpp
index 461f8a8..5bb6732 100644
--- a/src/pixelflinger2/llvm_scanline.cpp
+++ b/src/pixelflinger2/llvm_scanline.cpp
@@ -384,6 +384,7 @@ static FunctionType * ScanLineFunctionType(IRBuilder<> & builder)
funcArgs.push_back(vectorPtr); // start
funcArgs.push_back(vectorPtr); // step
+ funcArgs.push_back(vectorPtr); // constants
funcArgs.push_back(intPointerType); // frame
funcArgs.push_back(intPointerType); // depth
funcArgs.push_back(bytePointerType); // stencil
@@ -399,7 +400,7 @@ static FunctionType * ScanLineFunctionType(IRBuilder<> & builder)
// generated scanline function parameters are VertexOutput * start, VertexOutput * step,
// unsigned * frame, int * depth, unsigned char * stencil,
-// ActiveStencilState * stencilState, unsigned count
+// GGLActiveStencilState * stencilState, unsigned count
void GenerateScanLine(const GGLContext * gglCtx, const gl_shader_program * program, Module * mod,
const char * shaderName, const char * scanlineName)
{
@@ -427,6 +428,8 @@ void GenerateScanLine(const GGLContext * gglCtx, const gl_shader_program * progr
start->setName("start");
Value * step = args++;
step->setName("step");
+ Value * constants = args++;
+ constants->setName("constants");
// need alloc to be able to assign to it by using store
Value * framePtr = builder.CreateAlloca(intPointerType);
@@ -567,14 +570,18 @@ void GenerateScanLine(const GGLContext * gglCtx, const gl_shader_program * progr
condBranch.ifCond(sCmp, "if_sCmp", "sCmp_fail");
condBranch.ifCond(zCmp, "if_zCmp", "zCmp_fail");
- Value * fsInputs = builder.CreateConstInBoundsGEP1_32(start,
- offsetof(VertexOutput,position)/sizeof(Vector4));
+// Value * fsInputs = builder.CreateConstInBoundsGEP1_32(start,
+// offsetof(VertexOutput,position)/sizeof(Vector4));
+ Value * inputs = start;
+ Value * outputs = inputs;
+
Value * fsOutputs = builder.CreateConstInBoundsGEP1_32(start,
offsetof(VertexOutput,fragColor)/sizeof(Vector4));
Function * fsFunction = mod->getFunction(shaderName);
assert(fsFunction);
- CallInst *call = builder.CreateCall(fsFunction);
+// CallInst *call = builder.CreateCall(fsFunction);
+ CallInst *call = builder.CreateCall3(fsFunction,inputs, outputs, constants);
call->setCallingConv(CallingConv::C);
call->setTailCall(false);
diff --git a/src/pixelflinger2/pixelflinger2.cpp b/src/pixelflinger2/pixelflinger2.cpp
index 0845d23..b33825a 100644
--- a/src/pixelflinger2/pixelflinger2.cpp
+++ b/src/pixelflinger2/pixelflinger2.cpp
@@ -65,17 +65,10 @@ static void FrontFace(GGLInterface * iface, GLenum mode)
static void BlendColor(GGLInterface * iface, GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
{
GGL_GET_CONTEXT(ctx, iface);
-#if USE_LLVM_SCANLINE
ctx->blendState.color[0] = MIN2(MAX2(red * 255, 0.0f), 255.0f);
ctx->blendState.color[1] = MIN2(MAX2(green * 255, 0.0f), 255.0f);
ctx->blendState.color[2] = MIN2(MAX2(blue * 255, 0.0f), 255.0f);
ctx->blendState.color[3] = MIN2(MAX2(alpha * 255, 0.0f), 255.0f);
-#else
- ctx->blendState.color.r = MIN2(MAX2(red * 255, 0), 255);
- ctx->blendState.color.g = MIN2(MAX2(green * 255, 0), 255);
- ctx->blendState.color.b = MIN2(MAX2(blue * 255, 0), 255);
- ctx->blendState.color.a = MIN2(MAX2(alpha * 255, 0), 255);
-#endif
SetShaderVerifyFunctions(iface);
}
diff --git a/src/pixelflinger2/pixelflinger2.h b/src/pixelflinger2/pixelflinger2.h
index 8f8a4d5..3e5f4da 100644
--- a/src/pixelflinger2/pixelflinger2.h
+++ b/src/pixelflinger2/pixelflinger2.h
@@ -47,6 +47,8 @@ class LLVMContext;
typedef int BlendComp_t;
#endif
+typedef void (*ShaderFunction_t)(const void*,void*,const void*);
+
#define GGL_GET_CONTEXT(context, interface) GGLContext * context = (GGLContext *)interface;
#define GGL_GET_CONST_CONTEXT(context, interface) const GGLContext * context = \
(const GGLContext *)interface; (void)context;
@@ -67,60 +69,13 @@ struct GGLContext {
unsigned stencil; // s_8; repeated to clear 4 pixels at a time
} clearState;
- struct StencilState {
- unsigned char ref, mask; // ref is masked during StencilFuncSeparate
+ GGLStencilState frontStencil, backStencil; // all affect scanline jit
- // GL_NEVER = 0, GL_LESS, GL_EQUAL, GL_LEQUAL, GL_GREATER, GL_NOTEQUAL, GL_GEQUAL,
- // GL_ALWAYS; value = GLenum & 0x7 (GLenum is 0x200-0x207)
- unsigned char func; // compare function
+ mutable GGLActiveStencilState activeStencil; // after primitive assembly, call StencilSelect
- // GL_ZERO = 0, GL_KEEP = 1, GL_REPLACE, GL_INCR, GL_DECR, GL_INVERT, GL_INCR_WRAP,
- // GL_DECR_WRAP = 7; value = 0 | GLenum - GL_KEEP | GL_INVERT | GLenum - GL_INCR_WRAP
- unsigned char sFail, dFail, dPass; // operations
- } frontStencil, backStencil; // all affect scanline jit
+ GGLBufferState bufferState; // all affect scanline jit
- mutable struct ActiveStencilState { // do not change layout, used in GenerateScanLine
- unsigned char face; // FRONT = 0, BACK = 1
- unsigned char ref, mask;
- } activeStencil; // after primitive assembly, call StencilSelect
-
- struct BufferState { // all affect scanline jit
-unsigned stencilTest :
- 1;
-unsigned depthTest :
- 1;
- // same as sf/bFunc; GL_NEVER = 0, GL_LESS, GL_EQUAL, GL_LEQUAL, GL_GREATER, GL_NOTEQUAL,
- // GL_GEQUAL, GL_ALWAYS = 7; value = GLenum & 0x7 (GLenum is 0x200-0x207)
-unsigned depthFunc :
- 3;
- } bufferState;
-
- struct BlendState { // all values affect scanline jit
-#if USE_LLVM_SCANLINE
- unsigned char color[4]; // rgba[0,255]
-#else
- Vec4<BlendComp_t> color;
-#endif
-
-unsigned scf :
-4, saf :
-4, dcf :
-4, daf :
- 4; // GL_ZERO = 0, GL_ONE, GL_SRC_COLOR = 2,
- // GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
- // GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
- // GL_SRC_ALPHA_SATURATE, GL_CONSTANT_COLOR = 11, GL_ONE_MINUS_CONSTANT_COLOR,
- // GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA;
- // value = 0,1 | GLenum - GL_SRC_COLOR + 2 | GLenum - GL_CONSTANT_COLOR + 11
-
-unsigned ce :
-3, ae :
- 3; // GL_FUNC_ADD = 0, GL_FUNC_SUBTRACT = 4,
- // GL_FUNC_REVERSE_SUBTRACT = 5; value = GLenum - GL_FUNC_ADD
-
-unsigned enable :
- 1;
- } blendState;
+ GGLBlendState blendState; // all affect scanline jit
struct {
// format affects vs and fs jit
diff --git a/src/pixelflinger2/raster.cpp b/src/pixelflinger2/raster.cpp
index 3f05c9f..63d63b4 100644
--- a/src/pixelflinger2/raster.cpp
+++ b/src/pixelflinger2/raster.cpp
@@ -19,6 +19,7 @@
#include <assert.h>
#include <math.h>
#include <string.h>
+#include <stdio.h>
#include "pixelflinger2.h"
#include "src/mesa/main/mtypes.h"
@@ -62,9 +63,13 @@ static void ProcessVertex(const GGLInterface * iface, const VertexInput * input,
// textureGGLContext = ctx;
//#endif
//
- memcpy(ctx->glCtx->CurrentProgram->ValuesVertexInput, input, sizeof(*input));
- ctx->glCtx->CurrentProgram->_LinkedShaders[MESA_SHADER_VERTEX]->function();
- memcpy(output, ctx->glCtx->CurrentProgram->ValuesVertexOutput, sizeof(*output));
+
+// memcpy(ctx->glCtx->CurrentProgram->ValuesVertexInput, input, sizeof(*input));
+// ctx->glCtx->CurrentProgram->_LinkedShaders[MESA_SHADER_VERTEX]->function();
+// memcpy(output, ctx->glCtx->CurrentProgram->ValuesVertexOutput, sizeof(*output));
+
+ ShaderFunction_t function = (ShaderFunction_t)ctx->glCtx->CurrentProgram->_LinkedShaders[MESA_SHADER_VERTEX]->function;
+ function(input, output, ctx->glCtx->CurrentProgram->ValuesUniform);
// const Vector4 * constants = (Vector4 *)
// ctx->glCtx->Shader.CurrentProgram->VertexProgram->Parameters->ParameterValues;
// ctx->glCtx->Shader.CurrentProgram->GLVMVP->function(input, output, constants);
diff --git a/src/pixelflinger2/scanline.cpp b/src/pixelflinger2/scanline.cpp
index bcb8853..04a55d4 100644
--- a/src/pixelflinger2/scanline.cpp
+++ b/src/pixelflinger2/scanline.cpp
@@ -197,9 +197,10 @@ void ScanLine(const GGLInterface * iface, const VertexOutput * v1, const VertexO
+ y * ctx->frameSurface.width + startX;
const VectorComp_t div = VectorComp_t_CTR(1 / (float)(endX - startX));
- memcpy(ctx->glCtx->CurrentProgram->ValuesVertexOutput, v1, sizeof(*v1));
+ //memcpy(ctx->glCtx->CurrentProgram->ValuesVertexOutput, v1, sizeof(*v1));
// shader symbols are mapped to gl_shader_program_Values*
- VertexOutput & vertex(*(VertexOutput*)ctx->glCtx->CurrentProgram->ValuesVertexOutput);
+ //VertexOutput & vertex(*(VertexOutput*)ctx->glCtx->CurrentProgram->ValuesVertexOutput);
+ VertexOutput vertex(*v1);
VertexOutput vertexDx(*v2);
vertexDx.position -= v1->position;
@@ -236,14 +237,14 @@ void ScanLine(const GGLInterface * iface, const VertexOutput * v1, const VertexO
// TODO DXL consider inverting gl_FragCoord.y
#if USE_LLVM_SCANLINE
- typedef void (* ScanLineFunction_t)(VertexOutput * start, VertexOutput * step,
+ typedef void (* ScanLineFunction_t)(VertexOutput * start, VertexOutput * step, float (*constants)[4],
unsigned * frame, int * depth, unsigned char * stencil,
- GGLContext::ActiveStencilState *, unsigned count);
+ GGLActiveStencilState *, unsigned count);
ScanLineFunction_t scanLineFunction = (ScanLineFunction_t)
ctx->glCtx->CurrentProgram->_LinkedShaders[MESA_SHADER_FRAGMENT]->function;
if (endX >= startX) {
- scanLineFunction(&vertex, &vertexDx, frame, depth, stencil, &ctx->activeStencil, endX - startX + 1);
+ scanLineFunction(&vertex, &vertexDx, ctx->glCtx->CurrentProgram->ValuesUniform, frame, depth, stencil, &ctx->activeStencil, endX - startX + 1);
}
#else
@@ -335,9 +336,9 @@ void ScanLine(const GGLInterface * iface, const VertexOutput * v1, const VertexO
}
if (!DepthTest || zCmp) {
float * varying = (float *)ctx->glCtx->CurrentProgram->ValuesVertexOutput;
-
- assert((void *)&(vertex.varyings[0]) == &(varying[2 * 4]));
- ctx->glCtx->CurrentProgram->_LinkedShaders[MESA_SHADER_FRAGMENT]->function();
+ ShaderFunction_t function = (ShaderFunction_t)ctx->glCtx->CurrentProgram->_LinkedShaders[MESA_SHADER_FRAGMENT]->function;
+ function(&vertex, &vertex, ctx->glCtx->CurrentProgram->ValuesUniform);
+ //ctx->glCtx->CurrentProgram->_LinkedShaders[MESA_SHADER_FRAGMENT]->function();
if (BlendEnable) {
BlendComp_t sOne = 255, sZero = 0;
Vec4<BlendComp_t> one = sOne, zero = sZero;
@@ -365,21 +366,23 @@ void ScanLine(const GGLInterface * iface, const VertexOutput * v1, const VertexO
dst.a = (dc >>= 8) & 255;
Vec4<BlendComp_t> sf, df;
+ Vec4<BlendComp_t> blendStateColor(ctx->blendState.color[0], ctx->blendState.color[1],
+ ctx->blendState.color[2], ctx->blendState.color[3]);
BlendFactor(ctx->blendState.scf, sf, src, dst,
- ctx->blendState.color, one, zero, src.a, dst.a,
- ctx->blendState.color.a, sOne);
+ blendStateColor, one, zero, src.a, dst.a,
+ blendStateColor.a, sOne);
if (ctx->blendState.scf != ctx->blendState.saf)
BlendFactor(ctx->blendState.saf, sf.a, src.a, dst.a,
- ctx->blendState.color.a, sOne, sZero, src.a, dst.a,
- ctx->blendState.color.a, sOne);
+ blendStateColor.a, sOne, sZero, src.a, dst.a,
+ blendStateColor.a, sOne);
BlendFactor(ctx->blendState.dcf, df, src, dst,
- ctx->blendState.color, one, zero, src.a, dst.a,
- ctx->blendState.color.a, sOne);
+ blendStateColor, one, zero, src.a, dst.a,
+ blendStateColor.a, sOne);
if (ctx->blendState.dcf != ctx->blendState.daf)
BlendFactor(ctx->blendState.daf, df.a, src.a, dst.a,
- ctx->blendState.color.a, sOne, sZero, src.a, dst.a,
- ctx->blendState.color.a, sOne);
+ blendStateColor.a, sOne, sZero, src.a, dst.a,
+ blendStateColor.a, sOne);
Vec4<BlendComp_t> sfs(sf), dfs(df);
sfs.LShr(7);
diff --git a/src/pixelflinger2/shader.cpp b/src/pixelflinger2/shader.cpp
index 1e92f9e..6352326 100644
--- a/src/pixelflinger2/shader.cpp
+++ b/src/pixelflinger2/shader.cpp
@@ -35,9 +35,9 @@
struct ShaderKey {
struct ScanLineKey {
- GGLContext::StencilState frontStencil, backStencil;
- GGLContext::BufferState bufferState;
- GGLContext::BlendState blendState;
+ GGLStencilState frontStencil, backStencil;
+ GGLBufferState bufferState;
+ GGLBlendState blendState;
} scanLineKey;
GGLPixelFormat textureFormats[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS];
unsigned char textureParameters[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS]; // wrap and filter
@@ -203,6 +203,10 @@ static GLboolean ShaderProgramLink(const GGLInterface * iface, gl_shader_program
{
GGL_GET_CONST_CONTEXT(ctx, iface);
link_shaders(ctx->glCtx, program);
+ if (infoLog)
+ *infoLog = program->InfoLog;
+ if (!program->LinkStatus)
+ return program->LinkStatus;
for (unsigned i = 0; i < program->Attributes->NumParameters; i++) {
const gl_program_parameter & attribute = program->Attributes->Parameters[i];
printf("attribute '%s': location=%d slots=%d \n", attribute.Name, attribute.Location, attribute.Slots);
@@ -215,8 +219,6 @@ static GLboolean ShaderProgramLink(const GGLInterface * iface, gl_shader_program
const gl_uniform & uniform = program->Uniforms->Uniforms[i];
printf("uniform '%s': location=%d type=%s \n", uniform.Name, uniform.Pos, uniform.Type->name);
}
- if (infoLog)
- *infoLog = program->InfoLog;
return program->LinkStatus;
}
@@ -401,6 +403,7 @@ static void ShaderUse(GGLInterface * iface, gl_shader_program * program)
GetShaderKey(ctx, shader, &shaderKey);
Instance * instance = shader->executable->instances[shaderKey];
if (!instance) {
+ puts("begin jit new shader");
instance = hieralloc_zero(shader->executable, Instance);
instance->module = new llvm::Module("glsl", *ctx->llvmCtx);
@@ -414,7 +417,7 @@ static void ShaderUse(GGLInterface * iface, gl_shader_program * program)
llvm::Module * module = glsl_ir_to_llvm_module(shader->ir, instance->module, ctx, shaderName);
if (!module)
- assert(0); // ir to llvm failed
+ assert(0);
#if USE_LLVM_SCANLINE
if (GL_FRAGMENT_SHADER == shader->Type) {
char scanlineName [SCANLINE_KEY_STRING_LEN] = {0};
@@ -425,10 +428,10 @@ static void ShaderUse(GGLInterface * iface, gl_shader_program * program)
#endif
CodeGen(instance, mainName, shader, program, ctx);
shader->executable->instances[shaderKey] = instance;
- debug_printf("jit new shader '%s'(%p) \n", mainName, instance->function); //getchar();
+ debug_printf("jit new shader '%s'(%p) \n", mainName, instance->function);
} else
- debug_printf("use cached shader %p \n", instance->function);
-
+// debug_printf("use cached shader %p \n", instance->function);
+ ;
shader->function = instance->function;
@@ -493,7 +496,6 @@ static GLint ShaderVaryingLocation(const GGLInterface_t * iface, const gl_shader
static GLint ShaderUniformLocation(const GGLInterface * iface, const gl_shader_program * program,
const char * name)
{
- GGL_GET_CONST_CONTEXT(ctx, iface);
for (unsigned i = 0; i < program->Uniforms->NumUniforms; i++)
if (!strcmp(program->Uniforms->Uniforms[i].Name, name))
return program->Uniforms->Uniforms[i].Pos;
@@ -503,7 +505,6 @@ static GLint ShaderUniformLocation(const GGLInterface * iface, const gl_shader_p
static void ShaderUniformGetfv(const GGLInterface * iface, gl_shader_program * program,
GLint location, GLfloat * params)
{
- GGL_GET_CONST_CONTEXT(ctx, iface);
memcpy(params, program->ValuesUniform + location, sizeof(*program->ValuesUniform));
}
@@ -519,7 +520,6 @@ static GLint ShaderUniform(const GGLInterface * iface, gl_shader_program * progr
GLint location, GLsizei count, const GLvoid *values, GLenum type)
{
// TODO: sampler uniform
- GGL_GET_CONST_CONTEXT(ctx, iface);
if (!program)
{
gglError(GL_INVALID_OPERATION);
@@ -568,16 +568,15 @@ static void ShaderUniformMatrix(const GGLInterface * iface, gl_shader_program *
GLint cols, GLint rows, GLint location, GLsizei count,
GLboolean transpose, const GLfloat *values)
{
- GGL_GET_CONST_CONTEXT(ctx, iface);
if (location == -1)
return;
assert(cols == rows);
int start = location, slots = cols * count;
- if (start < 0 || start + slots > ctx->glCtx->CurrentProgram->Uniforms->Slots)
+ if (start < 0 || start + slots > program->Uniforms->Slots)
return gglError(GL_INVALID_OPERATION);
for (unsigned i = 0; i < slots; i++)
{
- float * column = ctx->glCtx->CurrentProgram->ValuesUniform[start + i];
+ float * column = program->ValuesUniform[start + i];
for (unsigned j = 0; j < rows; j++)
column[j] = *(values++);
}
diff --git a/test/main.cpp b/test/main.cpp
index 1011056..29bb665 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -8,7 +8,7 @@
#define DRAW_TO_SCREEN 1
-#define USE_16BPP_TEXTURE 0 // forces texture to load as 16bpp
+#define USE_16BPP_TEXTURE 0 // forces texture to load as 16bpp, define before image_file.h
#ifdef __arm__
#define PATH_PREFIX "/data/"
@@ -101,7 +101,7 @@ void test_scan()
SetupDrawingSurface(&width, &height, &bpp);
frameSurface.data = PresentDrawingSurface();
#else
- const unsigned width = 1280, height = 800;
+ const unsigned width = 640, height = 400;
frameSurface.data = (unsigned int *)malloc(width * height * 4);
#endif
@@ -262,7 +262,7 @@ void test_scan()
//ggl->ClearDepthf(ggl, pos.z + 0.0001f); // when there is no transform in vs
ggl->ClearDepthf(ggl, 1);
ggl->EnableDisable(ggl, GL_BLEND, false);
- //ggl->EnableDisable(ggl, GL_DEPTH_TEST, false);
+ ggl->EnableDisable(ggl, GL_DEPTH_TEST, true);
ggl->EnableDisable(ggl, GL_STENCIL_TEST, false);
@@ -278,12 +278,12 @@ void test_scan()
#endif
for (
#ifdef __arm__
- unsigned i = 0; i <= 100; i++
+ unsigned i = 0; i <= 360; i++
#else
- unsigned i = 0; i <= 1; i+= 1
+ unsigned i = 0; i <= 10; i+= 1
#endif
) {
-
+// printf("frame=%d \n", i);
ggl->Clear(ggl, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//ggl->Clear(ggl, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
@@ -304,7 +304,7 @@ void test_scan()
//_math_matrix_scale(&m0, 0.2, 0.2, 0.2);
//_math_matrix_translate(&m2, 1, 1, 1);
- _math_matrix_rotate(&m2, i, 1, 2, 3);
+ _math_matrix_rotate(&m2, i * 2, 1, 2, 3);
//_math_matrix_rotate(&m2, i, 0, 0, 1);
// matrix on the right is applied to vector first