diff options
author | David Li <davidxli@google.com> | 2011-02-11 17:03:20 -0800 |
---|---|---|
committer | David Li <davidxli@google.com> | 2011-02-11 17:03:20 -0800 |
commit | 8e399777f3d6c0e02a31af9e231e7547d3fdbb7d (patch) | |
tree | e32b3ff66bbf8482dc5f98c0b4af03cce2751798 | |
parent | 460ec7b491fedb70edd4a2a7437625b19450167e (diff) |
Fix make files, attribute & uniform linking and pow intrinsic.
Still more intrinsics to implement in src/glsl/builtins/ir.
Added experimental dual thread raster.
Change-Id: Ia5b2c794b552b31a437148274080ecac0e92fe56
Signed-off-by: David Li <davidxli@google.com>
-rw-r--r-- | Android.mk | 43 | ||||
-rw-r--r-- | CleanSpec.mk | 2 | ||||
-rw-r--r-- | include/pixelflinger2/pixelflinger2_interface.h | 11 | ||||
-rw-r--r-- | libMesa.project | 10 | ||||
-rw-r--r-- | src/glsl/builtin_function.cpp | 45 | ||||
-rw-r--r-- | src/glsl/builtins/ir/pow | 41 | ||||
-rwxr-xr-x | src/glsl/builtins/tools/generate_builtins.py | 19 | ||||
-rw-r--r-- | src/glsl/linker.cpp | 24 | ||||
-rw-r--r-- | src/glsl/main.cpp | 2 | ||||
-rw-r--r-- | src/mesa/main/shaderobj.c | 7 | ||||
-rw-r--r-- | src/pixelflinger2/raster.cpp | 166 | ||||
-rw-r--r-- | src/pixelflinger2/shader.cpp | 56 | ||||
-rw-r--r-- | test/Android.mk | 14 | ||||
-rw-r--r-- | test/mesa.project | 10 |
14 files changed, 322 insertions, 128 deletions
@@ -1,5 +1,3 @@ -ifeq (true,false) # disable everything - # USE_LLVM_EXECUTIONENGINE not fully implemented USE_LLVM_EXECUTIONENGINE := false # if using libLLVMExecutionEngine, @@ -117,6 +115,15 @@ libMesa_SRC_FILES := \ src/pixelflinger2/texture.cpp \ src/talloc/hieralloc.c +libMesa_C_INCLUDES := \ + $(LOCAL_PATH) \ + $(LOCAL_PATH)/src/glsl \ + $(LOCAL_PATH)/src/mesa \ + $(LOCAL_PATH)/src/talloc \ + $(LOCAL_PATH)/src/mapi \ + $(LOCAL_PATH)/include \ + frameworks/compile/libbcc/include + # Static library for host # ======================================================== include $(CLEAR_VARS) @@ -124,31 +131,23 @@ include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional ifeq ($(DEBUG_BUILD),true) -LOCAL_CPPFLAGS += -DDEBUG -UNDEBUG -O0 -g LOCAL_CFLAGS += -DDEBUG -UNDEBUG -O0 -g +else +LOCAL_CFLAGS += -O3 endif LOCAL_MODULE := libMesa LOCAL_SRC_FILES := $(libMesa_SRC_FILES) ifeq ($(USE_LLVM_EXECUTIONENGINE),true) -LOCAL_CPPFLAGS += -DUSE_LLVM_EXECUTIONENGINE=1 LOCAL_CFLAGS += -DUSE_LLVM_EXECUTIONENGINE=1 LOCAL_STATIC_LIBRARIES := libLLVMX86CodeGen libLLVMX86Info $(libMesa_STATIC_LIBS) else -LOCAL_CPPFLAGS += -DUSE_LLVM_EXECUTIONENGINE=0 LOCAL_CFLAGS += -DUSE_LLVM_EXECUTIONENGINE=0 LOCAL_SHARED_LIBRARIES := libbcc endif -LOCAL_C_INCLUDES := \ - $(LOCAL_PATH) \ - $(LOCAL_PATH)/src/glsl \ - $(LOCAL_PATH)/src/mesa \ - $(LOCAL_PATH)/src/talloc \ - $(LOCAL_PATH)/src/mapi \ - $(LOCAL_PATH)/include \ - $(LOCAL_PATH)/../libbcc/include +LOCAL_C_INCLUDES := $(libMesa_C_INCLUDES) include $(LLVM_ROOT_PATH)/llvm-host-build.mk include $(BUILD_HOST_STATIC_LIBRARY) @@ -162,8 +161,9 @@ include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional ifeq ($(DEBUG_BUILD),true) -LOCAL_CPPFLAGS += -DDEBUG -UNDEBUG -O0 -g -LOCAL_CFLAGS += -DDEBUG -UNDEBUG -O0 -g +LOCAL_CFLAGS += -DDEBUG -UNDEBUG -O0 -g +else +LOCAL_CFLAGS += -O3 endif LOCAL_MODULE := libMesa @@ -171,23 +171,14 @@ LOCAL_SRC_FILES := $(libMesa_SRC_FILES) LOCAL_SHARED_LIBRARIES := libstlport libcutils libdl libutils ifeq ($(USE_LLVM_EXECUTIONENGINE),true) -LOCAL_CPPFLAGS += -DUSE_LLVM_EXECUTIONENGINE=1 LOCAL_CFLAGS += -DUSE_LLVM_EXECUTIONENGINE=1 LOCAL_STATIC_LIBRARIES := libLLVMARMCodeGen libLLVMARMInfo libLLVMARMDisassembler libLLVMARMAsmPrinter $(libMesa_STATIC_LIBS) else -LOCAL_CPPFLAGS += -DUSE_LLVM_EXECUTIONENGINE=0 LOCAL_CFLAGS += -DUSE_LLVM_EXECUTIONENGINE=0 LOCAL_SHARED_LIBRARIES += libbcc endif -LOCAL_C_INCLUDES := \ - $(LOCAL_PATH) \ - $(LOCAL_PATH)/src/glsl \ - $(LOCAL_PATH)/src/mesa \ - $(LOCAL_PATH)/src/talloc \ - $(LOCAL_PATH)/src/mapi \ - $(LOCAL_PATH)/include \ - $(LOCAL_PATH)/../libbcc/include +LOCAL_C_INCLUDES := $(libMesa_C_INCLUDES) include $(LLVM_ROOT_PATH)/llvm-device-build.mk include $(BUILD_STATIC_LIBRARY) @@ -197,5 +188,3 @@ include $(BUILD_STATIC_LIBRARY) include $(call all-makefiles-under,$(LOCAL_PATH)) endif # TARGET_SIMULATOR != true - -endif # true != false diff --git a/CleanSpec.mk b/CleanSpec.mk index b84e1b6..93e143d 100644 --- a/CleanSpec.mk +++ b/CleanSpec.mk @@ -44,6 +44,8 @@ #$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f) #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*) +$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libMesa_intermediates) + # ************************************************ # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST # ************************************************ diff --git a/include/pixelflinger2/pixelflinger2_interface.h b/include/pixelflinger2/pixelflinger2_interface.h index 59f625e..99b18cf 100644 --- a/include/pixelflinger2/pixelflinger2_interface.h +++ b/include/pixelflinger2/pixelflinger2_interface.h @@ -267,10 +267,15 @@ struct GGLInterface { GLint location, GLfloat * params); void (* ShaderUniformGetiv)(gl_shader_program_t * program, GLint location, GLint * params); + + // retrieves the tmu each sampler is set to, sampler2tmu[sampler] == -1 means not used + void (* ShaderUniformGetSamplers)(const gl_shader_program_t * program, + int sampler2tmu[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS]); + // updates linked program uniform value by location; return >= 0 indicates sampler assigned 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)(gl_shader_program_t * program, GLint cols, GLint rows, GLint location, GLsizei count, @@ -327,6 +332,10 @@ extern "C" // gets uniform location for linked program GLint GGLShaderUniformLocation(const gl_shader_program_t * program, const char * name); + + // retrieves the tmu each sampler is set to, sampler2tmu[sampler] == -1 means not used + void GGLShaderUniformGetSamplers(const gl_shader_program_t * program, + int sampler2tmu[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS]); void GGLProcessVertex(const gl_shader_program_t * program, const VertexInput_t * input, VertexOutput_t * output, const float (*constants)[4]); diff --git a/libMesa.project b/libMesa.project index 28906fc..1ff6bcb 100644 --- a/libMesa.project +++ b/libMesa.project @@ -192,6 +192,7 @@ </VirtualDirectory> <Description/> <Dependencies/> + <Dependencies Name="Release"/> <Settings Type="Static Library"> <Configuration Name="Debug" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="Static Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append"> <Compiler Options="-D__STDC_LIMIT_MACROS;-D__STDC_CONSTANT_MACROS;-m32 -march=i686;-DDEBUG;-UNDEBUG;-O0;-g" Required="yes" PreCompiledHeader=""> @@ -199,10 +200,10 @@ <IncludePath Value="include/"/> <IncludePath Value="src/talloc/"/> <IncludePath Value="src/mapi/"/> - <IncludePath Value="../../../external/llvm/include"/> - <IncludePath Value="../../../external/llvm/host/include"/> - <IncludePath Value="../libbcc/include"/> - <IncludePath Value="../../base/opengl/include"/> + <IncludePath Value="../../external/llvm/include"/> + <IncludePath Value="../../external/llvm/host/include"/> + <IncludePath Value="../../frameworks/compile/libbcc/include"/> + <IncludePath Value="../../frameworks/base/opengl/include"/> </Compiler> <Linker Options="-m32 -lstdc++ -ldl -lpthread" Required="yes"> <LibraryPath Value="/home/davidxli/Desktop/android/master/out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMX86CodeGen_intermediates"/> @@ -289,5 +290,4 @@ </GlobalSettings> </Settings> <Dependencies Name="Debug"/> - <Dependencies Name="Release"/> </CodeLite_Project> diff --git a/src/glsl/builtin_function.cpp b/src/glsl/builtin_function.cpp index 1bfca3f..353bfaa 100644 --- a/src/glsl/builtin_function.cpp +++ b/src/glsl/builtin_function.cpp @@ -34,7 +34,7 @@ read_builtins(void * mem_ctx, GLenum target, const char *protos, const char **fu { struct gl_context fakeCtx; fakeCtx.API = API_OPENGL; - gl_shader *sh = _mesa_new_shader((gl_context *)mem_ctx, 0, target); + gl_shader *sh = _mesa_new_shader(mem_ctx, 0, target); struct _mesa_glsl_parse_state *st = new(sh) _mesa_glsl_parse_state(&fakeCtx, target, sh); @@ -60,7 +60,7 @@ read_builtins(void * mem_ctx, GLenum target, const char *protos, const char **fu if (st->error) { printf("error reading builtin: %.35s ...\n", functions[i]); printf("Info log:\n%s\n", st->info_log); - hieralloc_free(sh); + _mesa_delete_shader(NULL, sh); return NULL; } } @@ -2458,21 +2458,42 @@ static const char builtin_pow[] = "\n" " (signature vec2\n" " (parameters\n" - " (declare (in) vec2 arg0)\n" - " (declare (in) vec2 arg1))\n" - " ((return (expression vec2 pow (var_ref arg0) (var_ref arg1)))))\n" + " (declare (in) vec2 b)\n" + " (declare (in) vec2 e))\n" + " (\n" + " (declare () vec2 ret)\n" + " (assign (constant bool (1)) (x) (var_ref ret) (call pow ((swiz x (var_ref b)) (swiz x (var_ref e)) )))\n" + " (assign (constant bool (1)) (y) (var_ref ret) (call pow ((swiz y (var_ref b)) (swiz y (var_ref e)) )))\n" + " (return (var_ref ret))\n" + " )\n" + " )\n" "\n" " (signature vec3\n" " (parameters\n" - " (declare (in) vec3 arg0)\n" - " (declare (in) vec3 arg1))\n" - " ((return (expression vec3 pow (var_ref arg0) (var_ref arg1)))))\n" + " (declare (in) vec3 b)\n" + " (declare (in) vec3 e))\n" + " (\n" + " (declare () vec3 ret)\n" + " (assign (constant bool (1)) (x) (var_ref ret) (call pow ((swiz x (var_ref b)) (swiz x (var_ref e)) )))\n" + " (assign (constant bool (1)) (y) (var_ref ret) (call pow ((swiz y (var_ref b)) (swiz y (var_ref e)) )))\n" + " (assign (constant bool (1)) (z) (var_ref ret) (call pow ((swiz z (var_ref b)) (swiz z (var_ref e)) )))\n" + " (return (var_ref ret))\n" + " )\n" + " )\n" "\n" - " (signature vec4\n" + " (signature vec4\n" " (parameters\n" - " (declare (in) vec4 arg0)\n" - " (declare (in) vec4 arg1))\n" - " ((return (expression vec4 pow (var_ref arg0) (var_ref arg1)))))\n" + " (declare (in) vec4 b)\n" + " (declare (in) vec4 e))\n" + " (\n" + " (declare () vec4 ret)\n" + " (assign (constant bool (1)) (x) (var_ref ret) (call pow ((swiz x (var_ref b)) (swiz x (var_ref e)) )))\n" + " (assign (constant bool (1)) (y) (var_ref ret) (call pow ((swiz y (var_ref b)) (swiz y (var_ref e)) )))\n" + " (assign (constant bool (1)) (z) (var_ref ret) (call pow ((swiz z (var_ref b)) (swiz z (var_ref e)) )))\n" + " (assign (constant bool (1)) (w) (var_ref ret) (call pow ((swiz w (var_ref b)) (swiz w (var_ref e)) )))\n" + " (return (var_ref ret))\n" + " )\n" + " )\n" "))\n" "" ; diff --git a/src/glsl/builtins/ir/pow b/src/glsl/builtins/ir/pow index a61bc44..08dfc67 100644 --- a/src/glsl/builtins/ir/pow +++ b/src/glsl/builtins/ir/pow @@ -7,19 +7,40 @@ (signature vec2 (parameters - (declare (in) vec2 arg0) - (declare (in) vec2 arg1)) - ((return (expression vec2 pow (var_ref arg0) (var_ref arg1))))) + (declare (in) vec2 b) + (declare (in) vec2 e)) + ( + (declare () vec2 ret) + (assign (constant bool (1)) (x) (var_ref ret) (call pow ((swiz x (var_ref b)) (swiz x (var_ref e)) ))) + (assign (constant bool (1)) (y) (var_ref ret) (call pow ((swiz y (var_ref b)) (swiz y (var_ref e)) ))) + (return (var_ref ret)) + ) + ) (signature vec3 (parameters - (declare (in) vec3 arg0) - (declare (in) vec3 arg1)) - ((return (expression vec3 pow (var_ref arg0) (var_ref arg1))))) + (declare (in) vec3 b) + (declare (in) vec3 e)) + ( + (declare () vec3 ret) + (assign (constant bool (1)) (x) (var_ref ret) (call pow ((swiz x (var_ref b)) (swiz x (var_ref e)) ))) + (assign (constant bool (1)) (y) (var_ref ret) (call pow ((swiz y (var_ref b)) (swiz y (var_ref e)) ))) + (assign (constant bool (1)) (z) (var_ref ret) (call pow ((swiz z (var_ref b)) (swiz z (var_ref e)) ))) + (return (var_ref ret)) + ) + ) - (signature vec4 + (signature vec4 (parameters - (declare (in) vec4 arg0) - (declare (in) vec4 arg1)) - ((return (expression vec4 pow (var_ref arg0) (var_ref arg1))))) + (declare (in) vec4 b) + (declare (in) vec4 e)) + ( + (declare () vec4 ret) + (assign (constant bool (1)) (x) (var_ref ret) (call pow ((swiz x (var_ref b)) (swiz x (var_ref e)) ))) + (assign (constant bool (1)) (y) (var_ref ret) (call pow ((swiz y (var_ref b)) (swiz y (var_ref e)) ))) + (assign (constant bool (1)) (z) (var_ref ret) (call pow ((swiz z (var_ref b)) (swiz z (var_ref e)) ))) + (assign (constant bool (1)) (w) (var_ref ret) (call pow ((swiz w (var_ref b)) (swiz w (var_ref e)) ))) + (return (var_ref ret)) + ) + ) )) diff --git a/src/glsl/builtins/tools/generate_builtins.py b/src/glsl/builtins/tools/generate_builtins.py index 5ea4b5c..0506c42 100755 --- a/src/glsl/builtins/tools/generate_builtins.py +++ b/src/glsl/builtins/tools/generate_builtins.py @@ -128,21 +128,18 @@ if __name__ == "__main__": */ #include <stdio.h> -#include "main/core.h" /* for struct gl_shader */ +#include "main/shaderobj.h" /* for struct gl_shader */ #include "glsl_parser_extras.h" #include "ir_reader.h" #include "program.h" #include "ast.h" -extern "C" struct gl_shader * -_mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type); - gl_shader * -read_builtins(GLenum target, const char *protos, const char **functions, unsigned count) +read_builtins(void * mem_ctx, GLenum target, const char *protos, const char **functions, unsigned count) { struct gl_context fakeCtx; fakeCtx.API = API_OPENGL; - gl_shader *sh = _mesa_new_shader(NULL, 0, target); + gl_shader *sh = _mesa_new_shader(mem_ctx, 0, target); struct _mesa_glsl_parse_state *st = new(sh) _mesa_glsl_parse_state(&fakeCtx, target, sh); @@ -168,7 +165,7 @@ read_builtins(GLenum target, const char *protos, const char **functions, unsigne if (st->error) { printf("error reading builtin: %.35s ...\\n", functions[i]); printf("Info log:\\n%s\\n", st->info_log); - talloc_free(sh); + _mesa_delete_shader(NULL, sh); return NULL; } } @@ -193,7 +190,7 @@ void *builtin_mem_ctx = NULL; void _mesa_glsl_release_functions(void) { - talloc_free(builtin_mem_ctx); + hieralloc_free(builtin_mem_ctx); builtin_mem_ctx = NULL; memset(builtin_profiles, 0, sizeof(builtin_profiles)); } @@ -209,8 +206,8 @@ _mesa_read_profile(struct _mesa_glsl_parse_state *state, gl_shader *sh = builtin_profiles[profile_index]; if (sh == NULL) { - sh = read_builtins(GL_VERTEX_SHADER, prototypes, functions, count); - talloc_steal(builtin_mem_ctx, sh); + sh = read_builtins(state, GL_VERTEX_SHADER, prototypes, functions, count); + hieralloc_steal(builtin_mem_ctx, sh); builtin_profiles[profile_index] = sh; } @@ -223,7 +220,7 @@ _mesa_glsl_initialize_functions(exec_list *instructions, struct _mesa_glsl_parse_state *state) { if (builtin_mem_ctx == NULL) { - builtin_mem_ctx = talloc_init("GLSL built-in functions"); + builtin_mem_ctx = hieralloc_init("GLSL built-in functions"); memset(&builtin_profiles, 0, sizeof(builtin_profiles)); } diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp index e8f1497..14d1050 100644 --- a/src/glsl/linker.cpp +++ b/src/glsl/linker.cpp @@ -1355,13 +1355,6 @@ assign_attribute_locations(gl_shader_program *prog, unsigned max_attribute_index if (0 <= paramIndex) prog->Attributes->Parameters[paramIndex].Location = location; } - - for (int i = sizeof(used_locations) * 8 - 1; i >= 0; i--) - if (used_locations & (1 << i)) - { - prog->AttributeSlots = i + 1; - break; - } return true; } @@ -1685,6 +1678,13 @@ link_shaders(const struct gl_context *ctx, struct gl_shader_program *prog) prog->LinkStatus = false; goto done; } + prog->AttributeSlots = 0; + for (unsigned i = 0; i < prog->Attributes->NumParameters; i++) + { + const gl_program_parameter & param = prog->Attributes->Parameters[i]; + if (param.Location + param.Slots > prog->AttributeSlots) + prog->AttributeSlots = param.Location + param.Slots; + } } unsigned prev; @@ -1746,6 +1746,16 @@ link_shaders(const struct gl_context *ctx, struct gl_shader_program *prog) prog->ValuesVertexOutput = (float (*)[4])((unsigned long)prog->ValuesVertexInput + sizeof(VertexInput)); prog->ValuesUniform = (float (*)[4])((unsigned long)prog->ValuesVertexOutput + sizeof(VertexOutput)); + // default mapping of tmu to sampler + for (unsigned i = 0; i < prog->Uniforms->NumUniforms; i++) + { + const gl_uniform & uniform = prog->Uniforms->Uniforms[i]; + if (uniform.Type->is_sampler()) + prog->ValuesUniform[uniform.Pos][0] = uniform.Pos; + else if (uniform.Type->is_array() && uniform.Type->fields.array->is_sampler()) + assert(0); + } + done: free(vert_shader_list); diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp index 2267902..c51ee9a 100644 --- a/src/glsl/main.cpp +++ b/src/glsl/main.cpp @@ -42,7 +42,7 @@ #include "src/pixelflinger2/pixelflinger2.h" static int dump_ast = 0; -static int dump_hir = 1; +static int dump_hir = 0; static int dump_lir = 0; extern "C" void diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c index b01bef4..d9913cc 100644 --- a/src/mesa/main/shaderobj.c +++ b/src/mesa/main/shaderobj.c @@ -3,7 +3,8 @@ #include <GLES2/gl2.h> -#include <src/mesa/main/mtypes.h> +#include "src/mesa/main/mtypes.h" +#include "src/talloc/hieralloc.h" void _mesa_reference_shader(const void * ctx, struct gl_shader **ptr, struct gl_shader *sh) @@ -20,8 +21,6 @@ struct gl_shader * _mesa_new_shader(const void * ctx, GLuint name, GLenum type) shader->Name = name; shader->RefCount = 1; } - if (!ctx) - watches[watch++] = shader; return shader; } @@ -34,4 +33,4 @@ void _mesa_delete_shader(const void * ctx, struct gl_shader *shader) return; } hieralloc_free(shader); -}
\ No newline at end of file +} diff --git a/src/pixelflinger2/raster.cpp b/src/pixelflinger2/raster.cpp index 74fdc19..eeee8e7 100644 --- a/src/pixelflinger2/raster.cpp +++ b/src/pixelflinger2/raster.cpp @@ -54,7 +54,7 @@ static inline void InterpolateVertex(const VertexOutput * a, const VertexOutput } void GGLProcessVertex(const gl_shader_program * program, const VertexInput * input, - VertexOutput * output, const float (*constants)[4]) + VertexOutput * output, const float (*constants)[4]) { ShaderFunction_t function = (ShaderFunction_t)program->_LinkedShaders[MESA_SHADER_VERTEX]->function; function(input, output, constants); @@ -74,7 +74,7 @@ static void ProcessVertex(const GGLInterface * iface, const VertexInput * input, // memcpy(ctx->glCtx->CurrentProgram->ValuesVertexInput, input, sizeof(*input)); // ctx->glCtx->CurrentProgram->_LinkedShaders[MESA_SHADER_VERTEX]->function(); // memcpy(output, ctx->glCtx->CurrentProgram->ValuesVertexOutput, sizeof(*output)); - + GGLProcessVertex(ctx->CurrentProgram, input, output, ctx->CurrentProgram->ValuesUniform); // const Vector4 * constants = (Vector4 *) // ctx->glCtx->Shader.CurrentProgram->VertexProgram->Parameters->ParameterValues; @@ -85,6 +85,60 @@ static void ProcessVertex(const GGLInterface * iface, const VertexInput * input, //#endif } +#include <pthread.h> + +struct WorkerArgs { + const GGLInterface * iface; + unsigned startY, endY, varyingCount; + VertexOutput bV, cV, bDx, cDx; + int width, height; + volatile bool hasWork; + bool quit; + + static void * RasterTrapezoidWorker(void * threadArgs) { + WorkerArgs * args = (WorkerArgs *)threadArgs; + VertexOutput clip0, clip1, * left, * right; + while (!args->quit) { + if (!args->hasWork) + continue; + for (unsigned y = args->startY; y <= args->endY; y += 2) { + do { + if (args->bV.position.x < 0) { + if (args->cV.position.x < 0) + break; + InterpolateVertex(&args->bV, &args->cV, -args->bV.position.x / + (args->cV.position.x - args->bV.position.x), + &clip0, args->varyingCount); + left = &clip0; + } else + left = &args->bV; + if ((int)args->cV.position.x >= (int)args->width) { + if (args->bV.position.x >= (int)args->width) + break; + InterpolateVertex(&args->bV, &args->cV, (args->width - 1 - args->bV.position.x) / + (args->cV.position.x - args->bV.position.x), + &clip1, args->varyingCount); + right = &clip1; + } else + right = &args->cV; + args->iface->ScanLine(args->iface, left, right); + } while (false); + for (unsigned i = 0; i < args->varyingCount; i++) { + args->bV.varyings[i] += args->bDx.varyings[i]; + args->cV.varyings[i] += args->cDx.varyings[i]; + } + args->bV.position += args->bDx.position; + args->cV.position += args->cDx.position; + args->bV.frontFacingPointCoord += args->bDx.frontFacingPointCoord; + args->cV.frontFacingPointCoord += args->cDx.frontFacingPointCoord; + } + args->hasWork = false; + } + pthread_exit(NULL); + return NULL; + } +}; + static void RasterTrapezoid(const GGLInterface * iface, const VertexOutput * tl, const VertexOutput * tr, const VertexOutput * bl, const VertexOutput * br) @@ -125,27 +179,27 @@ static void RasterTrapezoid(const GGLInterface * iface, const VertexOutput * tl, brv = tmp; } - // horizontally clip - if ((int)tlv.position.x < 0) { - InterpolateVertex(&tlv, &trv, (0 - tlv.position.x) / (trv.position.x - tlv.position.x), - &tmp, varyingCount); - tlv = tmp; - } - if ((int)blv.position.x < 0) { - InterpolateVertex(&blv, &brv, (0 - blv.position.x) / (brv.position.x - blv.position.x), - &tmp, varyingCount); - blv = tmp; - } - if ((int)trv.position.x >= (int)width) { - InterpolateVertex(&tlv, &trv, (width - 1 - tlv.position.x) / (trv.position.x - tlv.position.x), - &tmp, varyingCount); - trv = tmp; - } - if ((int)brv.position.x >= (int)width) { - InterpolateVertex(&blv, &brv, (width - 1 - blv.position.x) / (brv.position.x - blv.position.x), - &tmp, varyingCount); - brv = tmp; - } +// // horizontally clip +// if ((int)tlv.position.x < 0) { +// InterpolateVertex(&tlv, &trv, (0 - tlv.position.x) / (trv.position.x - tlv.position.x), +// &tmp, varyingCount); +// tlv = tmp; +// } +// if ((int)blv.position.x < 0) { +// InterpolateVertex(&blv, &brv, (0 - blv.position.x) / (brv.position.x - blv.position.x), +// &tmp, varyingCount); +// blv = tmp; +// } +// if ((int)trv.position.x >= (int)width) { +// InterpolateVertex(&tlv, &trv, (width - 1 - tlv.position.x) / (trv.position.x - tlv.position.x), +// &tmp, varyingCount); +// trv = tmp; +// } +// if ((int)brv.position.x >= (int)width) { +// InterpolateVertex(&blv, &brv, (width - 1 - blv.position.x) / (brv.position.x - blv.position.x), +// &tmp, varyingCount); +// brv = tmp; +// } const unsigned int startY = tlv.position.y; const unsigned int endY = blv.position.y; @@ -182,8 +236,67 @@ static void RasterTrapezoid(const GGLInterface * iface, const VertexOutput * tl, cDx.frontFacingPointCoord *= yDistInv; cDx.frontFacingPointCoord.y = VectorComp_t_Zero; // gl_FrontFacing not interpolated - for (unsigned y = startY; y <= endY; y++) { - iface->ScanLine(iface, &bV, &cV); + static WorkerArgs args; // TODO: fix this static + +#define DUAL_THREAD 1 + +#if DUAL_THREAD + static pthread_t thread; + if (!thread) { + int rc = pthread_create(&thread, NULL, WorkerArgs::RasterTrapezoidWorker, &args); + assert(!rc); + } + args.bV = bV; + args.cV = cV; + for (unsigned i = 0; i < varyingCount; i++) { + args.bV.varyings[i] += bDx.varyings[i]; + bDx.varyings[i] += bDx.varyings[i]; + args.cV.varyings[i] += cDx.varyings[i]; + cDx.varyings[i] += cDx.varyings[i]; + } + args.bV.position += bDx.position; + bDx.position += bDx.position; + args.cV.position += cDx.position; + cDx.position += cDx.position; + args.bV.frontFacingPointCoord += bDx.frontFacingPointCoord; + bDx.frontFacingPointCoord += bDx.frontFacingPointCoord; + args.cV.frontFacingPointCoord += cDx.frontFacingPointCoord; + cDx.frontFacingPointCoord += cDx.frontFacingPointCoord; + args.iface = iface; + args.bDx = bDx; + args.cDx = cDx; + args.varyingCount = varyingCount; + args.startY = startY + 1; + args.endY = endY; + args.width = width; + args.height = height; + if (args.startY <= args.endY) + args.hasWork = true; +#endif + + VertexOutput * left, * right; + VertexOutput clip0, clip1; + + for (unsigned y = startY; y <= endY; y += 1 + DUAL_THREAD) { + do { + if (bV.position.x < 0) { + if (cV.position.x < 0) + break; + InterpolateVertex(&bV, &cV, -bV.position.x / (cV.position.x - bV.position.x), + &clip0, varyingCount); + left = &clip0; + } else + left = &bV; + if ((int)cV.position.x >= (int)width) { + if (bV.position.x >= (int)width) + break; + InterpolateVertex(&bV, &cV, (width - 1 - bV.position.x) / (cV.position.x - bV.position.x), + &clip1, varyingCount); + right = &clip1; + } else + right = &cV; + iface->ScanLine(iface, left, right); + } while (false); for (unsigned i = 0; i < varyingCount; i++) { bV.varyings[i] += bDx.varyings[i]; cV.varyings[i] += cDx.varyings[i]; @@ -193,6 +306,9 @@ static void RasterTrapezoid(const GGLInterface * iface, const VertexOutput * tl, bV.frontFacingPointCoord += bDx.frontFacingPointCoord; cV.frontFacingPointCoord += cDx.frontFacingPointCoord; } + + while (args.hasWork) + ; // wait } static void RasterTriangle(const GGLInterface * iface, const VertexOutput * v1, diff --git a/src/pixelflinger2/shader.cpp b/src/pixelflinger2/shader.cpp index 0762617..629d90b 100644 --- a/src/pixelflinger2/shader.cpp +++ b/src/pixelflinger2/shader.cpp @@ -257,6 +257,7 @@ GLboolean GGLShaderProgramLink(gl_shader_program * program, const char ** infoLo *infoLog = program->InfoLog; if (!program->LinkStatus) return program->LinkStatus; + printf("slots: attribute=%d varying=%d uniforms=%d \n", program->AttributeSlots, program->VaryingSlots, program->Uniforms->Slots); 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); @@ -577,10 +578,10 @@ void GGLShaderProgramGetiv(gl_shader_program_t * program, const GLenum pname, GL *params = program->NumShaders; break; case GL_ACTIVE_ATTRIBUTES: - *params = program->Attributes->NumParameters; + *params = program->AttributeSlots; break; case GL_ACTIVE_UNIFORMS: - *params = program->Uniforms->NumUniforms; + *params = program->Uniforms->Slots; break; case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: case GL_ACTIVE_UNIFORM_MAX_LENGTH: @@ -622,30 +623,55 @@ GLint GGLShaderUniformLocation(const gl_shader_program * program, { for (unsigned i = 0; i < program->Uniforms->NumUniforms; i++) if (!strcmp(program->Uniforms->Uniforms[i].Name, name)) - return program->Uniforms->Uniforms[i].Pos; + return i; return -1; } void GGLShaderUniformGetfv(gl_shader_program * program, GLint location, GLfloat * params) { - memcpy(params, program->ValuesUniform + location, sizeof(*program->ValuesUniform)); + assert(0 <= location && program->Uniforms->NumUniforms > location); + int index = program->Uniforms->Uniforms[location].Pos; + assert(0 <= index && program->Uniforms->Slots > index); + memcpy(params, program->ValuesUniform + index, sizeof(*program->ValuesUniform)); } void GGLShaderUniformGetiv(gl_shader_program * program, GLint location, GLint * params) { - // TODO: sampler uniform - memcpy(params, program->ValuesUniform + location, sizeof(*program->ValuesUniform)); + assert(0 <= location && program->Uniforms->NumUniforms > location); + int index = program->Uniforms->Uniforms[location].Pos; + assert(0 <= index && program->Uniforms->Slots > index); + const float * uniform = program->ValuesUniform[index]; + params[0] = uniform[0]; + params[1] = uniform[1]; + params[2] = uniform[2]; + params[3] = uniform[3]; +} + +void GGLShaderUniformGetSamplers(const gl_shader_program_t * program, + int sampler2tmu[GGL_MAXCOMBINEDTEXTUREIMAGEUNITS]) +{ + memset(sampler2tmu, 0xff, sizeof sampler2tmu); + for (unsigned i = 0; i < program->Uniforms->NumUniforms; i++) + { + const gl_uniform & uniform = program->Uniforms->Uniforms[i]; + if (uniform.Type->is_sampler()) + sampler2tmu[uniform.Pos] = program->ValuesUniform[i][0]; + else if (uniform.Type->is_array() && uniform.Type->fields.array->is_sampler()) + assert(0); + } } GLint GGLShaderUniform(gl_shader_program * program, GLint location, GLsizei count, const GLvoid *values, GLenum type) { - // TODO: sampler uniform + // TODO: sampler uniform and type checking if (!program) { //gglError(GL_INVALID_OPERATION); return -2; } - int start = location; + assert(0 <= location && program->Uniforms->NumUniforms > location); + const gl_uniform & unifrom = program->Uniforms->Uniforms[location]; + int start = unifrom.Pos; int slots = 0, elems = 0; switch (type) { case GL_INT: @@ -676,12 +702,16 @@ GLint GGLShaderUniform(gl_shader_program * program, GLint location, GLsizei coun assert(0); } if (0 < start) - return -1; + return -2; if (start + slots > program->Uniforms->Slots) - return -1; + return -2; for (int i = 0; i < slots; i++) memcpy(program->ValuesUniform + start + i, values, elems * sizeof(float)); - return start; + if (unifrom.Type->is_sampler()) + return program->ValuesUniform[start][0]; + else if (unifrom.Type->is_array() && unifrom.Type->fields.array->is_sampler()) + assert(0); + return -2; } void GGLShaderUniformMatrix(gl_shader_program * program, GLint cols, GLint rows, @@ -690,7 +720,8 @@ void GGLShaderUniformMatrix(gl_shader_program * program, GLint cols, GLint rows, if (location == -1) return; assert(cols == rows); - int start = location; + assert(0 <= location && program->Uniforms->NumUniforms > location); + int start = program->Uniforms->Uniforms[location].Pos; unsigned slots = cols * count; if (start < 0 || start + slots > program->Uniforms->Slots) return gglError(GL_INVALID_OPERATION); @@ -790,6 +821,7 @@ void InitializeShaderFunctions(struct GGLInterface * iface) iface->ShaderUniformLocation = GGLShaderUniformLocation; iface->ShaderUniformGetfv = GGLShaderUniformGetfv; iface->ShaderUniformGetiv = GGLShaderUniformGetiv; + iface->ShaderUniformGetSamplers = GGLShaderUniformGetSamplers; iface->ShaderUniform = GGLShaderUniform; iface->ShaderUniformMatrix = GGLShaderUniformMatrix; } diff --git a/test/Android.mk b/test/Android.mk index 4776c3d..da5dc6e 100644 --- a/test/Android.mk +++ b/test/Android.mk @@ -11,6 +11,10 @@ mesa_SRC_FILES := \ m_matrix.c \ main.cpp +mesa_C_INCLUDES := \ + $(LOCAL_PATH) \ + $(LOCAL_PATH)/../include + # Executable for host # ======================================================== include $(CLEAR_VARS) @@ -18,7 +22,6 @@ include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional ifeq ($(DEBUG_BUILD),true) -LOCAL_CPPFLAGS += -DDEBUG -UNDEBUG -O0 -g LOCAL_CFLAGS += -DDEBUG -UNDEBUG -O0 -g endif @@ -26,9 +29,7 @@ LOCAL_MODULE := mesa LOCAL_SRC_FILES := $(mesa_SRC_FILES) LOCAL_STATIC_LIBRARIES := libMesa LOCAL_SHARED_LIBRARIES := libbcc -LOCAL_C_INCLUDES := \ - $(LOCAL_PATH) \ - frameworks/compile/mesa/include +LOCAL_C_INCLUDES := $(mesa_C_INCLUDES) include $(LLVM_ROOT_PATH)/llvm-host-build.mk include $(BUILD_HOST_EXECUTABLE) @@ -41,7 +42,6 @@ include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional ifeq ($(DEBUG_BUILD),true) -LOCAL_CPPFLAGS += -DDEBUG -UNDEBUG -O0 -g LOCAL_CFLAGS += -DDEBUG -UNDEBUG -O0 -g endif @@ -49,9 +49,7 @@ LOCAL_MODULE := mesa LOCAL_SRC_FILES := $(mesa_SRC_FILES) LOCAL_STATIC_LIBRARIES := libMesa LOCAL_SHARED_LIBRARIES := libstlport libcutils libutils libhardware libsurfaceflinger_client libbcc libdl -LOCAL_C_INCLUDES := \ - $(LOCAL_PATH) \ - frameworks/compile/mesa/include +LOCAL_C_INCLUDES := $(mesa_C_INCLUDES) include $(LLVM_ROOT_PATH)/llvm-device-build.mk include $(BUILD_EXECUTABLE) diff --git a/test/mesa.project b/test/mesa.project index d0ecf6b..c486ddd 100644 --- a/test/mesa.project +++ b/test/mesa.project @@ -16,16 +16,13 @@ <File Name="m_matrix.h"/> </VirtualDirectory> <Dependencies Name="Release"/> - <Dependencies Name="Debug"> - <Project Name="libMesa"/> - </Dependencies> <Settings Type="Executable"> <Configuration Name="Debug" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append"> <Compiler Options="-D__STDC_LIMIT_MACROS;-D__STDC_CONSTANT_MACROS;-m32 -march=i686;-DDEBUG;-UNDEBUG;-O0;-g" Required="yes" PreCompiledHeader=""> <IncludePath Value="."/> <IncludePath Value="../include/"/> - <IncludePath Value="../../../base/opengl/include"/> - <IncludePath Value="../../../../external/llvm/include"/> + <IncludePath Value="../../../frameworks/base/opengl/include"/> + <IncludePath Value="../../../external/llvm/include"/> </Compiler> <Linker Options="-m32 -lstdc++ -ldl -lpthread -lbcc" Required="yes"> <LibraryPath Value="../Debug"/> @@ -92,4 +89,7 @@ <ResourceCompiler Options=""/> </GlobalSettings> </Settings> + <Dependencies Name="Debug"> + <Project Name="libMesa"/> + </Dependencies> </CodeLite_Project> |