diff options
author | David Li <davidxli@google.com> | 2011-01-31 15:21:03 -0800 |
---|---|---|
committer | David Li <davidxli@google.com> | 2011-01-31 15:21:03 -0800 |
commit | 3b02c91d7b1fcc777dbdafeb044e0df61e1ff0d8 (patch) | |
tree | 2513b75b541f1beab5cc2edda393f909cb12243e | |
parent | 36ffccf19c02a54a6dc9952dc9c181d4fda2a020 (diff) |
Fix hieralloc_realloc bug, and prepare for attributes list.
Signed-off-by: David Li <davidxli@google.com>
-rw-r--r-- | Android.mk | 19 | ||||
-rw-r--r-- | egl.cpp | 28 | ||||
-rw-r--r-- | include/pixelflinger2/pixelflinger2_format.h | 73 | ||||
-rw-r--r-- | src/glsl/glsl_parser_extras.cpp | 2 | ||||
-rw-r--r-- | src/glsl/glsl_symbol_table.cpp | 8 | ||||
-rw-r--r-- | src/glsl/glsl_symbol_table.h | 3 | ||||
-rw-r--r-- | src/glsl/linker.cpp | 8 | ||||
-rw-r--r-- | src/glsl/main.cpp | 80 | ||||
-rw-r--r-- | src/mesa/program/prog_parameter.h | 3 | ||||
-rw-r--r-- | src/pixelflinger2/format.cpp | 54 | ||||
-rw-r--r-- | src/pixelflinger2/pixelflinger2.h | 3 | ||||
-rw-r--r-- | src/talloc/hieralloc.c | 193 | ||||
-rw-r--r-- | src/talloc/hieralloc.h | 9 |
13 files changed, 393 insertions, 90 deletions
@@ -105,6 +105,7 @@ mesa_SRC_FILES := \ src/mesa/program/hash_table.c \ src/mesa/program/symbol_table.c \ src/pixelflinger2/buffer.cpp \ + src/pixelflinger2/format.cpp \ src/pixelflinger2/pixelflinger2.cpp \ src/pixelflinger2/raster.cpp \ src/pixelflinger2/scanline.cpp \ @@ -125,10 +126,12 @@ LOCAL_MODULE := mesa LOCAL_SRC_FILES := $(mesa_SRC_FILES) ifeq ($(USE_LLVM_EXECUTIONENGINE),true) -LOCAL_CPPFLAGS += -DUSE_LLVM_EXECUTIONENGINE -LOCAL_CFLAGS += -DUSE_LLVM_EXECUTIONENGINE +LOCAL_CPPFLAGS += -DUSE_LLVM_EXECUTIONENGINE=1 +LOCAL_CFLAGS += -DUSE_LLVM_EXECUTIONENGINE=1 LOCAL_STATIC_LIBRARIES := libLLVMX86CodeGen libLLVMX86Info $(mesa_STATIC_LIBS) else +LOCAL_CPPFLAGS += -DUSE_LLVM_EXECUTIONENGINE=0 +LOCAL_CFLAGS += -DUSE_LLVM_EXECUTIONENGINE=0 LOCAL_SHARED_LIBRARIES := libbcc endif @@ -169,16 +172,18 @@ LOCAL_SHARED_LIBRARIES := libstlport libcutils libdl LOCAL_SRC_FILES += egl.cpp #libutils libhardware libsurfaceflinger_client libpixelflinger # libsurfaceflinger_client and libpixelflinger causes hieralloc assertion -LOCAL_SHARED_LIBRARIES += libutils libhardware libsurfaceflinger_client libpixelflinger +LOCAL_SHARED_LIBRARIES += libutils libhardware libsurfaceflinger_client LOCAL_CPPFLAGS += -DDRAW_TO_SCREEN=1 -LOCAL_CFLAGS += -fvisibility=hidden -LOCAL_CPPFLAGS += -fvisibility=hidden +#LOCAL_CFLAGS += -fvisibility=hidden +#LOCAL_CPPFLAGS += -fvisibility=hidden ifeq ($(USE_LLVM_EXECUTIONENGINE),true) -LOCAL_CPPFLAGS += -DUSE_LLVM_EXECUTIONENGINE -LOCAL_CFLAGS += -DUSE_LLVM_EXECUTIONENGINE +LOCAL_CPPFLAGS += -DUSE_LLVM_EXECUTIONENGINE=1 +LOCAL_CFLAGS += -DUSE_LLVM_EXECUTIONENGINE=1 LOCAL_STATIC_LIBRARIES := libLLVMARMCodeGen libLLVMARMInfo libLLVMARMDisassembler libLLVMARMAsmPrinter $(mesa_STATIC_LIBS) else +LOCAL_CPPFLAGS += -DUSE_LLVM_EXECUTIONENGINE=0 +LOCAL_CFLAGS += -DUSE_LLVM_EXECUTIONENGINE=0 LOCAL_SHARED_LIBRARIES += libbcc endif @@ -1917,9 +1917,12 @@ EGLBoolean eglSetSwapRectangleANDROID(EGLDisplay dpy, EGLSurface draw, return EGL_TRUE; } -sp<SurfaceComposerClient> client; -sp<SurfaceControl> surfaceControl; -sp<Surface> surface; +static struct S +{ + sp<SurfaceComposerClient> client; + sp<SurfaceControl> surfaceControl; + sp<Surface> surface; +} * s = NULL; ANativeWindow * window; EGLDisplay display; EGLContext eglCtx; @@ -1927,16 +1930,17 @@ EGLSurface drawSurface; extern "C" int SetupDrawingSurface(unsigned * width, unsigned * height, unsigned * bpp) { + s = new S; // create a client to surfaceflinger - client = new SurfaceComposerClient(); + s->client = new SurfaceComposerClient(); - surfaceControl = client->createSurface(getpid(), 0, 1280, 800, PIXEL_FORMAT_RGBA_8888); - client->openTransaction(); - surfaceControl->setLayer(25000); - client->closeTransaction(); + s->surfaceControl = s->client->createSurface(getpid(), 0, 1280, 800, PIXEL_FORMAT_RGBA_8888); + s->client->openTransaction(); + s->surfaceControl->setLayer(25000); + s->client->closeTransaction(); - surface = surfaceControl->getSurface(); - window = surface.get(); + s->surface = s->surfaceControl->getSurface(); + window = s->surface.get(); printf("window=%p\n", window); @@ -1995,8 +1999,12 @@ extern "C" void * PresentDrawingSurface() extern "C" void DisposeDrawingSurface() { + puts("DisposeDrawingSurface"); eglDestroySurface(display, drawSurface); eglDestroyContext(display, eglCtx); + delete s; + s = NULL; + puts("DisposeDrawingSurface"); } diff --git a/include/pixelflinger2/pixelflinger2_format.h b/include/pixelflinger2/pixelflinger2_format.h index f582cb5..3bffee5 100644 --- a/include/pixelflinger2/pixelflinger2_format.h +++ b/include/pixelflinger2/pixelflinger2_format.h @@ -17,6 +17,9 @@ #ifndef _PIXELFLINGER2_FORMAT_H_ #define _PIXELFLINGER2_FORMAT_H_ +#include <stdint.h> +#include <sys/types.h> + enum GGLPixelFormat { // these constants need to match those // in graphics/PixelFormat.java, ui/PixelFormat.h, BlitHardware.h @@ -63,4 +66,74 @@ enum GGLPixelFormat { GGL_PIXEL_FORMAT_COUNT = 0xFF }; +enum GGLFormatComponents { + GGL_STENCIL_INDEX = 0x1901, + GGL_DEPTH_COMPONENT = 0x1902, + GGL_ALPHA = 0x1906, + GGL_RGB = 0x1907, + GGL_RGBA = 0x1908, + GGL_LUMINANCE = 0x1909, + GGL_LUMINANCE_ALPHA = 0x190A, +}; + +enum GGLFormatComponentIndex { + GGL_INDEX_ALPHA = 0, + GGL_INDEX_RED = 1, + GGL_INDEX_GREEN = 2, + GGL_INDEX_BLUE = 3, + GGL_INDEX_STENCIL = 0, + GGL_INDEX_DEPTH = 1, + GGL_INDEX_Y = 0, + GGL_INDEX_CB = 1, + GGL_INDEX_CR = 2, +}; + +typedef struct { +#ifdef __cplusplus + enum { + ALPHA = GGL_INDEX_ALPHA, + RED = GGL_INDEX_RED, + GREEN = GGL_INDEX_GREEN, + BLUE = GGL_INDEX_BLUE, + STENCIL = GGL_INDEX_STENCIL, + DEPTH = GGL_INDEX_DEPTH, + LUMA = GGL_INDEX_Y, + CHROMAB = GGL_INDEX_CB, + CHROMAR = GGL_INDEX_CR, + }; + inline uint32_t mask(int i) const { + return ((1<<(c[i].h-c[i].l))-1)<<c[i].l; + } + inline uint32_t bits(int i) const { + return c[i].h - c[i].l; + } +#endif + uint8_t size; // bytes per pixel + uint8_t bitsPerPixel; + union { + struct { + uint8_t ah; // alpha high bit position + 1 + uint8_t al; // alpha low bit position + uint8_t rh; // red high bit position + 1 + uint8_t rl; // red low bit position + uint8_t gh; // green high bit position + 1 + uint8_t gl; // green low bit position + uint8_t bh; // blue high bit position + 1 + uint8_t bl; // blue low bit position + }; + struct { + uint8_t h; + uint8_t l; + } __attribute__((__packed__)) c[4]; + } __attribute__((__packed__)); + uint16_t components; // GGLFormatComponents +} GGLFormat; + + +#ifdef __cplusplus +extern "C" const GGLFormat* gglGetPixelFormatTable(size_t* numEntries = 0); +#else +const GGLFormat* gglGetPixelFormatTable(size_t* numEntries); +#endif + #endif // _PIXELFLINGER2_FORMAT_H_ diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp index 88d9bde..174ff47 100644 --- a/src/glsl/glsl_parser_extras.cpp +++ b/src/glsl/glsl_parser_extras.cpp @@ -47,7 +47,7 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *ctx, this->scanner = NULL; this->translation_unit.make_empty(); - this->symbols = new(mem_ctx) glsl_symbol_table; + this->symbols = new(mem_ctx) glsl_symbol_table(mem_ctx); this->info_log = hieralloc_strdup(mem_ctx, ""); this->error = false; this->loop_or_switch_nesting = NULL; diff --git a/src/glsl/glsl_symbol_table.cpp b/src/glsl/glsl_symbol_table.cpp index bcc2ca6..6602857 100644 --- a/src/glsl/glsl_symbol_table.cpp +++ b/src/glsl/glsl_symbol_table.cpp @@ -51,19 +51,19 @@ public: ir_variable *v; ir_function *f; const glsl_type *t; -}; +}; -glsl_symbol_table::glsl_symbol_table() +glsl_symbol_table::glsl_symbol_table(void * ctx) { this->language_version = 120; this->table = _mesa_symbol_table_ctor(); - this->mem_ctx = hieralloc_init("symbol table entries"); + this->mem_ctx = hieralloc_allocate(ctx, 0, "symbol table entries"); } glsl_symbol_table::~glsl_symbol_table() { _mesa_symbol_table_dtor(table); - hieralloc_free(mem_ctx); + //hieralloc_free(mem_ctx); parent context free will free this } void glsl_symbol_table::push_scope() diff --git a/src/glsl/glsl_symbol_table.h b/src/glsl/glsl_symbol_table.h index 1f8921e..0004875 100644 --- a/src/glsl/glsl_symbol_table.h +++ b/src/glsl/glsl_symbol_table.h @@ -63,7 +63,6 @@ public: assert(table != NULL); hieralloc_set_destructor(table, (int (*)(void*)) _glsl_symbol_table_destructor); - return table; } @@ -76,7 +75,7 @@ public: hieralloc_free(table); } - glsl_symbol_table(); + glsl_symbol_table(void * mem_ctx); ~glsl_symbol_table(); unsigned int language_version; diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp index ac216e6..57bf4dd 100644 --- a/src/glsl/linker.cpp +++ b/src/glsl/linker.cpp @@ -323,7 +323,7 @@ cross_validate_globals(struct gl_shader_program *prog, /* Examine all of the uniforms in all of the shaders and cross validate * them. */ - glsl_symbol_table variables; + glsl_symbol_table variables(prog); for (unsigned i = 0; i < num_shaders; i++) { if (shader_list[i] == NULL) continue; @@ -449,7 +449,7 @@ bool cross_validate_outputs_to_inputs(struct gl_shader_program *prog, gl_shader *producer, gl_shader *consumer) { - glsl_symbol_table parameters; + glsl_symbol_table parameters(prog); /* FINISHME: Figure these out dynamically. */ const char *const producer_stage = "vertex"; const char *const consumer_stage = "fragment"; @@ -570,7 +570,7 @@ cross_validate_outputs_to_inputs(struct gl_shader_program *prog, static void populate_symbol_table(gl_shader *sh) { - sh->symbols = new(sh) glsl_symbol_table; + sh->symbols = new(sh) glsl_symbol_table(sh); foreach_list(node, sh->ir) { ir_instruction *const inst = (ir_instruction *) node; @@ -1487,7 +1487,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) if (prog->InfoLog != NULL) hieralloc_free(prog->InfoLog); - prog->InfoLog = hieralloc_strdup(NULL, ""); + prog->InfoLog = hieralloc_strdup(prog, ""); /* Separate the shaders into groups based on their type. */ diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp index 3364ee1..a4262c1 100644 --- a/src/glsl/main.cpp +++ b/src/glsl/main.cpp @@ -258,7 +258,7 @@ compile_shader(struct gl_context *ctx, struct gl_shader *shader) return; } -//#define DRAW_TO_SCREEN 1 +#define DRAW_TO_SCREEN 1 #include "image_file.h" #if defined __arm__ && defined DRAW_TO_SCREEN @@ -276,11 +276,12 @@ void execute(void (* function)(), gl_shader * shader) assert(32 == bpp); unsigned * frameSurface = (unsigned *)PresentDrawingSurface(); #else - const unsigned width = 480, height = 800; + const unsigned width = 1280, height = 800; unsigned * frameSurface = new unsigned [width * height]; #endif //const unsigned scale = 16, portWidth = 80, portHeight = 50; - unsigned scale = 1, portWidth = width, portHeight = height; + //unsigned scale = 1, portWidth = width / scale, portHeight = height / scale; + unsigned scale = 1, portWidth = width / 4, portHeight = height / 4; float * data = (float *)shader->Source; float * constants = data + 36; @@ -381,7 +382,7 @@ void execute(void (* function)(), gl_shader * shader) printf ("\n *** test_scan elapsed CPU time: %fs \n *** fps=%.2f, tpf=%.2fms \n", elapsed, frames / elapsed, elapsed / frames * 1000); printf("gl_FragColor=%.2f, %.2f, %.2f %.2f \n", outputs[0], outputs[1], outputs[2], outputs[3]); - assert(0.1f < outputs[3]); + //assert(0.1f < outputs[3]); #if defined __arm__ SaveBMP("/sdcard/mesa.bmp", frameSurface, width, height); #else @@ -550,7 +551,8 @@ void jit(llvm::Module * mod, gl_shader * shader) else printf("bcc_compile %s=%p \n", "main", function); - execute(function, shader); + if (GL_FRAGMENT_SHADER == shader->Type) + execute(function, shader); shader->Source = NULL; shader->Program = NULL; @@ -563,23 +565,27 @@ main(int argc, char **argv) { static char basePath [256] = {0}; static char texturePath [256] = {0}; - static char shaderPath [256] = {0}; + static char fragPath [256] = {0}; + static char vertPath [256] = {0}; static char cubeTexturePath [256] = {0}; - static const char shaderFile[] = "fs.frag"; + static const char fragFile[] = "fs.frag"; + static const char vertFile[] = "vs.vert"; static const char textureFile[] = "android.tga"; static const char cubeTextureFile[] = "cube.tga"; strncpy(basePath, argv[0], strrchr(argv[0], '/') - argv[0] + 1); - strcpy(shaderPath, basePath); - strcat(shaderPath, shaderFile); + strcpy(fragPath, basePath); + strcat(fragPath, fragFile); + strcpy(vertPath, basePath); + strcat(vertPath, vertFile); strcpy(texturePath, basePath); strcat(texturePath, textureFile); strcpy(cubeTexturePath, basePath); strcat(cubeTexturePath, cubeTextureFile); //* if (1 == argc) { - argc = 6; - const char * args [] = {argv[0], "--dump-hir", "--do-jit", "--link", "--glsl-es", shaderPath}; + const char * args [] = {argv[0], "--dump-hir", "--do-jit", "--link", "--glsl-es", fragPath, vertPath}; + argc = sizeof(args) / sizeof(*args); argv = (char **)args; } //*/ @@ -602,7 +608,8 @@ main(int argc, char **argv) whole_program = hieralloc_zero (NULL, struct gl_shader_program); assert(whole_program != NULL); - + whole_program->Attributes = hieralloc_zero(whole_program, gl_program_parameter_list); + for (/* empty */; argc > optind; optind++) { whole_program->Shaders = (struct gl_shader **) hieralloc_realloc(whole_program, whole_program->Shaders, @@ -641,8 +648,46 @@ main(int argc, char **argv) status = EXIT_FAILURE; break; } + + if (GL_VERTEX_SHADER == shader->Type) + { + gl_program_parameter_list * attributes = whole_program->Attributes; + foreach_list(node, shader->ir) { + ir_variable *const var = ((ir_instruction *) node)->as_variable(); + if ((var == NULL) || (var->mode != ir_var_in)) + continue; + bool exists = false; + for (unsigned i = 0; i < attributes->NumParameters; i++) + if (!strcmp(var->name, attributes->Parameters[i].Name)) + { + exists = true; + break; + } + if (exists) + continue; + + unsigned vec4_slots = 0; + if (var->type->is_array()) + vec4_slots = var->type->length * var->type->fields.array->matrix_columns; + else + vec4_slots = var->type->matrix_columns; + + attributes->NumParameters++; + attributes->Parameters = hieralloc_realloc(attributes, attributes->Parameters, + gl_program_parameter, attributes->NumParameters); + + gl_program_parameter * attribute = attributes->Parameters + attributes->NumParameters - 1; + memset(attribute, 0, sizeof(*attribute)); + attribute->Name = hieralloc_strdup(attributes->Parameters, var->name); + attribute->ExplicitLocation = -1; + attribute->Location = -1; + attribute->Slots = vec4_slots; + } + } } + puts("link"); + if ((status == EXIT_SUCCESS) && do_link) { link_shaders(ctx, whole_program); status = (whole_program->LinkStatus) ? EXIT_SUCCESS : EXIT_FAILURE; @@ -671,7 +716,6 @@ main(int argc, char **argv) struct gl_shader *shader = whole_program->_LinkedShaders[i]; if (!shader) continue; - // TODO: fix add_uniform for sampler location for (unsigned i = 0; i < whole_program->Uniforms->NumUniforms; i++) { const gl_uniform & uniform = whole_program->Uniforms->Uniforms[i]; @@ -681,6 +725,11 @@ main(int argc, char **argv) assert(var->location >= 0); printf("uniform '%s': location=%d type=%s \n", uniform.Name, uniform.FragPos, uniform.Type->name); } + for (unsigned i = 0; i < whole_program->Attributes->NumParameters; i++) + { + const gl_program_parameter & attribute = whole_program->Attributes->Parameters[i]; + printf("attribute '%s': location=%d slots=%d \n", attribute.Name, attribute.Location, attribute.Slots); + } ir_variable * sampler = NULL; if ((sampler = shader->symbols->get_variable("samp2D")) && sampler->location >= 0) ggl->SetSampler(ggl, sampler->location, &texture); @@ -701,20 +750,21 @@ main(int argc, char **argv) puts("\n *** Module for JIT *** \n"); //module->dump(); jit(module, shader); + puts("jitted"); } free(texture.levels); DestroyGGLInterface((GGLInterface *)ggl); - for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) hieralloc_free(whole_program->_LinkedShaders[i]); hieralloc_free(whole_program); + _mesa_glsl_release_types(); _mesa_glsl_release_functions(); - puts("mesa exit"); + printf("mesa exit(%d) \n", status); hieralloc_report_brief(NULL, stdout); return status; } diff --git a/src/mesa/program/prog_parameter.h b/src/mesa/program/prog_parameter.h index 10cbbe5..46df4a1 100644 --- a/src/mesa/program/prog_parameter.h +++ b/src/mesa/program/prog_parameter.h @@ -64,6 +64,9 @@ struct gl_program_parameter * The next program parameter's Size will be Size-4 of this parameter. */ GLuint Size; + GLuint Slots; /**< how many slots occupied */ + GLint ExplicitLocation; /**< for attributes, set by BindAttribLocation */ + GLint Location; /**< actual location assigned after linking */ GLboolean Initialized; /**< debug: Has the ParameterValue[] been set? */ GLbitfield Flags; /**< Bitmask of PROG_PARAM_*_BIT */ /** diff --git a/src/pixelflinger2/format.cpp b/src/pixelflinger2/format.cpp new file mode 100644 index 0000000..a7348ad --- /dev/null +++ b/src/pixelflinger2/format.cpp @@ -0,0 +1,54 @@ +#include <pixelflinger2/pixelflinger2_format.h> + +static GGLFormat const gPixelFormatInfos[] = +{ // Alpha Red Green Blue + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + { 4, 32, {{32,24, 8, 0, 16, 8, 24,16 }}, GGL_RGBA }, // PIXEL_FORMAT_RGBA_8888 + { 4, 24, {{ 0, 0, 8, 0, 16, 8, 24,16 }}, GGL_RGB }, // PIXEL_FORMAT_RGBX_8888 + {0},//{ 3, 24, {{ 0, 0, 8, 0, 16, 8, 24,16 }}, GGL_RGB }, // PIXEL_FORMAT_RGB_888 + { 2, 16, {{ 0, 0, 16,11, 11, 5, 5, 0 }}, GGL_RGB }, // PIXEL_FORMAT_RGB_565 + { 4, 32, {{32,24, 24,16, 16, 8, 8, 0 }}, GGL_RGBA }, // PIXEL_FORMAT_BGRA_8888 + { 2, 16, {{ 1, 0, 16,11, 11, 6, 6, 1 }}, GGL_RGBA }, // PIXEL_FORMAT_RGBA_5551 + { 2, 16, {{ 4, 0, 16,12, 12, 8, 8, 4 }}, GGL_RGBA }, // PIXEL_FORMAT_RGBA_4444 + { 1, 8, {{ 8, 0, 0, 0, 0, 0, 0, 0 }}, GGL_ALPHA}, // PIXEL_FORMAT_A8 + { 1, 8, {{ 0, 0, 8, 0, 8, 0, 8, 0 }}, GGL_LUMINANCE},//PIXEL_FORMAT_L8 + { 2, 16, {{16, 8, 8, 0, 8, 0, 8, 0 }}, GGL_LUMINANCE_ALPHA},// PIXEL_FORMAT_LA_88 + { 1, 8, {{ 0, 0, 8, 5, 5, 2, 2, 0 }}, GGL_RGB }, // PIXEL_FORMAT_RGB_332 + + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + + { 2, 16, {{ 0, 0, 16, 0, 0, 0, 0, 0 }}, GGL_DEPTH_COMPONENT}, + { 1, 8, {{ 8, 0, 0, 0, 0, 0, 0, 0 }}, GGL_STENCIL_INDEX }, + { 4, 24, {{ 0, 0, 24, 0, 0, 0, 0, 0 }}, GGL_DEPTH_COMPONENT}, + { 4, 8, {{ 32,24, 0, 0, 0, 0, 0, 0 }}, GGL_STENCIL_INDEX }, + { 4, 8, {{ 0, 0, 32, 0, 0, 0, 0, 0 }}, GGL_STENCIL_INDEX }, // PIXEL_FORMAT_Z32 + + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + { 0, 0, {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0 }, // PIXEL_FORMAT_NONE + +}; + +const GGLFormat* gglGetPixelFormatTable(size_t* numEntries) +{ + if (numEntries) { + *numEntries = sizeof(gPixelFormatInfos)/sizeof(GGLFormat); + } + return gPixelFormatInfos; +}
\ No newline at end of file diff --git a/src/pixelflinger2/pixelflinger2.h b/src/pixelflinger2/pixelflinger2.h index 5b9aa1d..e78890b 100644 --- a/src/pixelflinger2/pixelflinger2.h +++ b/src/pixelflinger2/pixelflinger2.h @@ -20,7 +20,10 @@ #define USE_LLVM_TEXTURE_SAMPLER 1 #define USE_LLVM_SCANLINE 1 + +#ifndef USE_LLVM_EXECUTIONENGINE #define USE_LLVM_EXECUTIONENGINE 0 // 1 to use llvm::Execution, 0 to use libBCC, requires modifying makefile +#endif #define debug_printf printf diff --git a/src/talloc/hieralloc.c b/src/talloc/hieralloc.c index f63351a..48b8179 100644 --- a/src/talloc/hieralloc.c +++ b/src/talloc/hieralloc.c @@ -1,12 +1,17 @@ /* * Similar core function to LGPL licensed talloc from Samba */ +#define CHECK_ALLOCATION 0 #include "hieralloc.h" #include <stdlib.h> #include <string.h> #include <assert.h> +#if CHECK_ALLOCATION +#include <set> +#endif + typedef struct hieralloc_header { unsigned beginMagic; @@ -22,18 +27,32 @@ typedef struct hieralloc_header #define BEGIN_MAGIC() (13377331) #define END_MAGIC(header) ((unsigned)((const hieralloc_header_t *)header + 1) % 0x10000 | 0x13370000) -static hieralloc_header_t global_hieralloc_header = {BEGIN_MAGIC(), 0, 0, 0, 0, "hieralloc_global_hieralloc_header", 0, 0 ,1, 0, 0x13370000}; +static hieralloc_header_t hieralloc_global_header = {BEGIN_MAGIC(), 0, 0, 0, 0, "hieralloc_hieralloc_global_header", 0, 0 ,1, 0, 0x13370000}; + +#if CHECK_ALLOCATION +static std::set<void *> allocations; +#endif +#ifdef __cplusplus +extern "C" { +#endif + // Returns 1 if it's a valid header static inline int check_header(const hieralloc_header_t * header) { + if (BEGIN_MAGIC() != header->beginMagic) + printf("*** hieralloc check_header fail: %p ***\n", header + 1); assert(BEGIN_MAGIC() == header->beginMagic); - if (&global_hieralloc_header == header) + if (&hieralloc_global_header == header) { assert(0x13370000 == header->endMagic); return 1; } assert(END_MAGIC(header) == header->endMagic); + assert(!header->nextSibling || header->nextSibling->prevSibling == header); + assert(!header->nextSibling || header->nextSibling->parent == header->parent); + assert(!header->prevSibling || header->prevSibling->nextSibling == header); + assert(!header->prevSibling || header->prevSibling->parent == header->parent); return 1; } @@ -44,6 +63,21 @@ static inline hieralloc_header_t * get_header(const void *ptr) return header; } +static void check_children(hieralloc_header_t * header) +{ + check_header(header); + unsigned childCount = 0; + hieralloc_header_t * child = header->child; + while (child) + { + childCount++; + check_children(child); + child = child->nextSibling; + } + assert(childCount == header->childCount); +} + + // attach to parent and siblings static void add_to_parent(hieralloc_header_t * parent, hieralloc_header_t * header) { @@ -52,12 +86,25 @@ static void add_to_parent(hieralloc_header_t * parent, hieralloc_header_t * head assert(NULL == header->nextSibling); if (parent->child) + { +// hieralloc_header_t * child = parent->child; +// while (child) +// { +// assert(child != header); +// child = child->nextSibling; +// } parent->child->prevSibling = header; + } header->nextSibling = parent->child; header->prevSibling = NULL; header->parent = parent; parent->child = header; parent->childCount++; + + assert(!header->nextSibling || header->nextSibling->prevSibling == header); + assert(!header->nextSibling || header->nextSibling->parent == header->parent); + assert(!header->prevSibling || header->prevSibling->nextSibling == header); + assert(!header->prevSibling || header->prevSibling->parent == header->parent); } // detach from parent and siblings @@ -65,6 +112,10 @@ static void remove_from_parent(hieralloc_header_t * header) { hieralloc_header_t * parent = header->parent; hieralloc_header_t * sibling = header->prevSibling; + assert(!header->nextSibling || header->nextSibling->prevSibling == header); + assert(!header->nextSibling || header->nextSibling->parent == header->parent); + assert(!header->prevSibling || header->prevSibling->nextSibling == header); + assert(!header->prevSibling || header->prevSibling->parent == header->parent); if (sibling) { if (sibling->nextSibling != header) @@ -72,8 +123,6 @@ static void remove_from_parent(hieralloc_header_t * header) printf("&sibling->nextSibling=%p &header=%p \n", &sibling->nextSibling, &header); printf("sibling->nextSibling=%p header=%p \n", sibling->nextSibling, header); } - // TODO: assert breaks on device linking with some libsurfaceflinger_client and libpixelflinger - //assert(sibling->nextSibling == header); sibling->nextSibling = header->nextSibling; if (header->nextSibling) header->nextSibling->prevSibling = sibling; @@ -82,6 +131,7 @@ static void remove_from_parent(hieralloc_header_t * header) } else { + assert(parent->child == header); parent->child = header->nextSibling; if (header->nextSibling) header->nextSibling->prevSibling = NULL; @@ -94,7 +144,7 @@ static void remove_from_parent(hieralloc_header_t * header) // allocate memory and attach to parent context and siblings void * hieralloc_allocate(const void * context, unsigned size, const char * name) { - hieralloc_header_t * ptr = malloc(size + sizeof(hieralloc_header_t)); + hieralloc_header_t * ptr = (hieralloc_header_t *)malloc(size + sizeof(hieralloc_header_t)); assert(ptr); memset(ptr, 0xcd, sizeof(*ptr)); ptr->beginMagic = BEGIN_MAGIC(); @@ -108,12 +158,14 @@ void * hieralloc_allocate(const void * context, unsigned size, const char * name hieralloc_header_t * parent = NULL; if (!context) - parent = &global_hieralloc_header; + parent = &hieralloc_global_header; else parent = get_header(context); - check_header(parent); - add_to_parent(parent, ptr); +#if CHECK_ALLOCATION + assert(allocations.find(ptr + 1) == allocations.end()); + allocations.insert(ptr + 1); +#endif return ptr + 1; } @@ -122,13 +174,11 @@ void * hieralloc_reallocate(const void * context, void * ptr, unsigned size, con { if (NULL == ptr) return hieralloc_allocate(context, size, name); - - int reparented = 0; +#if CHECK_ALLOCATION + assert(allocations.find(ptr) != allocations.end()); +#endif if (NULL == context) - { - context = &global_hieralloc_header + 1; - reparented = 1; - } + context = &hieralloc_global_header + 1; hieralloc_header_t * header = get_header(ptr); hieralloc_header_t * parent = header->parent; @@ -140,19 +190,19 @@ void * hieralloc_reallocate(const void * context, void * ptr, unsigned size, con add_to_parent(parent, header); } - hieralloc_header_t * sibling = header->prevSibling; - - ptr = realloc(header, size + sizeof(hieralloc_header_t)); - assert(ptr); - ((hieralloc_header_t *)ptr)->size = size; - if (ptr == header) - return header + 1; - - header = ptr; - header->beginMagic = BEGIN_MAGIC(); + header = (hieralloc_header_t *)realloc(header, size + sizeof(hieralloc_header_t)); + assert(header); + header->size = size; + header->name = name; + if (ptr == (header + 1)) + return ptr; // realloc didn't move allocation + + header->beginMagic = BEGIN_MAGIC(); header->endMagic = END_MAGIC(header); - if (sibling) - sibling->nextSibling = header; + if (header->nextSibling) + header->nextSibling->prevSibling = header; + if (header->prevSibling) + header->prevSibling->nextSibling = header; else parent->child = header; @@ -162,7 +212,11 @@ void * hieralloc_reallocate(const void * context, void * ptr, unsigned size, con child->parent = header; child = child->nextSibling; } - +#if CHECK_ALLOCATION + allocations.erase(ptr); + assert(allocations.find(header + 1) == allocations.end()); + allocations.insert(header + 1); +#endif return header + 1; } @@ -170,9 +224,11 @@ void * hieralloc_reallocate(const void * context, void * ptr, unsigned size, con // if destructor returns -1, then do nothing and return -1. int hieralloc_free(void * ptr) { - if (!ptr) + if (!ptr) return 0; - hieralloc_header_t * header = get_header(ptr); + + hieralloc_header_t * header = get_header(ptr); + header->refCount--; if (header->refCount > 0) return -1; @@ -181,28 +237,39 @@ int hieralloc_free(void * ptr) if (header->destructor(ptr)) return -1; - int ret = 0; + int ret = 0; + //* TODO: implement reference and steal first hieralloc_header_t * child = header->child; while (child) { hieralloc_header_t * current = child; - child = child->nextSibling; + assert(!current->prevSibling); + child = child->nextSibling; if (hieralloc_free(current + 1)) { ret = -1; remove_from_parent(current); add_to_parent(header->parent, current); + assert(0); // shouldn't happen since reference is always 1 } + } - //*/ - + if (ret) return -1; - + + assert(0 == header->childCount); + assert(!header->child); remove_from_parent(header); - memset(header, 0xfe, header->size + sizeof(*header)); - free(header); + memset(header, 0xfe, header->size + sizeof(*header)); +#if CHECK_ALLOCATION + assert(allocations.find(ptr) != allocations.end()); + allocations.erase(ptr); + // don't free yet to force allocations to new addresses for checking double freeing +#else + free(header); +#endif return 0; } @@ -241,7 +308,7 @@ void * hieralloc_init(const char * name) // returns global context void * hieralloc_autofree_context() { - return &global_hieralloc_header + 1; + return &hieralloc_global_header + 1; } // sets destructor to be called before freeing; dctor return -1 aborts free @@ -293,9 +360,10 @@ char * hieralloc_strdup(const void * ctx, const char * str) static char * _hieralloc_strlendup_append(char * str, unsigned len, const char * append, unsigned appendLen) { - //char * ret = hieralloc_allocate(NULL, sizeof(char) * (len + appendLen + 1), str); + //char * ret = hieralloc_allocate(str, sizeof(char) * (len + appendLen + 1), str); //memcpy(ret, str, len); - char * ret = hieralloc_reallocate(NULL, str, sizeof(char) * (len + appendLen + 1), str); + hieralloc_header_t * header = get_header(str); + char * ret = (char *)hieralloc_reallocate(header->parent + 1, str, sizeof(char) * (len + appendLen + 1), str); if (!ret) return NULL; memcpy(ret + len, append, appendLen); @@ -375,7 +443,7 @@ char * hieralloc_vasprintf_append(char * str, const char * fmt, va_list va) assert(appendLen >= 0); // some vsnprintf may return -1 if (appendLen < 0) return str; - str = hieralloc_reallocate(NULL, str, sizeof(char) * (len + appendLen + 1), str); + str = (char *)hieralloc_reallocate(NULL, str, sizeof(char) * (len + appendLen + 1), str); if (!str) return NULL; @@ -402,8 +470,9 @@ static void _hieralloc_report(const hieralloc_header_t * header, FILE * file, un unsigned i = 0; for (i = 0; i < tab; i++) fputc(' ', file); - fprintf(file, "%p: child=%d ref=%d size=%d name='%.256s' \n", header + 1, - header->childCount, header->refCount, header->size, header->name); + check_header(header); + fprintf(file, "%p: child=%d ref=%d size=%d dctor=%p name='%.256s' \n", header + 1, + header->childCount, header->refCount, header->size, header->destructor, header->name); const hieralloc_header_t * child = header->child; while (child) { @@ -417,13 +486,14 @@ static void _hieralloc_report(const hieralloc_header_t * header, FILE * file, un void hieralloc_report(const void * ptr, FILE * file) { if (NULL == ptr) - ptr = &global_hieralloc_header + 1; + ptr = &hieralloc_global_header + 1; fputs("hieralloc_report: \n", file); _hieralloc_report(get_header(ptr), file, 0); } static void _hieralloc_report_brief(const hieralloc_header_t * header, FILE * file, unsigned * data) { + check_header(header); data[0]++; data[1] += header->size; data[2] += header->childCount; @@ -439,11 +509,11 @@ static void _hieralloc_report_brief(const hieralloc_header_t * header, FILE * fi void hieralloc_report_brief(const void * ptr, FILE * file) { if (NULL == ptr) - ptr = &global_hieralloc_header + 1; + ptr = &hieralloc_global_header + 1; unsigned data [4] = {0}; _hieralloc_report_brief(get_header(ptr), file, data); - fprintf(file, "hieralloc_report total: count=%d size=%d child=%d ref=%d \n", - data[0], data[1], data[2], data[3]); + fprintf(file, "hieralloc_report %p total: count=%d size=%d child=%d ref=%d \n", + ptr, data[0], data[1], data[2], data[3]); } void hieralloc_report_lineage(const void * ptr, FILE * file, int tab) @@ -454,5 +524,34 @@ void hieralloc_report_lineage(const void * ptr, FILE * file, int tab) for (tab; tab >=0; tab--) fputc(' ', file); fprintf(file, "hieralloc_report_lineage %p: size=%d child=%d ref=%d name='%s' parent=%p \n", - ptr, header->size, header->child, header->refCount, header->name, header->parent + 1); + ptr, header->size, header->childCount, header->refCount, header->name, header->parent ? header->parent + 1 : NULL); } + +int hieralloc_find(const void * top, const void * ptr, FILE * file, int tab) +{ + int found = 0; + if (NULL == top) + top = &hieralloc_global_header + 1; + if (0 == tab && file) + fputs("hieralloc_find start \n", file); + if (top == ptr) + { + if (file) + fprintf(file, "hieralloc_found %p \n", ptr); + found++; + } + const hieralloc_header_t * start = get_header(top); + const hieralloc_header_t * child = start->child; + while (child) + { + found += hieralloc_find(child + 1, ptr, file, tab + 2); + child = child->nextSibling; + } + if (0 == tab && file) + fprintf(file, "hieralloc_find end found=%d \n", found); + return found; +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/src/talloc/hieralloc.h b/src/talloc/hieralloc.h index fd1c7d3..796a947 100644 --- a/src/talloc/hieralloc.h +++ b/src/talloc/hieralloc.h @@ -24,6 +24,9 @@ #define hieralloc_array(ctx, type, count) (type *)hieralloc_allocate(ctx, sizeof(type) * count, "ar:"#type) #define hieralloc_realloc(ctx, p, type, count) (type *)hieralloc_reallocate(ctx, p, sizeof(type) * count, "re:"#type) +#ifdef __cplusplus +extern "C" { +#endif // allocate memory and attach to parent context and siblings void * hieralloc_allocate(const void * context, unsigned size, const char * name); @@ -90,4 +93,10 @@ void hieralloc_report_brief(const void * ptr, FILE * file); void hieralloc_report_lineage(const void * ptr, FILE * file, int tab); +int hieralloc_find(const void * top, const void * ptr, FILE * file, int tab); + +#ifdef __cplusplus +} +#endif + #endif |