diff options
author | David Li <davidxli@google.com> | 2011-02-07 15:47:12 -0800 |
---|---|---|
committer | David Li <davidxli@google.com> | 2011-02-07 15:47:12 -0800 |
commit | 2ac1cf8a62bcf080b70eaa7c0e4f57d4e8001685 (patch) | |
tree | 9b98f7c064f0bf013da46f115f876b2e3e00bc13 | |
parent | 0f34e4ed10959fe2a6fefcfbf8bd7b1b6716909d (diff) |
Checkpoint: factor out minimum context required for shader functionality
Signed-off-by: David Li <davidxli@google.com>
-rw-r--r-- | include/pixelflinger2/pixelflinger2_interface.h | 101 | ||||
-rw-r--r-- | src/glsl/ir_to_llvm.cpp | 12 | ||||
-rw-r--r-- | src/glsl/ir_to_llvm.h | 2 | ||||
-rw-r--r-- | src/glsl/ir_to_llvm_helper.cpp | 4 | ||||
-rw-r--r-- | src/glsl/linker.cpp | 8 | ||||
-rw-r--r-- | src/mesa/main/mtypes.h | 3 | ||||
-rw-r--r-- | src/pixelflinger2/buffer.cpp | 34 | ||||
-rw-r--r-- | src/pixelflinger2/llvm_scanline.cpp | 14 | ||||
-rw-r--r-- | src/pixelflinger2/pixelflinger2.cpp | 32 | ||||
-rw-r--r-- | src/pixelflinger2/pixelflinger2.h | 12 | ||||
-rw-r--r-- | src/pixelflinger2/raster.cpp | 14 | ||||
-rw-r--r-- | src/pixelflinger2/scanline.cpp | 678 | ||||
-rw-r--r-- | src/pixelflinger2/shader.cpp | 158 | ||||
-rw-r--r-- | src/pixelflinger2/texture.cpp | 28 | ||||
-rw-r--r-- | test/cmain.c | 14 | ||||
-rw-r--r-- | test/main.cpp | 24 |
16 files changed, 608 insertions, 530 deletions
diff --git a/include/pixelflinger2/pixelflinger2_interface.h b/include/pixelflinger2/pixelflinger2_interface.h index 0a2102c..3fa26b2 100644 --- a/include/pixelflinger2/pixelflinger2_interface.h +++ b/include/pixelflinger2/pixelflinger2_interface.h @@ -26,6 +26,7 @@ typedef struct gl_shader gl_shader_t; typedef struct gl_shader_program gl_shader_program_t; typedef struct gl_context gl_context_t; +typedef struct GGLContext GGLContext_t; typedef struct VertexInput { Vector4 attributes[GGL_MAXVERTEXATTRIBS]; // vert input @@ -85,15 +86,6 @@ unsigned magFilter : 1; // GL_NEAREST = 0, GL_LINEAR } GGLTexture_t; -typedef struct GGLTextureState { - // format affects vs and fs jit - GGLTexture_t textures[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS]; // the active samplers - // array of pointers to texture surface data synced to textures; used by LLVM generated texture sampler - void * textureData[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS]; - // array of texture dimensions synced to textures; by LLVM generated texture sampler - unsigned textureDimensions[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS * 2]; -} TextureState_t; - typedef struct GGLStencilState { unsigned char ref, mask; // ref is masked during StencilFuncSeparate @@ -106,10 +98,10 @@ typedef struct GGLStencilState { unsigned char sFail, dFail, dPass; // operations } GGLStencilState_t; -typedef struct GGLActiveStencilState { // do not change layout, used in GenerateScanLine +typedef struct GGLActiveStencil { // do not change layout, used in GenerateScanLine unsigned char face; // FRONT = 0, BACK = 1 unsigned char ref, mask; -} GGLActiveStencilState_t; +} GGLActiveStencil_t; typedef struct GGLBufferState { // all affect scanline jit unsigned stencilTest : @@ -143,7 +135,27 @@ unsigned ce : unsigned enable : 1; -} BlendState_t; +} GGLBlendState_t; + +typedef struct GGLTextureState { + // format affects vs and fs jit + GGLTexture_t textures[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS]; // the active samplers + // array of pointers to texture surface data synced to textures; used by LLVM generated texture sampler + void * textureData[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS]; + // array of texture dimensions synced to textures; by LLVM generated texture sampler + unsigned textureDimensions[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS * 2]; +} GGLTextureState_t; + +typedef struct GGLState { + GGLStencilState_t frontStencil, backStencil; // all affect scanline jit + + GGLBufferState_t bufferState; // all affect scanline jit + + GGLBlendState_t blendState; // all affect scanline jit + + GGLTextureState_t textureState; // most affect vs/fs jit + +} GGLState_t; // most functions are according to GL ES 2.0 spec and uses GLenum values // there is some error checking for invalid GLenum @@ -208,7 +220,7 @@ struct GGLInterface { // compiles a shader given glsl; returns GL_TRUE on success; glsl only used during call; use infoLog to retrieve status GLboolean (* ShaderCompile)(const GGLInterface_t * iface, gl_shader_t * shader, const char * glsl, const char ** infoLog); - + void (* ShaderDelete)(const GGLInterface_t * iface, gl_shader_t * shader); // creates empty program @@ -224,33 +236,33 @@ struct GGLInterface { GLboolean (* ShaderProgramLink)(const GGLInterface_t * iface, gl_shader_program_t * program, const char ** infoLog); // frees program - void (* ShaderProgramDelete)(const GGLInterface_t * iface, gl_shader_program_t * program); + void (* ShaderProgramDelete)(GGLInterface_t * iface, gl_shader_program_t * program); // LLVM JIT and set as active program void (* ShaderUse)(GGLInterface_t * iface, gl_shader_program_t * program); - + // bind attribute location before linking - void (* ShaderAttributeBind)(const GGLInterface_t * iface, const gl_shader_program_t * program, + void (* ShaderAttributeBind)(const gl_shader_program_t * program, GLuint index, const GLchar * name); - GLint (* ShaderAttributeLocation)(const GGLInterface_t * iface, const gl_shader_program_t * program, + GLint (* ShaderAttributeLocation)(const gl_shader_program_t * program, const char * name); // returns fragment input location and vertex output location for varying of linked program - GLint (* ShaderVaryingLocation)(const GGLInterface_t * iface, const gl_shader_program_t * program, + GLint (* ShaderVaryingLocation)(const gl_shader_program_t * program, const char * name, GLint * vertexOutputLocation); // gets uniform location for linked program - GLint (* ShaderUniformLocation)(const GGLInterface_t * iface, const gl_shader_program_t * program, + GLint (* ShaderUniformLocation)(const gl_shader_program_t * program, const char * name); - void (* ShaderUniformGetfv)(const GGLInterface_t * iface, gl_shader_program_t * program, + void (* ShaderUniformGetfv)(gl_shader_program_t * program, GLint location, GLfloat * params); - void (* ShaderUniformGetiv)(const GGLInterface_t * iface, gl_shader_program_t * program, + void (* ShaderUniformGetiv)(gl_shader_program_t * program, GLint location, GLint * params); // updates linked program uniform value by location; return >= 0 indicates sampler assigned - GLint (* ShaderUniform)(const GGLInterface_t * iface, gl_shader_program_t * program, + GLint (* ShaderUniform)(gl_shader_program_t * program, GLint location, GLsizei count, const GLvoid *values, GLenum type); // updates linked program uniform matrix value by location - void (* ShaderUniformMatrix)(const GGLInterface_t * iface, gl_shader_program_t * program, - GLint cols, GLint rows, GLint location, GLsizei count, + void (* ShaderUniformMatrix)(gl_shader_program_t * program, GLint cols, + GLint rows, GLint location, GLsizei count, GLboolean transpose, const GLfloat *values); }; @@ -262,13 +274,13 @@ extern "C" GGLInterface_t * CreateGGLInterface(); void DestroyGGLInterface(GGLInterface_t * interface); - + // creates empty shader gl_shader_t * GGLShaderCreate(GLenum type); - + // compiles a shader given glsl; returns GL_TRUE on success; glsl only used during call; use infoLog to retrieve status - GLboolean GGLShaderCompile(const struct gl_context * glCtx, gl_shader_t * shader, const char * glsl, const char ** infoLog); - + GLboolean GGLShaderCompile(const gl_context_t * glCtx, gl_shader_t * shader, const char * glsl, const char ** infoLog); + void GGLShaderDelete(gl_shader_t * shader); // creates empty program @@ -285,28 +297,33 @@ extern "C" // frees program void GGLShaderProgramDelete(gl_shader_program_t * program); - // LLVM JIT and set as active program - void GGLShaderUse(gl_shader_program_t * program); + // LLVM JIT and set as active program, also call after gglState change to re-JIT + void GGLShaderUse(const GGLContext_t * gglCtx /*nullable*/, void * llvmCtx, const GGLState_t * gglState, gl_shader_program_t * program); + // bind attribute location before linking void GGLShaderAttributeBind(const gl_shader_program_t * program, - GLuint index, const GLchar * name); + GLuint index, const GLchar * name); GLint GGLShaderAttributeLocation(const gl_shader_program_t * program, - const char * name); + const char * name); // returns fragment input location and vertex output location for varying of linked program GLint GGLShaderVaryingLocation(const gl_shader_program_t * program, - const char * name, GLint * vertexOutputLocation); + const char * name, GLint * vertexOutputLocation); // gets uniform location for linked program GLint GGLShaderUniformLocation(const gl_shader_program_t * program, - const char * name); - - void GGLProcessVertex(const VertexInput_t * inputs, - VertexOutput_t * outputs, const float (*constants[4])); - + const char * name); + + void GGLProcessVertex(const gl_shader_program_t * program, const VertexInput_t * input, + VertexOutput_t * output, const float (*constants)[4]); + // scan line given left and right processed and scizored vertices - void GGLScanLine(const VertexOutput_t * v1, const VertexOutput_t * v2); - - void GGLProcessFragment(const VertexOutput_t * inputs, VertexOutput_t * outputs, - const float (*constants[4])); + // depth value bitcast float->int, if negative then ^= 0x7fffffff + void GGLScanLine(const gl_shader_program_t * program, unsigned * frameBuffer, + int * depthBuffer, unsigned char * stencilBuffer, unsigned bufferWidth, + unsigned bufferHeight, GGLActiveStencil_t * activeStencil, const VertexOutput_t * start, + const VertexOutput_t * end, const float (*constants)[4]); + +// void GGLProcessFragment(const VertexOutput_t * inputs, VertexOutput_t * outputs, +// const float (*constants[4])); #ifdef __cplusplus } diff --git a/src/glsl/ir_to_llvm.cpp b/src/glsl/ir_to_llvm.cpp index b0dd036..0641569 100644 --- a/src/glsl/ir_to_llvm.cpp +++ b/src/glsl/ir_to_llvm.cpp @@ -63,12 +63,12 @@ using namespace tr1; #include "glsl_types.h" #include "src/mesa/main/mtypes.h" -struct GGLContext; +struct GGLState; llvm::Value * tex2D(llvm::IRBuilder<> & builder, llvm::Value * in1, const unsigned sampler, - const GGLContext * gglCtx); + const GGLState * gglCtx); llvm::Value * texCube(llvm::IRBuilder<> & builder, llvm::Value * in1, const unsigned sampler, - const GGLContext * gglCtx); + const GGLState * gglCtx); class ir_to_llvm_visitor : public ir_visitor { ir_to_llvm_visitor(); @@ -84,12 +84,12 @@ public: llvm::Value* result; llvm::IRBuilder<> bld; - const GGLContext * gglCtx; + const GGLState * 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) + ir_to_llvm_visitor(llvm::Module* p_mod, const GGLState * 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), inputsPtr(NULL), outputsPtr(NULL), constantsPtr(NULL), @@ -1360,7 +1360,7 @@ public: struct llvm::Module * glsl_ir_to_llvm_module(struct exec_list *ir, llvm::Module * mod, - const struct GGLContext * gglCtx, const char * shaderSuffix) + const struct GGLState * gglCtx, const char * shaderSuffix) { ir_to_llvm_visitor v(mod, gglCtx, shaderSuffix); diff --git a/src/glsl/ir_to_llvm.h b/src/glsl/ir_to_llvm.h index 5a3cc44..63f5c83 100644 --- a/src/glsl/ir_to_llvm.h +++ b/src/glsl/ir_to_llvm.h @@ -5,6 +5,6 @@ #include "ir.h" struct llvm::Module * glsl_ir_to_llvm_module(struct exec_list *ir, llvm::Module * mod, - const struct GGLContext * gglCtx, const char * shaderSuffix); + const struct GGLState * gglCtx, const char * shaderSuffix); #endif /* IR_TO_LLVM_H_ */ diff --git a/src/glsl/ir_to_llvm_helper.cpp b/src/glsl/ir_to_llvm_helper.cpp index 9392990..ece6653 100644 --- a/src/glsl/ir_to_llvm_helper.cpp +++ b/src/glsl/ir_to_llvm_helper.cpp @@ -246,7 +246,7 @@ static Value * texcoordWrap(IRBuilder<> & builder, const unsigned wrap, Value * tex2D(IRBuilder<> & builder, Value * in1, const unsigned sampler, /*const RegDesc * in1Desc, const RegDesc * dstDesc,*/ - const GGLContext * gglCtx) + const GGLState * gglCtx) { const Type * intType = builder.getInt32Ty(); const PointerType * intPointerType = PointerType::get(intType, 0); @@ -336,7 +336,7 @@ static Value * Fabs(IRBuilder<> & builder, Value * val) Value * texCube(IRBuilder<> & builder, Value * in1, const unsigned sampler, /*const RegDesc * in1Desc, const RegDesc * dstDesc,*/ - const GGLContext * gglCtx) + const GGLState * gglCtx) { // if (in1Desc) // the major axis determination code is only float for now // assert(in1Desc->IsVectorType(Float)); diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp index f727952..0b6a125 100644 --- a/src/glsl/linker.cpp +++ b/src/glsl/linker.cpp @@ -86,6 +86,8 @@ extern "C" { #include "main/shaderobj.h" } +extern "C" void _mesa_delete_shader(gl_context * ctx, gl_shader * shader); + /** * Visitor that determines whether or not a variable is ever written. */ @@ -835,7 +837,7 @@ link_intrastage_shaders(void *mem_ctx, return NULL; } - gl_shader *linked = ctx->Driver.NewShader(ctx, 0, main->Type); + gl_shader *linked = _mesa_new_shader(ctx, 0, main->Type); hieralloc_steal(prog, linked); linked->ir = new(linked) exec_list; clone_ir_list(mem_ctx, linked->ir, main->ir); @@ -885,7 +887,7 @@ link_intrastage_shaders(void *mem_ctx, if (!link_function_calls(prog, linked, linking_shaders, num_linking_shaders)) { - ctx->Driver.DeleteShader(ctx, linked); + _mesa_delete_shader(ctx, linked); linked = NULL; } @@ -1595,7 +1597,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) for (unsigned int i = 0; i < MESA_SHADER_TYPES; i++) { if (prog->_LinkedShaders[i] != NULL) - ctx->Driver.DeleteShader(ctx, prog->_LinkedShaders[i]); + _mesa_delete_shader(ctx, prog->_LinkedShaders[i]); prog->_LinkedShaders[i] = NULL; } diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 573dae2..8dd73d1 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -3077,7 +3077,6 @@ struct gl_context /** State possibly shared with other contexts in the address space */ // struct gl_shared_state *Shared; - struct gl_shader_program * CurrentProgram; /**< currently active for rendering ř*/ /** \name API function pointer tables */ /*@{*/ gl_api API; @@ -3095,7 +3094,7 @@ struct gl_context /** * Device driver function pointer table */ - struct dd_function_table Driver; +// struct dd_function_table Driver; // void *DriverCtx; /**< Points to device driver context/state */ diff --git a/src/pixelflinger2/buffer.cpp b/src/pixelflinger2/buffer.cpp index 1c5c18c..3e1f081 100644 --- a/src/pixelflinger2/buffer.cpp +++ b/src/pixelflinger2/buffer.cpp @@ -27,7 +27,7 @@ static void DepthFunc(GGLInterface * iface, GLenum func) GGL_GET_CONTEXT(ctx, iface); if (GL_NEVER > func || GL_ALWAYS < func) return gglError(GL_INVALID_ENUM); - ctx->bufferState.depthFunc = func & 0x7; + ctx->state.bufferState.depthFunc = func & 0x7; SetShaderVerifyFunctions(iface); } @@ -43,15 +43,15 @@ static void StencilFuncSeparate(GGLInterface * iface, GLenum face, GLenum func, ref &= mask; if (GL_FRONT == face || GL_FRONT_AND_BACK == face) { - ctx->frontStencil.ref = ref; - ctx->frontStencil.mask = mask; - ctx->frontStencil.func = func & 0x7; + ctx->state.frontStencil.ref = ref; + ctx->state.frontStencil.mask = mask; + ctx->state.frontStencil.func = func & 0x7; } if (GL_BACK == face || GL_FRONT_AND_BACK == face) { - ctx->backStencil.ref = ref; - ctx->backStencil.mask = mask; - ctx->backStencil.func = func & 0x7; + ctx->state.backStencil.ref = ref; + ctx->state.backStencil.mask = mask; + ctx->state.backStencil.func = func & 0x7; } SetShaderVerifyFunctions(iface); } @@ -79,15 +79,15 @@ static void StencilOpSeparate(GGLInterface * iface, GLenum face, GLenum sfail, G return gglError(GL_INVALID_ENUM); if (GL_FRONT == face || GL_FRONT_AND_BACK == face) { - ctx->frontStencil.sFail = StencilOpEnum(sfail, ctx->frontStencil.sFail); - ctx->frontStencil.dFail = StencilOpEnum(dpfail, ctx->frontStencil.dFail); - ctx->frontStencil.dPass = StencilOpEnum(dppass, ctx->frontStencil.dPass); + ctx->state.frontStencil.sFail = StencilOpEnum(sfail, ctx->state.frontStencil.sFail); + ctx->state.frontStencil.dFail = StencilOpEnum(dpfail, ctx->state.frontStencil.dFail); + ctx->state.frontStencil.dPass = StencilOpEnum(dppass, ctx->state.frontStencil.dPass); } if (GL_BACK == face || GL_FRONT_AND_BACK == face) { - ctx->backStencil.sFail = StencilOpEnum(sfail, ctx->backStencil.sFail); - ctx->backStencil.dFail = StencilOpEnum(dpfail, ctx->backStencil.dFail); - ctx->backStencil.dPass = StencilOpEnum(dppass, ctx->backStencil.dPass); + ctx->state.backStencil.sFail = StencilOpEnum(sfail, ctx->state.backStencil.sFail); + ctx->state.backStencil.dFail = StencilOpEnum(dpfail, ctx->state.backStencil.dFail); + ctx->state.backStencil.dPass = StencilOpEnum(dppass, ctx->state.backStencil.dPass); } SetShaderVerifyFunctions(iface); } @@ -98,14 +98,14 @@ static void StencilSelect(const GGLInterface * iface, GLenum face) if (GL_FRONT == face) { ctx->activeStencil.face = 0; - ctx->activeStencil.ref = ctx->frontStencil.ref; - ctx->activeStencil.mask = ctx->frontStencil.mask; + ctx->activeStencil.ref = ctx->state.frontStencil.ref; + ctx->activeStencil.mask = ctx->state.frontStencil.mask; } else if (GL_BACK == face) { ctx->activeStencil.face = 1; - ctx->activeStencil.ref = ctx->backStencil.ref; - ctx->activeStencil.mask = ctx->backStencil.mask; + ctx->activeStencil.ref = ctx->state.backStencil.ref; + ctx->activeStencil.mask = ctx->state.backStencil.mask; } } diff --git a/src/pixelflinger2/llvm_scanline.cpp b/src/pixelflinger2/llvm_scanline.cpp index 5bb6732..e9b9efe 100644 --- a/src/pixelflinger2/llvm_scanline.cpp +++ b/src/pixelflinger2/llvm_scanline.cpp @@ -213,10 +213,10 @@ static Value * IntVectorToColor(IRBuilder<> & builder, Value * src) } // src is <4 x float> approx [0,1]; dst is <4 x i32> [0,255] from frame buffer; return is i32 -Value * GenerateFSBlend(const GGLContext * gglCtx, /*const RegDesc * regDesc,*/ +Value * GenerateFSBlend(const GGLState * gglCtx, /*const RegDesc * regDesc,*/ IRBuilder<> & builder, Value * src, Value * dst) { - const Type * const intType = Type::getInt32Ty(*gglCtx->llvmCtx); + const Type * const intType = builder.getInt32Ty(); // TODO cast the outputs pointer type to int for writing to minimize bandwidth if (!gglCtx->blendState.enable) { @@ -401,15 +401,15 @@ static FunctionType * ScanLineFunctionType(IRBuilder<> & builder) // generated scanline function parameters are VertexOutput * start, VertexOutput * step, // unsigned * frame, int * depth, unsigned char * stencil, // GGLActiveStencilState * stencilState, unsigned count -void GenerateScanLine(const GGLContext * gglCtx, const gl_shader_program * program, Module * mod, +void GenerateScanLine(const GGLState * gglCtx, const gl_shader_program * program, Module * mod, const char * shaderName, const char * scanlineName) { IRBuilder<> builder(mod->getContext()); debug_printf("GenerateScanLine %s \n", scanlineName); - const Type * intType = Type::getInt32Ty(*gglCtx->llvmCtx); + const Type * intType = builder.getInt32Ty(); const PointerType * intPointerType = PointerType::get(intType, 0); - const Type * byteType = Type::getInt8Ty(*gglCtx->llvmCtx); + const Type * byteType = builder.getInt8Ty(); const PointerType * bytePointerType = PointerType::get(byteType, 0); Function * func = mod->getFunction(scanlineName); @@ -485,7 +485,7 @@ void GenerateScanLine(const GGLContext * gglCtx, const gl_shader_program * progr stencil->setName("stencil"); // temporaries to load/store value - sCmpPtr = builder.CreateAlloca(Type::getInt1Ty(*gglCtx->llvmCtx)); + sCmpPtr = builder.CreateAlloca(builder.getInt1Ty()); sCmpPtr->setName("sCmpPtr"); sPtr = builder.CreateAlloca(byteType); sPtr->setName("sPtr"); @@ -650,7 +650,7 @@ void GenerateScanLine(const GGLContext * gglCtx, const gl_shader_program * progr v = builder.CreateFAdd(v, dx); builder.CreateStore(v, vPtr); } else if (gglCtx->bufferState.depthTest) { - const Type * floatType = Type::getFloatTy(*gglCtx->llvmCtx); + const Type * floatType = builder.getFloatTy(); const PointerType * floatPointerType = PointerType::get(floatType, 0); vPtr = builder.CreateBitCast(start, floatPointerType); vPtr = builder.CreateConstInBoundsGEP1_32(vPtr, diff --git a/src/pixelflinger2/pixelflinger2.cpp b/src/pixelflinger2/pixelflinger2.cpp index fc37714..2eb419d 100644 --- a/src/pixelflinger2/pixelflinger2.cpp +++ b/src/pixelflinger2/pixelflinger2.cpp @@ -67,10 +67,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); - 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); + ctx->state.blendState.color[0] = MIN2(MAX2(red * 255, 0.0f), 255.0f); + ctx->state.blendState.color[1] = MIN2(MAX2(green * 255, 0.0f), 255.0f); + ctx->state.blendState.color[2] = MIN2(MAX2(blue * 255, 0.0f), 255.0f); + ctx->state.blendState.color[3] = MIN2(MAX2(alpha * 255, 0.0f), 255.0f); SetShaderVerifyFunctions(iface); } @@ -83,8 +83,8 @@ static void BlendEquationSeparate(GGLInterface * iface, GLenum modeRGB, GLenum m if (GL_FUNC_ADD != modeRGB && (GL_FUNC_SUBTRACT > modeRGB || GL_FUNC_REVERSE_SUBTRACT < modeRGB)) return gglError(GL_INVALID_ENUM); - ctx->blendState.ce = modeRGB - GL_FUNC_ADD; - ctx->blendState.ae = modeAlpha - GL_FUNC_ADD; + ctx->state.blendState.ce = modeRGB - GL_FUNC_ADD; + ctx->state.blendState.ae = modeAlpha - GL_FUNC_ADD; SetShaderVerifyFunctions(iface); } @@ -111,19 +111,19 @@ static void BlendFuncSeparate(GGLInterface * iface, GLenum srcRGB, GLenum dstRGB srcAlpha = GL_ONE; // in c++ it's templated function for color and alpha, // so it requires setting srcAlpha to GL_ONE to run template again only for alpha - ctx->blendState.scf = srcRGB <= GL_ONE ? srcRGB : + ctx->state.blendState.scf = srcRGB <= GL_ONE ? srcRGB : (srcRGB <= GL_SRC_ALPHA_SATURATE ? srcRGB - GL_SRC_COLOR + 2 : srcRGB - GL_CONSTANT_COLOR + 11); - ctx->blendState.saf = srcAlpha <= GL_ONE ? srcAlpha : + ctx->state.blendState.saf = srcAlpha <= GL_ONE ? srcAlpha : (srcAlpha <= GL_SRC_ALPHA_SATURATE ? srcAlpha - GL_SRC_COLOR + 2 : srcAlpha - GL_CONSTANT_COLOR + 11); - ctx->blendState.dcf = dstRGB <= GL_ONE ? dstRGB : + ctx->state.blendState.dcf = dstRGB <= GL_ONE ? dstRGB : (dstRGB <= GL_SRC_ALPHA_SATURATE ? dstRGB - GL_SRC_COLOR + 2 : dstRGB - GL_CONSTANT_COLOR + 11); - ctx->blendState.daf = dstAlpha <= GL_ONE ? dstAlpha : + ctx->state.blendState.daf = dstAlpha <= GL_ONE ? dstAlpha : (dstAlpha <= GL_SRC_ALPHA_SATURATE ? dstAlpha - GL_SRC_COLOR + 2 : dstAlpha - GL_CONSTANT_COLOR + 11); @@ -137,20 +137,20 @@ static void EnableDisable(GGLInterface * iface, GLenum cap, GLboolean enable) bool changed = false; switch (cap) { case GL_BLEND: - changed |= ctx->blendState.enable ^ enable; - ctx->blendState.enable = enable; + changed |= ctx->state.blendState.enable ^ enable; + ctx->state.blendState.enable = enable; break; case GL_CULL_FACE: changed |= ctx->cullState.enable ^ enable; ctx->cullState.enable = enable; break; case GL_DEPTH_TEST: - changed |= ctx->bufferState.depthTest ^ enable; - ctx->bufferState.depthTest = enable; + changed |= ctx->state.bufferState.depthTest ^ enable; + ctx->state.bufferState.depthTest = enable; break; case GL_STENCIL_TEST: - changed |= ctx->bufferState.stencilTest ^ enable; - ctx->bufferState.stencilTest = enable; + changed |= ctx->state.bufferState.stencilTest ^ enable; + ctx->state.bufferState.stencilTest = enable; break; default: gglError(GL_INVALID_ENUM); diff --git a/src/pixelflinger2/pixelflinger2.h b/src/pixelflinger2/pixelflinger2.h index e6f5057..007954a 100644 --- a/src/pixelflinger2/pixelflinger2.h +++ b/src/pixelflinger2/pixelflinger2.h @@ -69,15 +69,11 @@ struct GGLContext { unsigned stencil; // s_8; repeated to clear 4 pixels at a time } clearState; - GGLStencilState frontStencil, backStencil; // all affect scanline jit - - mutable GGLActiveStencilState activeStencil; // after primitive assembly, call StencilSelect - - GGLBufferState bufferState; // all affect scanline jit - - GGLBlendState blendState; // all affect scanline jit + gl_shader_program * CurrentProgram; + + mutable GGLActiveStencil activeStencil; // after primitive assembly, call StencilSelect - GGLTextureState textureState; + GGLState state; // states affecting jit // called by ShaderUse to set to proper rendering functions void (* PickScanLine)(GGLInterface * iface); diff --git a/src/pixelflinger2/raster.cpp b/src/pixelflinger2/raster.cpp index 63d63b4..c2db172 100644 --- a/src/pixelflinger2/raster.cpp +++ b/src/pixelflinger2/raster.cpp @@ -53,6 +53,13 @@ static inline void InterpolateVertex(const VertexOutput * a, const VertexOutput } +void GGLProcessVertex(const gl_shader_program * program, const VertexInput_t * input, + VertexOutput_t * output, const float (*constants)[4]) +{ + ShaderFunction_t function = (ShaderFunction_t)program->_LinkedShaders[MESA_SHADER_VERTEX]->function; + function(input, output, constants); +} + static void ProcessVertex(const GGLInterface * iface, const VertexInput * input, VertexOutput * output) { @@ -68,8 +75,7 @@ static void ProcessVertex(const GGLInterface * iface, const VertexInput * 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); + GGLProcessVertex(ctx->CurrentProgram, input, output, ctx->CurrentProgram->ValuesUniform); // const Vector4 * constants = (Vector4 *) // ctx->glCtx->Shader.CurrentProgram->VertexProgram->Parameters->ParameterValues; // ctx->glCtx->Shader.CurrentProgram->GLVMVP->function(input, output, constants); @@ -90,7 +96,7 @@ static void RasterTrapezoid(const GGLInterface * iface, const VertexOutput * tl, assert(fabs(tl->position.y - tr->position.y) < 1 && fabs(bl->position.y - br->position.y) < 1); const unsigned width = ctx->frameSurface.width, height = ctx->frameSurface.height; - const unsigned varyingCount = ctx->glCtx->CurrentProgram->VaryingSlots; + const unsigned varyingCount = ctx->CurrentProgram->VaryingSlots; // tlv-trv and blv-brv are parallel and horizontal @@ -193,7 +199,7 @@ static void RasterTriangle(const GGLInterface * iface, const VertexOutput * v1, const VertexOutput * v2, const VertexOutput * v3) { GGL_GET_CONST_CONTEXT(ctx, iface); - const unsigned varyingCount = ctx->glCtx->CurrentProgram->VaryingSlots; + const unsigned varyingCount = ctx->CurrentProgram->VaryingSlots; const unsigned height = ctx->frameSurface.height; const VertexOutput * a = v1, * b = v2, * d = v3; //abc is a triangle, bcd is another triangle, they share bc as horizontal edge diff --git a/src/pixelflinger2/scanline.cpp b/src/pixelflinger2/scanline.cpp index 04a55d4..a7f8475 100644 --- a/src/pixelflinger2/scanline.cpp +++ b/src/pixelflinger2/scanline.cpp @@ -144,7 +144,6 @@ static inline void BlendFactor(const unsigned mode, T & factor, const T & src, return; } } -#endif // #if !USE_LLVM_SCANLINE unsigned char StencilOp(const unsigned op, unsigned char s, const unsigned char ref) { @@ -175,333 +174,390 @@ unsigned char StencilOp(const unsigned op, unsigned char s, const unsigned char } } -template <bool StencilTest, bool DepthTest, bool DepthWrite, bool BlendEnable> -void ScanLine(const GGLInterface * iface, const VertexOutput * v1, const VertexOutput * v2) +#endif // #if !USE_LLVM_SCANLINE + +#ifdef USE_LLVM_SCANLINE +typedef void (* ScanLineFunction_t)(VertexOutput * start, VertexOutput * step, + const float (*constants)[4], unsigned * frame, + int * depth, unsigned char * stencil, + GGLActiveStencil *, unsigned count); +#endif + +void GGLScanLine(const gl_shader_program * program, unsigned * frameBuffer, + int * depthBuffer, unsigned char * stencilBuffer, unsigned bufferWidth, + unsigned bufferHeight, GGLActiveStencil * activeStencil, const VertexOutput_t * start, + const VertexOutput_t * end, const float (*constants)[4]) { - GGL_GET_CONST_CONTEXT(ctx, iface); - // assert((unsigned)v1->position.y == (unsigned)v2->position.y); - // - // assert(GGL_PIXEL_FORMAT_RGBA_8888 == ctx->frameSurface.format); - // assert(GGL_PIXEL_FORMAT_Z_32 == ctx->depthSurface.format); - // assert(ctx->frameSurface.width == ctx->depthSurface.width); - // assert(ctx->frameSurface.height == ctx->depthSurface.height); +#if !USE_LLVM_SCANLINE + assert(!"only for USE_LLVM_SCANLINE"); +#endif - const unsigned int varyingCount = ctx->glCtx->CurrentProgram->VaryingSlots; - const unsigned y = v1->position.y, startX = v1->position.x, - endX = v2->position.x; + const unsigned int varyingCount = program->VaryingSlots; + const unsigned y = start->position.y, startX = start->position.x, + endX = end->position.x; //assert(ctx->frameSurface.width > startX && ctx->frameSurface.width > endX); //assert(ctx->frameSurface.height > y); - unsigned * frame = (unsigned *)ctx->frameSurface.data - + y * ctx->frameSurface.width + startX; + unsigned * frame = frameBuffer + y * bufferWidth + 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, start, sizeof(*start)); // shader symbols are mapped to gl_shader_program_Values* //VertexOutput & vertex(*(VertexOutput*)ctx->glCtx->CurrentProgram->ValuesVertexOutput); - VertexOutput vertex(*v1); - VertexOutput vertexDx(*v2); + VertexOutput vertex(*start); + VertexOutput vertexDx(*end); - vertexDx.position -= v1->position; + vertexDx.position -= start->position; vertexDx.position *= div; //printf("vertexDx.position.z=%.8g \n", vertexDx.position.z); for (unsigned i = 0; i < varyingCount; i++) { - vertexDx.varyings[i] -= v1->varyings[i]; + vertexDx.varyings[i] -= start->varyings[i]; vertexDx.varyings[i] *= div; } - vertexDx.frontFacingPointCoord -= v1->frontFacingPointCoord; + vertexDx.frontFacingPointCoord -= start->frontFacingPointCoord; vertexDx.frontFacingPointCoord *= div; // gl_PointCoord, only zw vertexDx.frontFacingPointCoord.y = 0; // gl_FrontFacing not interpolated -#if USE_FORCED_FIXEDPOINT - for (unsigned j = 0; j < 4; j++) { - for (unsigned i = 0; i < varyingCount; i++) { - vertex.varyings[i].i[j] = vertex.varyings[i].f[j] * 65536; - vertexDx.varyings[i].i[j] = vertexDx.varyings[i].f[j] * 65536; - } - vertex.position.i[j] = vertex.position.f[j] * 65536; - vertexDx.position.i[j] = vertexDx.position.f[j] * 65536; - vertex.frontFacingPointCoord.i[j] = vertex.frontFacingPointCoord.f[j] * 65536; - } -#endif - - int * depth = (int *)ctx->depthSurface.data + y * ctx->frameSurface.width + startX; - unsigned char * stencil = (unsigned char *)ctx->stencilSurface.data + y * ctx->frameSurface.width + startX; - -#if !USE_LLVM_TEXTURE_SAMPLER - extern const GGLContext * textureGGLContext; - textureGGLContext = ctx; -#endif + int * depth = depthBuffer + y * bufferWidth + startX; + unsigned char * stencil = stencilBuffer + y * bufferWidth + startX; // TODO DXL consider inverting gl_FragCoord.y - -#if USE_LLVM_SCANLINE - typedef void (* ScanLineFunction_t)(VertexOutput * start, VertexOutput * step, float (*constants)[4], - unsigned * frame, int * depth, unsigned char * stencil, - GGLActiveStencilState *, unsigned count); - ScanLineFunction_t scanLineFunction = (ScanLineFunction_t) - ctx->glCtx->CurrentProgram->_LinkedShaders[MESA_SHADER_FRAGMENT]->function; - if (endX >= startX) { - scanLineFunction(&vertex, &vertexDx, ctx->glCtx->CurrentProgram->ValuesUniform, frame, depth, stencil, &ctx->activeStencil, endX - startX + 1); - } -#else - - int z; - bool sCmp = true; // default passed, unless failed by stencil test - unsigned char s; // masked stored stencil value - const unsigned char sMask = ctx->activeStencil.mask; - const unsigned char sRef = ctx->activeStencil.ref; - const unsigned sFunc = ctx->activeStencil.face ? 0x200 | ctx->backStencil.func : - 0x200 | ctx->frontStencil.func; - const unsigned ssFail = ctx->activeStencil.face ? ctx->backStencil.sFail : - ctx->frontStencil.sFail; - const unsigned sdFail = ctx->activeStencil.face ? ctx->backStencil.dFail : - ctx->frontStencil.dFail; - const unsigned sdPass = ctx->activeStencil.face ? ctx->backStencil.dPass : - ctx->frontStencil.dPass; - - for (unsigned x = startX; x <= endX; x++) { - //assert(abs((int)(vertex.position.x) - (int)x) < 2); - //assert((unsigned)vertex.position.y == y); - if (StencilTest) { - s = *stencil & sMask; - switch (sFunc) { - case GL_NEVER: - sCmp = false; - break; - case GL_LESS: - sCmp = sRef < s; - break; - case GL_EQUAL: - sCmp = sRef == s; - break; - case GL_LEQUAL: - sCmp = sRef <= s; - break; - case GL_GREATER: - sCmp = sRef > s; - break; - case GL_NOTEQUAL: - sCmp = sRef != s; - break; - case GL_GEQUAL: - sCmp = sRef >= s; - break; - case GL_ALWAYS: - sCmp = true; - break; - default: - assert(0); - break; - } - } - - if (!StencilTest || sCmp) { - z = vertex.position.i[2]; - if (z & 0x80000000) // negative float has leading 1 - z ^= 0x7fffffff; // bigger negative is smaller - bool zCmp = true; - if (DepthTest) { - switch (0x200 | ctx->bufferState.depthFunc) { - case GL_NEVER: - zCmp = false; - break; - case GL_LESS: - zCmp = z < *depth; - break; - case GL_EQUAL: - zCmp = z == *depth; - break; - case GL_LEQUAL: - zCmp = z <= *depth; - break; - case GL_GREATER: - zCmp = z > *depth; - break; - case GL_NOTEQUAL: - zCmp = z != *depth; - break; - case GL_GEQUAL: - zCmp = z >= *depth; - break; - case GL_ALWAYS: - zCmp = true; - break; - default: - assert(0); - break; - } - } - if (!DepthTest || zCmp) { - float * varying = (float *)ctx->glCtx->CurrentProgram->ValuesVertexOutput; - 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; + program->_LinkedShaders[MESA_SHADER_FRAGMENT]->function; + if (endX >= startX) + scanLineFunction(&vertex, &vertexDx, constants, frame, depth, stencil, activeStencil, endX - startX + 1); - Vec4<BlendComp_t> src; -// if (outputRegDesc.IsInt32Color()) -// RGBAIntToRGBAIntx4(vertex.fragColor[0].u[0], &src); -// else if (outputRegDesc.IsVectorType(Float)) - RGBAFloatx4ToRGBAIntx4(&vertex.fragColor[0], &src); -// else if (outputRegDesc.IsVectorType(Fixed8)) -// { -// src.u[0] = vertex.fragColor[0].u[0]; -// src.u[1] = vertex.fragColor[0].u[1]; -// src.u[2] = vertex.fragColor[0].u[2]; -// src.u[3] = vertex.fragColor[0].u[3]; -// } -// else -// assert(0); - - Vec4<BlendComp_t> dst; - unsigned dc = *frame; - dst.r = dc & 255; - dst.g = (dc >>= 8) & 255; - dst.b = (dc >>= 8) & 255; - 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, - 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, - blendStateColor.a, sOne, sZero, src.a, dst.a, - blendStateColor.a, sOne); - BlendFactor(ctx->blendState.dcf, df, src, dst, - 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, - blendStateColor.a, sOne, sZero, src.a, dst.a, - blendStateColor.a, sOne); - - Vec4<BlendComp_t> sfs(sf), dfs(df); - sfs.LShr(7); - sf += sfs; - dfs.LShr(7); - df += dfs; - - src *= sf; - dst *= df; - Vec4<BlendComp_t> res(src); - switch (ctx->blendState.ce + GL_FUNC_ADD) { - case GL_FUNC_ADD: - res += dst; - break; - case GL_FUNC_SUBTRACT: - res -= dst; - break; - case GL_FUNC_REVERSE_SUBTRACT: - res = dst; - res -= src; - break; - default: - assert(0); - break; - } - if (ctx->blendState.ce != ctx->blendState.ae) - switch (ctx->blendState.ce + GL_FUNC_ADD) { - case GL_FUNC_ADD: - res.a = src.a + dst.a; - break; - case GL_FUNC_SUBTRACT: - res.a = src.a - dst.a; - break; - case GL_FUNC_REVERSE_SUBTRACT: - res.a = dst.a - src.a; - break; - default: - assert(0); - break; - } - - res.AShr(8); - Saturate(&res); - *frame = RGBAIntx4ToRGBAInt(&res); - } else { -// if (outputRegDesc.IsInt32Color()) -// *frame = vertex.fragColor[0].u[0]; -// else if (outputRegDesc.IsVectorType(Float)) - { - Vec4<BlendComp_t> src; - RGBAFloatx4ToRGBAIntx4(&vertex.fragColor[0], &src); - Saturate(&src); - *frame = RGBAIntx4ToRGBAInt(&src); - } -// else if (outputRegDesc.IsVectorType(Fixed16)) -// { -// Vec4<BlendComp_t> & src = (Vec4<BlendComp_t> &)vertex.fragColor[0]; -// src.r = (src.r * 255 >> 16); -// src.g = (src.g * 255 >> 16); -// src.b = (src.b * 255 >> 16); -// src.a = (src.a * 255 >> 16); -// Saturate(&src); -// *frame = RGBAIntx4ToRGBAInt(&src); -// } -// else if (outputRegDesc.IsVectorType(Fixed8)) -// { -// Vec4<BlendComp_t> & src = (Vec4<BlendComp_t> &)vertex.fragColor[0]; -// Saturate(&src); -// *frame = RGBAIntx4ToRGBAInt(&src); -// } -// else -// assert(0); - } - - if (DepthWrite) - *depth = z; - if (StencilTest) - *stencil = StencilOp(sdPass, s, sRef); - } else if (StencilTest) - *stencil = StencilOp(sdFail, s, sRef); - } else if (StencilTest) - *stencil = StencilOp(ssFail, s, sRef); - - frame++; - depth++; - stencil++; - -#if USE_FORCED_FIXEDPOINT - for (unsigned j = 0; j < 4; j++) { - if (ctx->glCtx->Shader.CurrentProgram->FragmentProgram->UsesFragCoord) - vertex.position.i[j] += vertexDx.position.i[j]; - for (unsigned i = 0; i < varyingCount; i++) - vertex.varyings[i].i[j] += vertexDx.varyings[i].i[j]; - } - vertex.position.i[2] += vertexDx.position.i[2]; - if (ctx->glCtx->Shader.CurrentProgram->FragmentProgram->UsesPointCoord) { - vertex.frontFacingPointCoord.i[2] = vertexDx.frontFacingPointCoord.i[2]; - vertex.frontFacingPointCoord.i[3] = vertexDx.frontFacingPointCoord.i[3]; - } -#else - if (ctx->glCtx->CurrentProgram->UsesFragCoord) - vertex.position += vertexDx.position; - else if (ctx->bufferState.depthTest) - vertex.position.z += vertexDx.position.z; - - for (unsigned i = 0; i < varyingCount; i++) - vertex.varyings[i] += vertexDx.varyings[i]; - if (ctx->glCtx->CurrentProgram->UsesPointCoord) { - vertex.frontFacingPointCoord.z += vertexDx.frontFacingPointCoord.z; - vertex.frontFacingPointCoord.w += vertexDx.frontFacingPointCoord.w; - } -#endif // #if USE_FORCED_FIXEDPOINT - } - -#endif // #if USE_LLVM_SCANLINE +} -#if !USE_LLVM_TEXTURE_SAMPLER - textureGGLContext = NULL; -#endif +template <bool StencilTest, bool DepthTest, bool DepthWrite, bool BlendEnable> +void ScanLine(const GGLInterface * iface, const VertexOutput * start, const VertexOutput * end) +{ + GGL_GET_CONST_CONTEXT(ctx, iface); + GGLScanLine(ctx->CurrentProgram, (unsigned *)ctx->frameSurface.data, + (int *)ctx->depthSurface.data, (unsigned char *)ctx->stencilSurface.data, + ctx->frameSurface.width, ctx->frameSurface.height, &ctx->activeStencil, + start, end, ctx->CurrentProgram->ValuesUniform); +// GGL_GET_CONST_CONTEXT(ctx, iface); +// // assert((unsigned)start->position.y == (unsigned)end->position.y); +// // +// // assert(GGL_PIXEL_FORMAT_RGBA_8888 == ctx->frameSurface.format); +// // assert(GGL_PIXEL_FORMAT_Z_32 == ctx->depthSurface.format); +// // assert(ctx->frameSurface.width == ctx->depthSurface.width); +// // assert(ctx->frameSurface.height == ctx->depthSurface.height); +// +// const unsigned int varyingCount = ctx->glCtx->CurrentProgram->VaryingSlots; +// const unsigned y = start->position.y, startX = start->position.x, +// endX = end->position.x; +// +// //assert(ctx->frameSurface.width > startX && ctx->frameSurface.width > endX); +// //assert(ctx->frameSurface.height > y); +// +// unsigned * frame = (unsigned *)ctx->frameSurface.data +// + y * ctx->frameSurface.width + startX; +// const VectorComp_t div = VectorComp_t_CTR(1 / (float)(endX - startX)); +// +// //memcpy(ctx->glCtx->CurrentProgram->ValuesVertexOutput, start, sizeof(*start)); +// // shader symbols are mapped to gl_shader_program_Values* +// //VertexOutput & vertex(*(VertexOutput*)ctx->glCtx->CurrentProgram->ValuesVertexOutput); +// VertexOutput vertex(*start); +// VertexOutput vertexDx(*end); +// +// vertexDx.position -= start->position; +// vertexDx.position *= div; +// //printf("vertexDx.position.z=%.8g \n", vertexDx.position.z); +// for (unsigned i = 0; i < varyingCount; i++) { +// vertexDx.varyings[i] -= start->varyings[i]; +// vertexDx.varyings[i] *= div; +// } +// vertexDx.frontFacingPointCoord -= start->frontFacingPointCoord; +// vertexDx.frontFacingPointCoord *= div; // gl_PointCoord, only zw +// vertexDx.frontFacingPointCoord.y = 0; // gl_FrontFacing not interpolated +// +//#if USE_FORCED_FIXEDPOINT +// for (unsigned j = 0; j < 4; j++) { +// for (unsigned i = 0; i < varyingCount; i++) { +// vertex.varyings[i].i[j] = vertex.varyings[i].f[j] * 65536; +// vertexDx.varyings[i].i[j] = vertexDx.varyings[i].f[j] * 65536; +// } +// vertex.position.i[j] = vertex.position.f[j] * 65536; +// vertexDx.position.i[j] = vertexDx.position.f[j] * 65536; +// vertex.frontFacingPointCoord.i[j] = vertex.frontFacingPointCoord.f[j] * 65536; +// } +//#endif +// +// int * depth = (int *)ctx->depthSurface.data + y * ctx->frameSurface.width + startX; +// unsigned char * stencil = (unsigned char *)ctx->stencilSurface.data + y * ctx->frameSurface.width + startX; +// +//#if !USE_LLVM_TEXTURE_SAMPLER +// extern const GGLContext * textureGGLContext; +// textureGGLContext = ctx; +//#endif +// +// // TODO DXL consider inverting gl_FragCoord.y +// +//#if USE_LLVM_SCANLINE +// ScanLineFunction_t scanLineFunction = (ScanLineFunction_t) +// ctx->glCtx->CurrentProgram->_LinkedShaders[MESA_SHADER_FRAGMENT]->function; +// if (endX >= startX) { +// scanLineFunction(&vertex, &vertexDx, ctx->glCtx->CurrentProgram->ValuesUniform, frame, depth, stencil, &ctx->activeStencil, endX - startX + 1); +// } +//#else +// +// int z; +// bool sCmp = true; // default passed, unless failed by stencil test +// unsigned char s; // masked stored stencil value +// const unsigned char sMask = ctx->activeStencil.mask; +// const unsigned char sRef = ctx->activeStencil.ref; +// const unsigned sFunc = ctx->activeStencil.face ? 0x200 | ctx->backStencil.func : +// 0x200 | ctx->frontStencil.func; +// const unsigned ssFail = ctx->activeStencil.face ? ctx->backStencil.sFail : +// ctx->frontStencil.sFail; +// const unsigned sdFail = ctx->activeStencil.face ? ctx->backStencil.dFail : +// ctx->frontStencil.dFail; +// const unsigned sdPass = ctx->activeStencil.face ? ctx->backStencil.dPass : +// ctx->frontStencil.dPass; +// +// for (unsigned x = startX; x <= endX; x++) { +// //assert(abs((int)(vertex.position.x) - (int)x) < 2); +// //assert((unsigned)vertex.position.y == y); +// if (StencilTest) { +// s = *stencil & sMask; +// switch (sFunc) { +// case GL_NEVER: +// sCmp = false; +// break; +// case GL_LESS: +// sCmp = sRef < s; +// break; +// case GL_EQUAL: +// sCmp = sRef == s; +// break; +// case GL_LEQUAL: +// sCmp = sRef <= s; +// break; +// case GL_GREATER: +// sCmp = sRef > s; +// break; +// case GL_NOTEQUAL: +// sCmp = sRef != s; +// break; +// case GL_GEQUAL: +// sCmp = sRef >= s; +// break; +// case GL_ALWAYS: +// sCmp = true; +// break; +// default: +// assert(0); +// break; +// } +// } +// +// if (!StencilTest || sCmp) { +// z = vertex.position.i[2]; +// if (z & 0x80000000) // negative float has leading 1 +// z ^= 0x7fffffff; // bigger negative is smaller +// bool zCmp = true; +// if (DepthTest) { +// switch (0x200 | ctx->state.bufferState.depthFunc) { +// case GL_NEVER: +// zCmp = false; +// break; +// case GL_LESS: +// zCmp = z < *depth; +// break; +// case GL_EQUAL: +// zCmp = z == *depth; +// break; +// case GL_LEQUAL: +// zCmp = z <= *depth; +// break; +// case GL_GREATER: +// zCmp = z > *depth; +// break; +// case GL_NOTEQUAL: +// zCmp = z != *depth; +// break; +// case GL_GEQUAL: +// zCmp = z >= *depth; +// break; +// case GL_ALWAYS: +// zCmp = true; +// break; +// default: +// assert(0); +// break; +// } +// } +// if (!DepthTest || zCmp) { +// float * varying = (float *)ctx->glCtx->CurrentProgram->ValuesVertexOutput; +// 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; +// +// Vec4<BlendComp_t> src; +//// if (outputRegDesc.IsInt32Color()) +//// RGBAIntToRGBAIntx4(vertex.fragColor[0].u[0], &src); +//// else if (outputRegDesc.IsVectorType(Float)) +// RGBAFloatx4ToRGBAIntx4(&vertex.fragColor[0], &src); +//// else if (outputRegDesc.IsVectorType(Fixed8)) +//// { +//// src.u[0] = vertex.fragColor[0].u[0]; +//// src.u[1] = vertex.fragColor[0].u[1]; +//// src.u[2] = vertex.fragColor[0].u[2]; +//// src.u[3] = vertex.fragColor[0].u[3]; +//// } +//// else +//// assert(0); +// +// Vec4<BlendComp_t> dst; +// unsigned dc = *frame; +// dst.r = dc & 255; +// dst.g = (dc >>= 8) & 255; +// dst.b = (dc >>= 8) & 255; +// dst.a = (dc >>= 8) & 255; +// +// Vec4<BlendComp_t> sf, df; +// Vec4<BlendComp_t> blendStateColor(ctx->state.blendState.color[0], ctx->state.blendState.color[1], +// ctx->state.blendState.color[2], ctx->state.blendState.color[3]); +// +// BlendFactor(ctx->state.blendState.scf, sf, src, dst, +// blendStateColor, one, zero, src.a, dst.a, +// blendStateColor.a, sOne); +// if (ctx->state.blendState.scf != ctx->state.blendState.saf) +// BlendFactor(ctx->state.blendState.saf, sf.a, src.a, dst.a, +// blendStateColor.a, sOne, sZero, src.a, dst.a, +// blendStateColor.a, sOne); +// BlendFactor(ctx->state.blendState.dcf, df, src, dst, +// blendStateColor, one, zero, src.a, dst.a, +// blendStateColor.a, sOne); +// if (ctx->state.blendState.dcf != ctx->state.blendState.daf) +// BlendFactor(ctx->state.blendState.daf, df.a, src.a, dst.a, +// blendStateColor.a, sOne, sZero, src.a, dst.a, +// blendStateColor.a, sOne); +// +// Vec4<BlendComp_t> sfs(sf), dfs(df); +// sfs.LShr(7); +// sf += sfs; +// dfs.LShr(7); +// df += dfs; +// +// src *= sf; +// dst *= df; +// Vec4<BlendComp_t> res(src); +// switch (ctx->state.blendState.ce + GL_FUNC_ADD) { +// case GL_FUNC_ADD: +// res += dst; +// break; +// case GL_FUNC_SUBTRACT: +// res -= dst; +// break; +// case GL_FUNC_REVERSE_SUBTRACT: +// res = dst; +// res -= src; +// break; +// default: +// assert(0); +// break; +// } +// if (ctx->state.blendState.ce != ctx->state.blendState.ae) +// switch (ctx->state.blendState.ce + GL_FUNC_ADD) { +// case GL_FUNC_ADD: +// res.a = src.a + dst.a; +// break; +// case GL_FUNC_SUBTRACT: +// res.a = src.a - dst.a; +// break; +// case GL_FUNC_REVERSE_SUBTRACT: +// res.a = dst.a - src.a; +// break; +// default: +// assert(0); +// break; +// } +// +// res.AShr(8); +// Saturate(&res); +// *frame = RGBAIntx4ToRGBAInt(&res); +// } else { +//// if (outputRegDesc.IsInt32Color()) +//// *frame = vertex.fragColor[0].u[0]; +//// else if (outputRegDesc.IsVectorType(Float)) +// { +// Vec4<BlendComp_t> src; +// RGBAFloatx4ToRGBAIntx4(&vertex.fragColor[0], &src); +// Saturate(&src); +// *frame = RGBAIntx4ToRGBAInt(&src); +// } +//// else if (outputRegDesc.IsVectorType(Fixed16)) +//// { +//// Vec4<BlendComp_t> & src = (Vec4<BlendComp_t> &)vertex.fragColor[0]; +//// src.r = (src.r * 255 >> 16); +//// src.g = (src.g * 255 >> 16); +//// src.b = (src.b * 255 >> 16); +//// src.a = (src.a * 255 >> 16); +//// Saturate(&src); +//// *frame = RGBAIntx4ToRGBAInt(&src); +//// } +//// else if (outputRegDesc.IsVectorType(Fixed8)) +//// { +//// Vec4<BlendComp_t> & src = (Vec4<BlendComp_t> &)vertex.fragColor[0]; +//// Saturate(&src); +//// *frame = RGBAIntx4ToRGBAInt(&src); +//// } +//// else +//// assert(0); +// } +// +// if (DepthWrite) +// *depth = z; +// if (StencilTest) +// *stencil = StencilOp(sdPass, s, sRef); +// } else if (StencilTest) +// *stencil = StencilOp(sdFail, s, sRef); +// } else if (StencilTest) +// *stencil = StencilOp(ssFail, s, sRef); +// +// frame++; +// depth++; +// stencil++; +// +//#if USE_FORCED_FIXEDPOINT +// for (unsigned j = 0; j < 4; j++) { +// if (ctx->glCtx->Shader.CurrentProgram->FragmentProgram->UsesFragCoord) +// vertex.position.i[j] += vertexDx.position.i[j]; +// for (unsigned i = 0; i < varyingCount; i++) +// vertex.varyings[i].i[j] += vertexDx.varyings[i].i[j]; +// } +// vertex.position.i[2] += vertexDx.position.i[2]; +// if (ctx->glCtx->Shader.CurrentProgram->FragmentProgram->UsesPointCoord) { +// vertex.frontFacingPointCoord.i[2] = vertexDx.frontFacingPointCoord.i[2]; +// vertex.frontFacingPointCoord.i[3] = vertexDx.frontFacingPointCoord.i[3]; +// } +//#else +// if (ctx->glCtx->CurrentProgram->UsesFragCoord) +// vertex.position += vertexDx.position; +// else if (ctx->state.bufferState.depthTest) +// vertex.position.z += vertexDx.position.z; +// +// for (unsigned i = 0; i < varyingCount; i++) +// vertex.varyings[i] += vertexDx.varyings[i]; +// if (ctx->glCtx->CurrentProgram->UsesPointCoord) { +// vertex.frontFacingPointCoord.z += vertexDx.frontFacingPointCoord.z; +// vertex.frontFacingPointCoord.w += vertexDx.frontFacingPointCoord.w; +// } +//#endif // #if USE_FORCED_FIXEDPOINT +// } +// +//#endif // #if USE_LLVM_SCANLINE +// +//#if !USE_LLVM_TEXTURE_SAMPLER +// textureGGLContext = NULL; +//#endif } static void PickScanLine(GGLInterface * iface) @@ -509,26 +565,26 @@ static void PickScanLine(GGLInterface * iface) GGL_GET_CONTEXT(ctx, iface); ctx->interface.ScanLine = NULL; - if (ctx->bufferState.stencilTest) { - if (ctx->bufferState.depthTest) { - if (ctx->blendState.enable) + if (ctx->state.bufferState.stencilTest) { + if (ctx->state.bufferState.depthTest) { + if (ctx->state.blendState.enable) ctx->interface.ScanLine = ScanLine<true, true, true, true>; else ctx->interface.ScanLine = ScanLine<true, true, true, false>; } else { - if (ctx->blendState.enable) + if (ctx->state.blendState.enable) ctx->interface.ScanLine = ScanLine<true, false, false, true>; else ctx->interface.ScanLine = ScanLine<true, false, false, false>; } } else { - if (ctx->bufferState.depthTest) { - if (ctx->blendState.enable) + if (ctx->state.bufferState.depthTest) { + if (ctx->state.blendState.enable) ctx->interface.ScanLine = ScanLine<false, true, true, true>; else ctx->interface.ScanLine = ScanLine<false, true, true, false>; } else { - if (ctx->blendState.enable) + if (ctx->state.blendState.enable) ctx->interface.ScanLine = ScanLine<false, false, false, true>; else ctx->interface.ScanLine = ScanLine<false, false, false, false>; diff --git a/src/pixelflinger2/shader.cpp b/src/pixelflinger2/shader.cpp index 89248d7..87af237 100644 --- a/src/pixelflinger2/shader.cpp +++ b/src/pixelflinger2/shader.cpp @@ -275,7 +275,7 @@ static GLboolean ShaderProgramLink(const GGLInterface * iface, gl_shader_program return GGLShaderProgramLink(ctx->glCtx, program, infoLog); } -static void GetShaderKey(const GGLContext * ctx, const gl_shader * shader, ShaderKey * key) +static void GetShaderKey(const GGLState * ctx, const gl_shader * shader, ShaderKey * key) { memset(key, 0, sizeof(*key)); if (GL_FRAGMENT_SHADER == shader->Type) { @@ -350,7 +350,7 @@ static char * GetScanlineKeyString(const ShaderKey * key, char * buffer, } struct SymbolLookupContext { - const GGLContext * gglCtx; + const GGLState * gglCtx; const gl_shader_program * program; const gl_shader * shader; }; @@ -360,7 +360,7 @@ static void* SymbolLookup(void* pContext, const char* name) SymbolLookupContext * ctx = (SymbolLookupContext *)pContext; const gl_shader * shader = ctx->shader; const gl_shader_program * program = ctx->program; - const GGLContext * gglCtx = ctx->gglCtx; + const GGLState * gglCtx = ctx->gglCtx; const void * symbol = (void*)dlsym(RTLD_DEFAULT, name); if (NULL == symbol) { if (!strcmp(_PF2_TEXTURE_DATA_NAME_, name)) @@ -400,7 +400,7 @@ static void* SymbolLookup(void* pContext, const char* name) } static void CodeGen(Instance * instance, const char * mainName, gl_shader * shader, - gl_shader_program * program, const GGLContext * gglCtx) + gl_shader_program * program, const GGLState * gglCtx) { SymbolLookupContext ctx = {gglCtx, program, shader}; int result = 0; @@ -429,20 +429,11 @@ static void CodeGen(Instance * instance, const char * mainName, gl_shader * shad printf("bcc_compile %s=%p \n", mainName, instance->function); } -void GenerateScanLine(const GGLContext * gglCtx, const gl_shader_program * program, llvm::Module * mod, +void GenerateScanLine(const GGLState * gglCtx, const gl_shader_program * program, llvm::Module * mod, const char * shaderName, const char * scanlineName); -static void ShaderUse(GGLInterface * iface, gl_shader_program * program) +void GGLShaderUse(const GGLContext * gglCtx, void * llvmCtx, const GGLState * gglState, gl_shader_program * program) { - GGL_GET_CONST_CONTEXT(ctx, iface); - assert(program); - if (!program) { - ctx->glCtx->CurrentProgram = NULL; - // so drawing calls will do nothing until ShaderUse with a program - SetShaderVerifyFunctions(iface); - return; - } - for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { if (!program->_LinkedShaders[i]) continue; @@ -453,12 +444,12 @@ static void ShaderUse(GGLInterface * iface, gl_shader_program * program) } ShaderKey shaderKey; - GetShaderKey(ctx, shader, &shaderKey); + GetShaderKey(gglState, 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); + 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); @@ -468,18 +459,18 @@ static void ShaderUse(GGLInterface * iface, gl_shader_program * program) do_mat_op_to_vec(shader->ir); - llvm::Module * module = glsl_ir_to_llvm_module(shader->ir, instance->module, ctx, shaderName); + llvm::Module * module = glsl_ir_to_llvm_module(shader->ir, instance->module, gglState, shaderName); if (!module) assert(0); #if USE_LLVM_SCANLINE if (GL_FRAGMENT_SHADER == shader->Type) { char scanlineName [SCANLINE_KEY_STRING_LEN] = {0}; GetScanlineKeyString(&shaderKey, scanlineName, sizeof scanlineName / sizeof *scanlineName); - GenerateScanLine(ctx, program, module, mainName, scanlineName); - CodeGen(instance, scanlineName, shader, program, ctx); + GenerateScanLine(gglState, program, module, mainName, scanlineName); + CodeGen(instance, scanlineName, shader, program, gglState); } else #endif - CodeGen(instance, mainName, shader, program, ctx); + CodeGen(instance, mainName, shader, program, gglState); shader->executable->instances[shaderKey] = instance; debug_printf("jit new shader '%s'(%p) \n", mainName, instance->function); } else @@ -488,54 +479,70 @@ static void ShaderUse(GGLInterface * iface, gl_shader_program * program) shader->function = instance->function; - if (GL_VERTEX_SHADER == shader->Type) - ctx->PickRaster(iface); - else if (GL_FRAGMENT_SHADER == shader->Type) - ctx->PickScanLine(iface); - else - assert(0); + if (gglCtx) + if (GL_VERTEX_SHADER == shader->Type) + gglCtx->PickRaster((GGLInterface *)gglCtx); + else if (GL_FRAGMENT_SHADER == shader->Type) + gglCtx->PickScanLine((GGLInterface *)gglCtx); + else + assert(0); } - - ctx->glCtx->CurrentProgram = program; } -static void ShaderProgramDelete(const GGLInterface * iface, gl_shader_program * program) +static void ShaderUse(GGLInterface * iface, gl_shader_program * program) { - GGL_GET_CONST_CONTEXT(ctx, iface); - if (ctx->glCtx->CurrentProgram == program) { - ctx->glCtx->CurrentProgram = NULL; - SetShaderVerifyFunctions(const_cast<GGLInterface *>(iface)); + GGL_GET_CONTEXT(ctx, iface); + assert(program); + if (!program) { + ctx->CurrentProgram = NULL; + // so drawing calls will do nothing until ShaderUse with a program + SetShaderVerifyFunctions(iface); + return; } + GGLShaderUse(ctx, ctx->llvmCtx, &ctx->state, program); + + ctx->CurrentProgram = program; +} + +void GGLShaderProgramDelete(gl_shader_program * program) +{ for (unsigned i = 0; i < program->NumShaders; i++) { - iface->ShaderDelete(iface, program->Shaders[i]); - iface->ShaderDetach(iface, program, program->Shaders[i]); + GGLShaderDelete(program->Shaders[i]); + GGLShaderDetach(program, program->Shaders[i]); } for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) - iface->ShaderDelete(iface, program->_LinkedShaders[i]); + GGLShaderDelete(program->_LinkedShaders[i]); } -static void ShaderAttributeBind(const GGLInterface * iface, const gl_shader_program * program, - GLuint index, const GLchar * name) +static void ShaderProgramDelete(GGLInterface * iface, gl_shader_program * program) +{ + GGL_GET_CONTEXT(ctx, iface); + if (ctx->CurrentProgram == program) { + ctx->CurrentProgram = NULL; + SetShaderVerifyFunctions(const_cast<GGLInterface *>(iface)); + } + + GGLShaderProgramDelete(program); +} + +void GGLShaderAttributeBind(const gl_shader_program * program, GLuint index, const GLchar * name) { - GGL_GET_CONST_CONTEXT(ctx, iface); int i = _mesa_add_parameter(program->Attributes, name); program->Attributes->Parameters[i].BindLocation = index; } -static GLint ShaderAttributeLocation(const GGLInterface * iface, const gl_shader_program * program, - const char * name) +GLint GGLShaderAttributeLocation(const gl_shader_program * program, const char * name) { - GGL_GET_CONST_CONTEXT(ctx, iface); int i = _mesa_get_parameter(program->Attributes, name); if (i >= 0) return program->Attributes->Parameters[i].Location; return -1; } -static GLint ShaderVaryingLocation(const GGLInterface_t * iface, const gl_shader_program_t * program, - const char * name, GLint * vertexOutputLocation) +GLint GGLShaderVaryingLocation(const gl_shader_program_t * program, + const char * name, GLint * vertexOutputLocation) { for (unsigned int i = 0; i < program->Varying->NumParameters; i++) if (!strcmp(program->Varying->Parameters[i].Name, name)) { @@ -546,8 +553,8 @@ static GLint ShaderVaryingLocation(const GGLInterface_t * iface, const gl_shader return -1; } -static GLint ShaderUniformLocation(const GGLInterface * iface, const gl_shader_program * program, - const char * name) +GLint GGLShaderUniformLocation(const gl_shader_program * program, + const char * name) { for (unsigned i = 0; i < program->Uniforms->NumUniforms; i++) if (!strcmp(program->Uniforms->Uniforms[i].Name, name)) @@ -555,26 +562,23 @@ static GLint ShaderUniformLocation(const GGLInterface * iface, const gl_shader_p return -1; } -static void ShaderUniformGetfv(const GGLInterface * iface, gl_shader_program * program, - GLint location, GLfloat * params) +void GGLShaderUniformGetfv(gl_shader_program * program, GLint location, GLfloat * params) { memcpy(params, program->ValuesUniform + location, sizeof(*program->ValuesUniform)); } -static void ShaderUniformGetiv(const GGLInterface * iface, gl_shader_program * program, - GLint location, GLint * params) +void GGLShaderUniformGetiv(gl_shader_program * program, GLint location, GLint * params) { // TODO: sampler uniform - GGL_GET_CONST_CONTEXT(ctx, iface); memcpy(params, program->ValuesUniform + location, sizeof(*program->ValuesUniform)); } -static GLint ShaderUniform(const GGLInterface * iface, gl_shader_program * program, - GLint location, GLsizei count, const GLvoid *values, GLenum type) +GLint GGLShaderUniform(gl_shader_program * program, GLint location, GLsizei count, + const GLvoid *values, GLenum type) { // TODO: sampler uniform if (!program) { - gglError(GL_INVALID_OPERATION); + //gglError(GL_INVALID_OPERATION); return -2; } int start = location; @@ -616,9 +620,8 @@ static GLint ShaderUniform(const GGLInterface * iface, gl_shader_program * progr return start; } -static void ShaderUniformMatrix(const GGLInterface * iface, gl_shader_program * program, - GLint cols, GLint rows, GLint location, GLsizei count, - GLboolean transpose, const GLfloat *values) +void GGLShaderUniformMatrix(gl_shader_program * program, GLint cols, GLint rows, + GLint location, GLsizei count, GLboolean transpose, const GLfloat *values) { if (location == -1) return; @@ -637,8 +640,8 @@ static void ShaderVerifyProcessVertex(const GGLInterface * iface, const VertexIn VertexOutput * output) { GGL_GET_CONST_CONTEXT(ctx, iface); - if (ctx->glCtx->CurrentProgram) { - ShaderUse(const_cast<GGLInterface *>(iface), ctx->glCtx->CurrentProgram); + if (ctx->CurrentProgram) { + ShaderUse(const_cast<GGLInterface *>(iface), ctx->CurrentProgram); if (ShaderVerifyProcessVertex != iface->ProcessVertex) iface->ProcessVertex(iface, input, output); } @@ -648,8 +651,8 @@ static void ShaderVerifyDrawTriangle(const GGLInterface * iface, const VertexInp const VertexInput * v1, const VertexInput * v2) { GGL_GET_CONST_CONTEXT(ctx, iface); - if (ctx->glCtx->CurrentProgram) { - ShaderUse(const_cast<GGLInterface *>(iface), ctx->glCtx->CurrentProgram); + if (ctx->CurrentProgram) { + ShaderUse(const_cast<GGLInterface *>(iface), ctx->CurrentProgram); if (ShaderVerifyDrawTriangle != iface->DrawTriangle) iface->DrawTriangle(iface, v0, v1, v2); } @@ -659,8 +662,8 @@ static void ShaderVerifyRasterTriangle(const GGLInterface * iface, const VertexO const VertexOutput * v2, const VertexOutput * v3) { GGL_GET_CONST_CONTEXT(ctx, iface); - if (ctx->glCtx->CurrentProgram) { - ShaderUse(const_cast<GGLInterface *>(iface), ctx->glCtx->CurrentProgram); + if (ctx->CurrentProgram) { + ShaderUse(const_cast<GGLInterface *>(iface), ctx->CurrentProgram); if (ShaderVerifyRasterTriangle != iface->RasterTriangle) iface->RasterTriangle(iface, v1, v2, v3); } @@ -671,8 +674,8 @@ static void ShaderVerifyRasterTrapezoid(const GGLInterface * iface, const Vertex const VertexOutput * br) { GGL_GET_CONST_CONTEXT(ctx, iface); - if (ctx->glCtx->CurrentProgram) { - ShaderUse(const_cast<GGLInterface *>(iface), ctx->glCtx->CurrentProgram); + if (ctx->CurrentProgram) { + ShaderUse(const_cast<GGLInterface *>(iface), ctx->CurrentProgram); if (ShaderVerifyRasterTrapezoid != iface->RasterTrapezoid) iface->RasterTrapezoid(iface, tl, tr, bl, br); } @@ -682,8 +685,8 @@ static void ShaderVerifyScanLine(const GGLInterface * iface, const VertexOutput const VertexOutput * v2) { GGL_GET_CONST_CONTEXT(ctx, iface); - if (ctx->glCtx->CurrentProgram) { - ShaderUse(const_cast<GGLInterface *>(iface), ctx->glCtx->CurrentProgram); + if (ctx->CurrentProgram) { + ShaderUse(const_cast<GGLInterface *>(iface), ctx->CurrentProgram); if (ShaderVerifyScanLine != iface->ScanLine) iface->ScanLine(iface, v1, v2); } @@ -727,9 +730,6 @@ static void InitializeGLContext(struct gl_context *ctx) ctx->Const.FragmentProgram.MaxUniformComponents = 64; ctx->Const.MaxDrawBuffers = 2; - - ctx->Driver.NewShader = _mesa_new_shader; - ctx->Driver.DeleteShader = _mesa_delete_shader; } void InitializeShaderFunctions(struct GGLInterface * iface) @@ -748,14 +748,14 @@ void InitializeShaderFunctions(struct GGLInterface * iface) iface->ShaderProgramLink = ShaderProgramLink; iface->ShaderUse = ShaderUse; iface->ShaderProgramDelete = ShaderProgramDelete; - iface->ShaderAttributeBind = ShaderAttributeBind; - iface->ShaderAttributeLocation = ShaderAttributeLocation; - iface->ShaderVaryingLocation = ShaderVaryingLocation; - iface->ShaderUniformLocation = ShaderUniformLocation; - iface->ShaderUniformGetfv = ShaderUniformGetfv; - iface->ShaderUniformGetiv = ShaderUniformGetiv; - iface->ShaderUniform = ShaderUniform; - iface->ShaderUniformMatrix = ShaderUniformMatrix; + iface->ShaderAttributeBind = GGLShaderAttributeBind; + iface->ShaderAttributeLocation = GGLShaderAttributeLocation; + iface->ShaderVaryingLocation = GGLShaderVaryingLocation; + iface->ShaderUniformLocation = GGLShaderUniformLocation; + iface->ShaderUniformGetfv = GGLShaderUniformGetfv; + iface->ShaderUniformGetiv = GGLShaderUniformGetiv; + iface->ShaderUniform = GGLShaderUniform; + iface->ShaderUniformMatrix = GGLShaderUniformMatrix; } void DestroyShaderFunctions(GGLInterface * iface) diff --git a/src/pixelflinger2/texture.cpp b/src/pixelflinger2/texture.cpp index 6d72ed2..0925f4e 100644 --- a/src/pixelflinger2/texture.cpp +++ b/src/pixelflinger2/texture.cpp @@ -392,31 +392,31 @@ static void SetSampler(GGLInterface * iface, const unsigned sampler, GGLTexture GGL_GET_CONTEXT(ctx, iface); if (!texture) SetShaderVerifyFunctions(iface); - else if (ctx->textureState.textures[sampler].format != texture->format) + else if (ctx->state.textureState.textures[sampler].format != texture->format) SetShaderVerifyFunctions(iface); - else if (ctx->textureState.textures[sampler].wrapS != texture->wrapS) + else if (ctx->state.textureState.textures[sampler].wrapS != texture->wrapS) SetShaderVerifyFunctions(iface); - else if (ctx->textureState.textures[sampler].wrapT != texture->wrapT) + else if (ctx->state.textureState.textures[sampler].wrapT != texture->wrapT) SetShaderVerifyFunctions(iface); - else if (ctx->textureState.textures[sampler].minFilter != texture->minFilter) + else if (ctx->state.textureState.textures[sampler].minFilter != texture->minFilter) SetShaderVerifyFunctions(iface); - else if (ctx->textureState.textures[sampler].magFilter != texture->magFilter) + else if (ctx->state.textureState.textures[sampler].magFilter != texture->magFilter) SetShaderVerifyFunctions(iface); if (texture) { - ctx->textureState.textures[sampler] = *texture; // shallow copy, data pointed to must remain valid - //ctx->textureState.textureData[sampler] = texture->levels[0]; - ctx->textureState.textureData[sampler] = texture->levels; - ctx->textureState.textureDimensions[sampler * 2] = texture->width; - ctx->textureState.textureDimensions[sampler * 2 + 1] = texture->height; + ctx->state.textureState.textures[sampler] = *texture; // shallow copy, data pointed to must remain valid + //ctx->state.textureState.textureData[sampler] = texture->levels[0]; + ctx->state.textureState.textureData[sampler] = texture->levels; + ctx->state.textureState.textureDimensions[sampler * 2] = texture->width; + ctx->state.textureState.textureDimensions[sampler * 2 + 1] = texture->height; } else { - memset(ctx->textureState.textures + sampler, 0, sizeof(ctx->textureState.textures[sampler])); - ctx->textureState.textureData[sampler] = NULL; - ctx->textureState.textureDimensions[sampler * 2] = 0; - ctx->textureState.textureDimensions[sampler * 2 + 1] = 0; + memset(ctx->state.textureState.textures + sampler, 0, sizeof(ctx->state.textureState.textures[sampler])); + ctx->state.textureState.textureData[sampler] = NULL; + ctx->state.textureState.textureDimensions[sampler * 2] = 0; + ctx->state.textureState.textureDimensions[sampler * 2 + 1] = 0; } } diff --git a/test/cmain.c b/test/cmain.c index 0ed9264..6271f2e 100644 --- a/test/cmain.c +++ b/test/cmain.c @@ -66,8 +66,8 @@ int cmain(int argc, char **argv) ggl->ShaderAttach(ggl, program0, shader0); ggl->ShaderAttach(ggl, program0, shader1); - ggl->ShaderAttributeBind(ggl, program0, 2, "aTexCoord"); - ggl->ShaderAttributeBind(ggl, program0, 3, "aPosition"); + ggl->ShaderAttributeBind(program0, 2, "aTexCoord"); + ggl->ShaderAttributeBind(program0, 3, "aPosition"); GLboolean linkStatus = ggl->ShaderProgramLink(ggl, program0, &infoLog); if (!linkStatus) @@ -82,7 +82,7 @@ int cmain(int argc, char **argv) texels0, 1, 2, 1, 1 }; // levels, wrapS, wrapT, minFilter, magFilter - int sampler2dLoc = ggl->ShaderUniformLocation(ggl, program0, "sampler2d"); + int sampler2dLoc = ggl->ShaderUniformLocation(program0, "sampler2d"); if (0 <= sampler2dLoc) { int samplerUnit = -1; //ggl->ShaderUniformGetiv(ggl, program0, sampler2dLoc, &samplerUnit); @@ -91,8 +91,8 @@ int cmain(int argc, char **argv) } Vector4 uVec4 = {1.125f, 1.5f, 1.75f, 1.75f}; - int uVec4Loc = ggl->ShaderUniformLocation(ggl, program0, "uVec4"); - ggl->ShaderUniform(ggl, program0, uVec4Loc, 1, &uVec4, GL_FLOAT_VEC4); + int uVec4Loc = ggl->ShaderUniformLocation(program0, "uVec4"); + ggl->ShaderUniform(program0, uVec4Loc, 1, &uVec4, GL_FLOAT_VEC4); VertexInput_t v0 = {0}; v0.attributes[2] = VECTOR4_CTR(0,0,1,1); // aTexCoord @@ -105,14 +105,14 @@ int cmain(int argc, char **argv) assert(0); } - int vTexCoordIndex = ggl->ShaderVaryingLocation(ggl, program0, "vTexCoord", NULL) - 2; + int vTexCoordIndex = ggl->ShaderVaryingLocation(program0, "vTexCoord", NULL) - 2; VECTOR4_OP_UNARY(vout0.varyings[vTexCoordIndex],-=,uVec4); if (memcmp(&vout0.varyings[vTexCoordIndex],&v0.attributes[2],sizeof uVec4)) { fprintf(stderr, "vTexCoord != aTexCoord + uVec4 \n"); assert(0); } Vector4 ones = {1,1,1,1}; - int vTexColorIndex = ggl->ShaderVaryingLocation(ggl, program0, "vTexColor", NULL) - 2; + int vTexColorIndex = ggl->ShaderVaryingLocation(program0, "vTexColor", NULL) - 2; if (memcmp(&vout0.varyings[vTexColorIndex],&ones,sizeof ones)) { // should be the last texel color fprintf(stderr, "vTexColor != Vector4(1,1,1,1) \n"); assert(0); diff --git a/test/main.cpp b/test/main.cpp index 29bb665..d51c6d9 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -71,8 +71,8 @@ gl_shader_program * init_shader() gl_shader_program * program = ggl->ShaderProgramCreate(ggl); // current scan_test assumes the following attribute layout - ggl->ShaderAttributeBind(ggl, program, 0, "aPosition"); - ggl->ShaderAttributeBind(ggl, program, 1, "aTexCoord"); + ggl->ShaderAttributeBind(program, 0, "aPosition"); + ggl->ShaderAttributeBind(program, 1, "aTexCoord"); puts("\n -- linking -- \n"); ggl->ShaderAttach(ggl, program, vertShader); @@ -191,9 +191,9 @@ void test_scan() _math_matrix_ctr(&m3); _math_matrix_ctr(&m4); - int uMatrixLoc = ggl->ShaderUniformLocation(ggl, program, "uMatrix"); - int uRotMLoc = ggl->ShaderUniformLocation(ggl, program, "uRotM"); - int uTLoc = ggl->ShaderUniformLocation(ggl, program, "t"); + int uMatrixLoc = ggl->ShaderUniformLocation(program, "uMatrix"); + int uRotMLoc = ggl->ShaderUniformLocation(program, "uRotM"); + int uTLoc = ggl->ShaderUniformLocation(program, "t"); GGLTexture cubeTexture = {GL_TEXTURE_CUBE_MAP, GGL_PIXEL_FORMAT_RGBA_8888, 1, 1, 1, NULL, 1, 2, 1, 1}; unsigned cubeTextureSurface [6] = {0xff0000ff, 0xff00ff00, 0xffff0000, @@ -202,9 +202,9 @@ void test_scan() void * levels [1] = {cubeTextureSurface}; cubeTexture.levels = levels; if (program) { - ggl->ShaderUniformMatrix(ggl, program, 4, 4, uMatrixLoc, 1, GL_FALSE, m0.m); - int sampler2dLoc = ggl->ShaderUniformLocation(ggl, program, "sampler2d"); - int samplercubeLoc = ggl->ShaderUniformLocation(ggl, program, "samplercube"); + ggl->ShaderUniformMatrix(program, 4, 4, uMatrixLoc, 1, GL_FALSE, m0.m); + int sampler2dLoc = ggl->ShaderUniformLocation(program, "sampler2d"); + int samplercubeLoc = ggl->ShaderUniformLocation(program, "samplercube"); int samplerUnit = -1; if (0 <= sampler2dLoc) { // set 2d texture to sampler if used samplerUnit = sampler2dLoc;//ggl->ShaderUniformGetiv(ggl, program, sampler2dLoc, &samplerUnit); @@ -314,9 +314,9 @@ void test_scan() float t = i * 0.6f; if (program) { - ggl->ShaderUniformMatrix(ggl, program, 4, 4, uMatrixLoc, 1, GL_FALSE, m4.m); - ggl->ShaderUniformMatrix(ggl, program, 4, 4, uRotMLoc, 1, GL_FALSE, m2.m); - ggl->ShaderUniform(ggl, program, uTLoc, 1, &t, GL_FLOAT); + ggl->ShaderUniformMatrix(program, 4, 4, uMatrixLoc, 1, GL_FALSE, m4.m); + ggl->ShaderUniformMatrix(program, 4, 4, uRotMLoc, 1, GL_FALSE, m2.m); + ggl->ShaderUniform(program, uTLoc, 1, &t, GL_FLOAT); } //ggl->EnableDisable(ggl, GL_BLEND, true); @@ -449,9 +449,11 @@ void test_scan() ggl = NULL; } +extern "C" int cmain(int,char**); int main (int argc, char * const argv[]) { + cmain(0,NULL); test_scan(); puts("mesa done"); return 0; |