This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

GPU memory malloc method



Hi all,

When we read source code of gralloc.cpp for gralloc.default.so which is in /system/lib/hw, we found gralloc_alloc function definition is as following. From folloing bold sentences, format is fixed as RGB, RGBA, RGBX for gralloc.default.so.  For output port buffer of OMX decoder, its format is HAL_PIXEL_FORMAT_TI_NV12 which equal to 256. 

So is there other method to malloc GPU memory for TI format? Thx.

 

static int gralloc_alloc(alloc_device_t* dev,

        int w, int h, int format, int usage,

        buffer_handle_t* pHandle, int* pStride)

{

    if (!pHandle || !pStride)

        return -EINVAL;

    size_t size, stride;

 

    int align = 4;

    int bpp = 0;

    switch (format) {

        case HAL_PIXEL_FORMAT_RGBA_8888:

        case HAL_PIXEL_FORMAT_RGBX_8888:

        case HAL_PIXEL_FORMAT_BGRA_8888:

            bpp = 4;

            break;

        case HAL_PIXEL_FORMAT_RGB_888:

            bpp = 3;

            break;

        case HAL_PIXEL_FORMAT_RGB_565:

        case HAL_PIXEL_FORMAT_RGBA_5551:

        case HAL_PIXEL_FORMAT_RGBA_4444:

            bpp = 2;

            break;

        default:

            return -EINVAL;

    }

    size_t bpr = (w*bpp + (align-1)) & ~(align-1);

    size = bpr * h;

    stride = bpr / bpp;

 

    int err;

    if (usage & GRALLOC_USAGE_HW_FB) {

        err = gralloc_alloc_framebuffer(dev, size, usage, pHandle);

    } else {

        err = gralloc_alloc_buffer(dev, size, usage, pHandle);

    }

 

    if (err < 0) {

        return err;

    }

 

    *pStride = stride;

    return 0;

}

 

regards,

guangx

  • Hi,

    The source code you are seeing is just the default Android code. The code TI acutally delivers is significantly different and makes full use of TI specialized hardware. The source code for that is not availabile publicly and therefore you won't see the source code in public releases, the proprietary binaries are loaded when the release is packaged into img files during the build process.

    The proprietary libraries are stored in device/ti/proprietary-open/omap4/sgx/lib/hw/gralloc.omap44xx.so. On the tablet they should be in /system/vendor/lib/hw/gralloc.omap44xx.so

  • Hi Matt,

    Thank you for your reply. In /system/vendor/lib/hw/, we can found three gralloc.omap44**.so files.

    For GPU memory malloc, one problem is encountered for TI format. So that is why i want to ask the question.

    Our problem is as following:

    When we try to use dequeue buffer from one ANativeWindows on our early build version of 4.0.4 , it can work well. But on new build version of 4.0.4, dequeue buffer is failed.

    1) Before dequeue buffer, we use native_window_set_buffers_geometry to set format as TI format which is format of output port for OMX decoder.

    2) Then we use m_IOMX->getGraphicBufferUsage(m_nodeId, kPortIndexOutput, &usage); to get usage.

    3) Then we use native_window_set_usage to set usage, the paramter is usage | GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_EXTERNAL_DISP

    The error information from logcat for dequeue buffer is malloc failed, return -22. From trace, it is can be located in gralloc.c which is default android method not TI. I don't why on new build version, when format is TI format, it is executed in default android method not into TI driver.

    After we delete red parameter GRALLOC_USAGE_EXTERNAL_DISP, there is no malloc error on new version. Our application can work well.

    Can you give you suggestion about why this parameter  lead to GPU mallocby using default android method not TI own driver? Thx.

    regards,

    guangx

  •  I need a bit more information from you before I can help you. What are you referring to as build version 4.0.4? Is this ICS? What software are you using? How are you building it? Are you running this on a tablet? a blaze? your own device?

    Also, can you put in a stackdump from the default gralloc so that the logs will show how it wound up in the default version? Can you provide a testcase/example code which demontrates the problem which I can run and diagnose?

     

    Matt Kiser

  • Hi Matt,

    The OS is ICS. Software we used is native C code, build tool is NDK-linux-r7b. We include header file of source code, and link with so files from target machine. Machine is Blaze_tablet. We are developing software on the machine.

    I am not sure we can get dump file for gralloc.default.so. Can tell us which part of code is used to judge whether use default malloc or TI driver method? Thx.

    regards,

    guangx

     

  • Sorry for the long delay.

    The best way to find out why the default gralloc is being loaded is to remove the shared library from /system and then follow the error messages from wherever dlopen() is being called. Make sure all your drivers are being correctly loaded with lsmod as well.

    Otherwise I would need to understand the differences between your old build and your new build to understand why you are not loading the correct libraries.