Exemplo n.º 1
0
int CMEM_init(void)
{
    int flags;
    unsigned int version;

    __D("init: entered - ref_count %d, cmem_fd %d\n", ref_count, cmem_fd);

    if (cmem_fd >= 0) {
        ref_count++;
        __D("init: /dev/cmem already opened, incremented ref_count %d\n",
            ref_count);
        return 0;
    }

    cmem_fd = open("/dev/cmem", O_RDWR);

    if (cmem_fd == -1) {
        __E("init: Failed to open /dev/cmem: '%s'\n", strerror(errno));
        return -1;
    }

    ref_count++;

    __D("init: successfully opened /dev/cmem, matching driver version...\n");

    version = CMEM_getVersion();
    if ((version & 0xffff0000) != (CMEM_VERSION & 0xffff0000)) {
        __E("init: major version mismatch between interface and driver.\n");
        __E("    needs driver version %#x, got %#x\n", CMEM_VERSION, version);
        CMEM_exit();
        return -1;
    }
    else if ((version & 0x0000ffff) < (CMEM_VERSION & 0x0000ffff)) {
        __E("init: minor version mismatch between interface and driver.\n");
        __E("    needs driver minor version %#x or greater.\n"
            "    got minor version %#x (full version %#x)\n",
            CMEM_VERSION & 0x0000ffff, version & 0x0000ffff, version);
        CMEM_exit();
        return -1;
    }

    __D("init: ... match good (%#x)\n", version);

    flags = fcntl(cmem_fd, F_GETFD);
    if (flags != -1) {
        fcntl(cmem_fd, F_SETFD, flags | FD_CLOEXEC);
    }
    else {
        __E("init: fcntl(F_GETFD) failed: '%s'\n", strerror(errno));
    }

    __D("init: exiting, returning success\n");

    return 0;
}
Exemplo n.º 2
0
/*
 *  ======== cleanup ========
 */
static Void cleanup(Void)
{
    ContigBuf *cb, *elem;

    if (curInit != FALSE) {
        curInit = FALSE;
        if (cmemInitialized) {
            CMEM_exit();
        }
        if (moduleLock != NULL) {
            Lock_delete(moduleLock);
        }
        /* free up contif buf list */
        cb = contigBufList;
        while (cb != NULL) {
            elem = cb;
            cb = cb->next;
            free(elem);
        }

        /* reinit static vars */
        contigBufList   = NULL;
        cmemInitialized = FALSE;
        moduleLock      = NULL;
    }
}
/* ARGSUSED - this line tells the compiler not to warn about unused args. */
IRES_Status IRES_ALGORITHM_initResources(IALG_Handle handle,
    IRES_ResourceDescriptor * resourceDescriptor, IRES_YieldFxn  yieldFxn,
    IRES_YieldArgs yieldArgs)
{
    Int i = 0;
    Int j = 0;
    unsigned int addr;
    unsigned int numBufs;
    IRES_VICP2_Handle res;
    DUMRES_TI_Handle algHandle = (DUMRES_TI_Handle)handle;
#ifdef xdc_target__os_Linux
    unsigned int tempAddr = 0x0;

    CMEM_init();
#endif

    /* Store information about resources received in the alg handle */
    for (i = 0; i < NUM_RESOURCES; i++) {

        res = ((IRES_VICP2_Handle)resourceDescriptor[i].handle);
        algHandle->resourceState[i] = 0;
        algHandle->resourceHandles[i] = res;

        for (j = 0; j < IRES_VICP2_NUMBUFFERS; j++) {

            addr = res->assignedIMCOPBuffers[j];
            /* An address of 0xFFFFFFFF is equivalent to a buffer not granted */
            if (addr != 0xFFFFFFFF) {

                printf("Resource #%d: VICP2 Buffer #%d: Addr 0x%x\n",i,j,addr);

#ifdef xdc_target__os_Linux
                tempAddr = (unsigned long)CMEM_getPhys((void *)addr);
                printf("Resource #%d: VICP2 Buffer #%d: PHY Addr 0x%x\n",i,j,
                        tempAddr);
#endif
            }
        }

        numBufs = res->numMemBufs;
        for (j = 0; j < numBufs; j++) {

            printf("Resource #%d: Mem Buffer #%d: Addr 0x%x Size 0x%x\n", i, j, 
                    res->assignedMemAddrs[j], res->assignedMemSizes[j]); 
#ifdef xdc_target__os_Linux
            tempAddr = (unsigned long) CMEM_getPhys((void *)
                    (res->assignedMemAddrs[j]));
            printf("Resource #%d: VICP2 Buffer #%d: PHY Addr 0x%x\n",
                    i,j, tempAddr);
#endif
        } 
    }
#ifdef xdc_target__os_Linux
    CMEM_exit();
#endif
    return (IRES_OK);
}
Exemplo n.º 4
0
/* ARGSUSED - this line tells the compiler not to warn about unused args. */
Int DUMALG_TI_useHDVICP(IDUMALG_Handle handle, unsigned int Id)
{
    Int i;
    DUMALG_TI_Obj * dumalg = (DUMALG_TI_Handle)handle;
    IRES_HDVICP_Handle hdvicp = NULL;

    if (dumalg->yieldFlag) {
        for (i = 0; i < NUM_RESOURCES; i++) {
            GT_2trace(ti_sdo_fc_rman_examples_hdvicp, GT_4CLASS,
                    "_DUMALG_TI_useHDVICP> Task #%d: Yielding HDVICP resource "
                    "%d\n", Id, (Int)(dumalg->hdvicp[i]));
        }

        /* Yield resource now */
        dumalg->yieldFxn((IRES_YieldResourceType)IRES_ALL,&dumalg->yieldContext,
                dumalg->yieldArgs);

            for (i = 0; i < NUM_RESOURCES; i++) {
            GT_2trace(ti_sdo_fc_rman_examples_hdvicp, GT_4CLASS,
                    "_DUMALG_TI_useHDVICP> Task #%d: HDVICP resource %d "
                    "re-acquired\n", Id, (Int)(dumalg->hdvicp[i]));
            }
    }
    else {

        /* Alg doesn't yield the resource */

#ifdef xdc_target__os_Linux
        CMEM_init();
#endif
        for (i = 0; i < NUM_RESOURCES; i++) {

            hdvicp = dumalg->resourceHandles[i];

            GT_2trace(ti_sdo_fc_rman_examples_hdvicp, GT_4CLASS,
                    "_DUMALG_TI_useHDVICP> Task #%d: Not yielding HDVICP "
                    "resource %d\n", Id, (Int)(hdvicp->id));

#ifdef xdc_target__os_Linux

            GT_3trace(ti_sdo_fc_rman_examples_hdvicp, GT_4CLASS,
                    "_DUMALG_TI_useHDVICP> Register space address 0x%x, Memory "
                    "base address 0x%x, Phy register base address 0x%x\n",
                    (unsigned int)(hdvicp->registerBaseAddress),
                    (unsigned int)(hdvicp->memoryBaseAddress),
                    (void *) CMEM_getPhys((void *)
                    (hdvicp->registerBaseAddress)));

#endif
        }
#ifdef xdc_target__os_Linux
        CMEM_exit();
#endif
    }

    return 0;
}
/*
 *  ======== MEMUTILS_cacheInv ========
 */
Void MEMUTILS_cacheInv(Ptr addr, Int sizeInBytes)
{
    if (!regInit) {
        addModule();
    }

    CMEM_init();
    CMEM_cacheInv(addr, sizeInBytes);
    CMEM_exit();
}
Exemplo n.º 6
0
/**
 * @brief Initiliztion of the message driver for Appro interface
 *
 *
 * @param   proc_id    message type id of the proceess, defined at ipnc_app/include/Stream_Msg_Def.h
 *
 * @return 0 is ok and -1 is error
 *
 *
 */
int ApproDrvInit(int proc_id)
{
	if(proc_id < MSG_TYPE_MSG1 || proc_id > 20){
		gProcId = MSG_TYPE_MSG1;
		return -1;
	}
	gProcId = proc_id;
	fprintf(stderr, "%s: %d\n", __func__, proc_id);
#if ENABLE_CMEM
	/* CMEM only one init is allowed in each process */
	if(Testflag==0)
	{
		if(CMEM_init() < 0){
			gProcId = MSG_TYPE_MSG1;
			return -1;
		}
	}
#endif
	Testflag = 1;;
	if(hndlApproDrvSem == NULL)
		hndlApproDrvSem = MakeSem();
	if(hndlApproDrvSem == NULL){
#if ENABLE_CMEM
		CMEM_exit();
#endif
		gProcId = MSG_TYPE_MSG1;
		return -1;
	}
	printf("Msg_Init Begin\n");
	if((qid=Msg_Init(MSG_KEY)) < 0){
		DestroySem(hndlApproDrvSem);
		hndlApproDrvSem = NULL;
#if ENABLE_CMEM
		CMEM_exit();
#endif
		gProcId = MSG_TYPE_MSG1;
		return -1;
	}
	printf("Msg_Init Done\n");
	return 0;
}
void amljpeg_exit()
{
	if(fd_amport>=0)
	{
		close(fd_amport);
#ifdef JPEG_DBG 		
		printf("fd_amport (%d) closed.\n",fd_amport);
#endif		
		fd_amport=-1;
	}
	CMEM_exit();    
}
/*
 *  ======== MEMUTILS_cacheInv ========
 */
Void MEMUTILS_cacheInv(Ptr addr, Int sizeInBytes)
{
#if GT_TRACE
    if (!(gtInit)) {
        GT_init();
        GT_create(&curTrace, "ti.sdo.fc.memutils");
        gtInit = 1;
    }    
#endif
    CMEM_init();
    CMEM_cacheInv(addr, sizeInBytes);
    CMEM_exit();
}
Exemplo n.º 9
0
int main(int argc, char *argv[])
{
    int size;
    int version;
    CMEM_BlockAttrs attrs;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s <Number of bytes to allocate>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    size = atoi(argv[1]);

    /* First initialize the CMEM module */
    if (CMEM_init() == -1) {
        fprintf(stderr, "Failed to initialize CMEM\n");
        exit(EXIT_FAILURE);
    }

    printf("CMEM initialized.\n");

    version = CMEM_getVersion();
    if (version == -1) {
        fprintf(stderr, "Failed to retrieve CMEM version\n");
    }
    printf("CMEM version = 0x%x\n", version);

    if (CMEM_getBlockAttrs(0, &attrs) == -1) {
        fprintf(stderr, "Failed to retrieve CMEM memory block 0 bounds\n");
    }
    printf("CMEM memory block 0: phys start = 0x%lx, size = 0x%x\n",
           attrs.phys_base, attrs.size);

    if (CMEM_getBlockAttrs(1, &attrs) == -1) {
        fprintf(stderr, "Failed to retrieve CMEM memory block 1 bounds\n");
    }
    printf("CMEM memory block 1: phys start = 0x%lx, size = 0x%x\n",
           attrs.phys_base, attrs.size);

    testHeap(size, 0);
    testHeap(size, 1);

    testCache(size, 0);
    testCache(size, 1);

    if (CMEM_exit() < 0) {
        fprintf(stderr, "Failed to finalize the CMEM module\n");
    }

    exit(EXIT_SUCCESS);
}
Exemplo n.º 10
0
/**
 * @brief Resource releasing of the message driver for Appro interface
 *
 *
 *
 * @return 0 is ok and -1 is error
 *
 *
 */
int ApproDrvExit()
{
	fprintf(stderr, "%s: %d\n", __func__, gProcId);
	gProcId = MSG_TYPE_MSG1;
	DestroySem(hndlApproDrvSem);
	hndlApproDrvSem = NULL;
#if ENABLE_CMEM

	if( Testflag != 0 )
	{
	 	CMEM_exit();
	}
	Testflag = 0;;
	return 0;
#else
	return 0;
#endif
}
/*
 *  ======== MEMUTILS_getPhysicalAddr ========
 *  Converts user virtual address to physical address,
 *  Returns 0 on failure, physical address on success.
 */
Void * MEMUTILS_getPhysicalAddr(Ptr addr)
{
    UInt32 physicalAddress = 0;

    if (!regInit) {
        addModule();
    }

    CMEM_init();

    physicalAddress = CMEM_getPhys(addr);
    Log_print2(Diags_USER1, "[+1] MEMUTILS_getPhysicalAddr> "
            "CMEM_getPhys(0x%x) = 0x%x.", (IArg)addr, (IArg)physicalAddress);

    Log_print1(Diags_ENTRY, "[+E] MEMUTILS_getPhysicalAddr> return (0x%x)",
            (IArg)physicalAddress);

    CMEM_exit();

    return ((Void *)physicalAddress);
}
Exemplo n.º 12
0
int main()
{
    CERuntime_init();
    CMEM_init();

#ifdef CE_TEST
    CERuntime_init();
    CERuntime_exit();
    CERuntime_init();
    CERuntime_exit();
#endif

    /* initialize libavcodec, and register all codecs and formats */
    av_register_all();

    /* TODO: can't run both yet, some problem with CE init and exit */
    ff_example("test.avi", "avi");
//    decode_example("test.mkv");

    CMEM_exit();
    CERuntime_exit();
    return 0;
}
/*
 *  ======== SCPY_configure ========
 *  Configure a transfer on the SDMA handle
 */
void SCPY_configure(IRES_SDMA_Handle handle, SCPY_Params * params)
{
    /* SCPY_configure should be called with only one logicalChannel */ 
    int logicalChannel = handle->channel->chanNum; 
    unsigned int dmaAddr = (unsigned int)(handle->channel->addr);

    CMEM_init();
    
    omap_set_dma_transfer_params(logicalChannel, dmaAddr, 
            params->transfer->dataType, params->transfer->elemCount, 
            params->transfer->frameCount);


    omap_set_dma_src_params(logicalChannel, dmaAddr, 
            params->src->addr_mode, CMEM_getPhys((void *)(params->src->addr)),
            params->src->elem_index, params->src->frame_index);

    omap_set_dma_dest_params(logicalChannel, dmaAddr, 
            params->dst->addr_mode, CMEM_getPhys((void *)(params->dst->addr)),
            params->dst->elem_index, params->dst->frame_index);

    CMEM_exit();
}
/*
 *  ======== MEMUTILS_getPhysicalAddr ========
 *  Converts user virtual address to physical address,
 *  Returns 0 on failure, physical address on success.
 */
Void * MEMUTILS_getPhysicalAddr(Ptr addr)
{
    UInt32 physicalAddress = 0;
#if GT_TRACE
    if (!(gtInit)) {
        GT_init();
        GT_create(&curTrace, "ti.sdo.fc.memutils");
        gtInit = 1;
    }    
#endif

    CMEM_init();

    physicalAddress = CMEM_getPhys(addr);
    GT_2trace(curTrace, GT_1CLASS, "MEMUTILS_getPhysicalAddr> "
            "CMEM_getPhys(0x%x) = 0x%x.\n", addr, physicalAddress);

    GT_1trace(curTrace, GT_ENTER, "MEMUTILS_getPhysicalAddr> "
            "return (0x%x)\n", physicalAddress);

    CMEM_exit();

    return ((Void *)physicalAddress);
}
Exemplo n.º 15
0
int main(int argc, char *argv[])
{
    size_t size;
    int version;
    CMEM_BlockAttrs attrs;
    int i;
    int c;
    
    non_interactive_flag = FALSE;

    while ((c = getopt(argc, argv, "n")) != -1) {
	switch (c) {
	case 'n':
	    non_interactive_flag = TRUE; 	
	    break;

	default:
	    fprintf(stderr, "Usage: %s [-n] <Number of bytes to allocate>\n",
		    argv[0]);
	    fprintf(stderr,
                    "    -n: non-interactive mode (no ENTER prompts)\n");
	    exit(EXIT_FAILURE);
	}
    }

    if ((argc - optind + 1) != 2) {
	fprintf(stderr, "Usage: %s [-n] <Number of bytes to allocate>\n",
	        argv[0]);
	fprintf(stderr, "    -n: non-interactive mode (no ENTER prompts)\n");
	exit(EXIT_FAILURE);
    }

    errno = 0;
    size = strtol(argv[optind], NULL, 0);

    if (errno) {
	fprintf(stderr, "Bad argument ('%s'), strtol() set errno %d\n",
	        argv[optind], errno);
        exit(EXIT_FAILURE);
    }

    /* First initialize the CMEM module */
    if (CMEM_init() == -1) {
        fprintf(stderr, "Failed to initialize CMEM\n");
        exit(EXIT_FAILURE);
    }

    printf("CMEM initialized.\n");

    version = CMEM_getVersion();
    if (version == -1) {
	fprintf(stderr, "Failed to retrieve CMEM version\n");
        exit(EXIT_FAILURE);
    }
    printf("CMEM version = 0x%x\n", version);

    testMap(size);
    testAllocPhys(size);

    testCMA(size);

    if (CMEM_getNumBlocks(&nblocks)) {
	fprintf(stderr, "Failed to retrieve number of blocks\n");
        exit(EXIT_FAILURE);
    }
    printf("\n# of CMEM blocks (doesn't include possible CMA global 'block'): %d\n", nblocks);

    if (nblocks) {
	for (i = 0; i < nblocks; i++) {
	    if (CMEM_getBlockAttrs(i, &attrs) == -1) {
		fprintf(stderr, "Failed to retrieve CMEM memory block %d bounds\n", i);
	    }
	    else {
		printf("CMEM memory block %d: phys start = %#llx, size = %#llx\n",
		       i, (unsigned long long)attrs.phys_base, attrs.size);
	    }

	    testHeap(size, i);
	    testHeap(size, i);
	    testPools(size, i);
	    testPools(size, i);
	    testCache(size, i);
	}
    }
    else {
	printf("    no physical block found, not performing block-based testing\n");
    }

    /* block 'nblocks' is the special CMEM CMA "block" */
    testPools(size, CMEM_CMABLOCKID);

    printf("\nexiting...\n");
    if (CMEM_exit() < 0) {
        fprintf(stderr, "Failed to finalize the CMEM module\n");
    }
    printf("...test done\n");

    exit(EXIT_SUCCESS);
}
Exemplo n.º 16
0
/*!****************************************************************************
 @Function		main
 @Input			argc		Number of arguments
 @Input			argv		Command line arguments
 @Return		int			result code to OS
 @Description	Main function of the program
******************************************************************************/
int main(int argc, char **argv)
{
	int testID = 0, err; //default
	char *extensions;
	unsigned int delta;
	NATIVE_PIXMAP_STRUCT* pNativePixmap = NULL;


	/* Initialise all globals */
	initialise_globals(&gTest);

	/* Pre init step - check the arguments */
	if(argc < 11)
	{
		SGXPERF_ERR_printf("Error: Invalid number of operands \n\n");
		SGXPERF_ERR_printf("%s",helpString);
		exit(-1);
	}
	testID = atol(argv[1]);
	if(testID > MAX_TEST_ID || testID < 0)
	{
		SGXPERF_ERR_printf("Error: No test available with this ID %d\n\n", testID);
		SGXPERF_ERR_printf("%s",helpString);
		exit(-1);
	}
	gTest.inNumberOfObjectsPerSide = atol(argv[7]);
	gTest.inSurfaceType = atol(argv[8]);

	if(argc < 4)
	{
		if(testID > 2) //1 and 2 do not need textures
		{
			SGXPERF_ERR_printf("Error: Invalid number of operands for selected testID %d\n\n", testID);
			SGXPERF_ERR_printf("%s",helpString);
			exit(-1);
		}
	}
	else
	{
		gTest.inTextureWidth = atol(argv[2]);
		gTest.inTextureHeight = atol(argv[3]);
	}
	gTest.inRotationEnabled = 0;
	//Rotation is unused in latest version
	if(argc >= 5)
		gTest.inRotationEnabled = atol(argv[4]);
	gTest.inPixelFormat = 0;
	if(argc >= 6)
		gTest.inPixelFormat = atol(argv[5]);
	if(gTest.inPixelFormat != SGXPERF_RGB565 && gTest.inPixelFormat != SGXPERF_ARGB8888 && gTest.inPixelFormat != SGXPERF_BYTE8)
	{
		SGXPERF_ERR_printf("Error: Unsupported pixel format for texture %d \n\n", gTest.inPixelFormat);
		SGXPERF_ERR_printf("%s",helpString);
		exit(-1);
	}
  
  //read extra params
  gTest.numTestIterations = atol(argv[9]);
  gTest.inFPS =atol(argv[10]); 
  gTest.msToSleep = 1000/gTest.inFPS;
  gTest.cookie = argv[11];
    
	if((gTest.inTextureWidth > 8000) || (gTest.inTextureHeight > 8000))
	{
		SGXPERF_ERR_printf("Error: Width or Height exceeds 8000 \n\n");
		SGXPERF_ERR_printf("%s",helpString);
		exit(-1);
	}
#ifndef _ENABLE_CMEM
	if(testID == 6 || testID == 7 || gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_16 || 
                                    gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_32)
	{
		SGXPERF_ERR_printf("ERROR: Cannot run native pixmap tests without CMEM\n");
		exit(-1);
	}
#endif
#ifndef _ENABLE_BUFFERCLASS
	if(testID == 8)
	{
		SGXPERF_ERR_printf("ERROR: Cannot run test8 without BUFFERCLASS driver\n");
		exit(-1);
	}
#endif
	//for pixmap related tests, surface cannot be pixmap
	if(testID == 6 && gTest.inSurfaceType != SGXPERF_SURFACE_TYPE_WINDOW)
	{
		SGXPERF_ERR_printf("ERROR: Cannot run native pixmap eglimage test with pixmap surface\n");
		goto cleanup;
	}

  signal(SIGINT, sgxperf_signal_handler);

#ifdef _ENABLE_CMEM
	//Initialise the CMEM module. 
	//CMEM ko should be inserted before this point
	SGXPERF_printf("Configuring CMEM\n");
	CMEM_init();
#endif
	//Allocate texture for use in GL texturing modes(can also be done from CMEM if memory permits
	gTest._textureData = (unsigned int*)malloc(gTest.inTextureWidth*gTest.inTextureHeight*4 + PAGE_SIZE);
	if(!gTest._textureData)
	{
		SGXPERF_ERR_printf("ERROR: No malloc memory for allocating texture!\n");
		goto cleanup;
	}
	delta =(PAGE_SIZE - ((unsigned int)gTest._textureData &
(PAGE_SIZE-1))); 
	gTest.textureData = (unsigned int*)((char*)gTest._textureData + delta);
	memset(gTest.textureData, 0, gTest.inTextureWidth*gTest.inTextureHeight*4);

	set_texture(gTest.inTextureWidth, gTest.inTextureHeight, (unsigned char*)gTest.textureData, gTest.inPixelFormat);

	//initialise egl
	err = common_eglinit(&gTest, testID, gTest.inSurfaceType, &pNativePixmap);
	if(err)
	{
		SGXPERF_ERR_printf("ERROR: eglinit - err = %d\n", err);
		goto cleanup;
	}

	GLuint uiFragShader, uiVertShader;		// Used to hold the fragment and vertex shader handles
	GLuint uiProgramObject;					// Used to hold the program handle (made out of the two previous shaders

	// Create the fragment shader object
	uiFragShader = glCreateShader(GL_FRAGMENT_SHADER);

	// Load the source code into it
	if((testID == 3) || (testID == 5) || (testID == 6) || (testID == 7)  || 
        (testID == 14) || (testID == 17))
		glShaderSource(uiFragShader, 1, (const char**)&pszFragTextureShader, NULL);
	else if(testID == 11) //Edge detect with RGB input
		glShaderSource(uiFragShader, 1, (const char**)&pszFragEdgeRGBDetectShader, NULL);
	else if(testID == 12) //Edge detect with YUV input
		glShaderSource(uiFragShader, 1, (const char**)&pszFragEdgeYUVDetectShader, NULL);
	else if(testID == 8) //IMG texture stream2
		glShaderSource(uiFragShader, 1, (const char**)&pszFragIMGTextureStreamShader, NULL);
	else if(testID == 16) //EGLImage streaming
		glShaderSource(uiFragShader, 1, (const char**)&pszFragEGLImageShader, NULL);
	else
		glShaderSource(uiFragShader, 1, (const char**)&pszFragNoTextureShader, NULL);

	// Compile the source code
	glCompileShader(uiFragShader);

	// Check if compilation succeeded
	GLint bShaderCompiled;
    glGetShaderiv(uiFragShader, GL_COMPILE_STATUS, &bShaderCompiled);

	if (!bShaderCompiled)
	{
		// An error happened, first retrieve the length of the log message
		int i32InfoLogLength, i32CharsWritten;
		glGetShaderiv(uiFragShader, GL_INFO_LOG_LENGTH, &i32InfoLogLength);

		// Allocate enough space for the message and retrieve it
		char* pszInfoLog = new char[i32InfoLogLength];
        glGetShaderInfoLog(uiFragShader, i32InfoLogLength, &i32CharsWritten, pszInfoLog);

		// Displays the error
		SGXPERF_ERR_printf("Failed to compile fragment shader: %s\n", pszInfoLog);
		delete [] pszInfoLog;
		goto cleanup;
	}

	// Loads the vertex shader in the same way
	uiVertShader = glCreateShader(GL_VERTEX_SHADER);
	if((testID == 3) || (testID == 5) || (testID == 6) || (testID == 7) || 
        (testID == 8) || (testID == 11) || (testID == 12)
           || (testID == 14) || (testID == 16) || (testID == 17))
		glShaderSource(uiVertShader, 1, (const char**)&pszVertTextureShader, NULL);
	else
	{
		SGXPERF_ERR_printf("INFO: Using no-texture vertex shader\n");
		glShaderSource(uiVertShader, 1, (const char**)&pszVertNoTextureShader, NULL);
	}

	glCompileShader(uiVertShader);
    glGetShaderiv(uiVertShader, GL_COMPILE_STATUS, &bShaderCompiled);

	if (!bShaderCompiled)
	{
		int i32InfoLogLength, i32CharsWritten;
		glGetShaderiv(uiVertShader, GL_INFO_LOG_LENGTH, &i32InfoLogLength);
		char* pszInfoLog = new char[i32InfoLogLength];
        glGetShaderInfoLog(uiVertShader, i32InfoLogLength, &i32CharsWritten, pszInfoLog);
		SGXPERF_ERR_printf("Failed to compile vertex shader: %s\n", pszInfoLog);
		delete [] pszInfoLog;
		goto cleanup;
	}

	// Create the shader program
    uiProgramObject = glCreateProgram();

	// Attach the fragment and vertex shaders to it
    glAttachShader(uiProgramObject, uiFragShader);
    glAttachShader(uiProgramObject, uiVertShader);

	// Bind the custom vertex attribute "myVertex" to location VERTEX_ARRAY
	glBindAttribLocation(uiProgramObject, VERTEX_ARRAY, "inVertex");
	glBindAttribLocation(uiProgramObject, TEXCOORD_ARRAY, "inTexCoord");

	// Link the program
    glLinkProgram(uiProgramObject);

	// Check if linking succeeded in the same way we checked for compilation success
    GLint bLinked;
    glGetProgramiv(uiProgramObject, GL_LINK_STATUS, &bLinked);

	if (!bLinked)
	{
		int ui32InfoLogLength, ui32CharsWritten;
		glGetProgramiv(uiProgramObject, GL_INFO_LOG_LENGTH, &ui32InfoLogLength);
		char* pszInfoLog = new char[ui32InfoLogLength];
		glGetProgramInfoLog(uiProgramObject, ui32InfoLogLength, &ui32CharsWritten, pszInfoLog);
		SGXPERF_ERR_printf("Failed to link program: %s\n", pszInfoLog);
		delete [] pszInfoLog;
		goto cleanup;
	}

	// Actually use the created program
	glUseProgram(uiProgramObject);
#ifdef _ENABLE_TEST16
	if(testID == 16)
	{
		int sampler = glGetUniformLocation(uiProgramObject, "yuvTexSampler");
		glUniform1i(sampler, 0);
	}
#endif
	//set rotation variables to init
	gTest.matrixLocation = glGetUniformLocation(uiProgramObject, "MVPMatrix");
	memset(gTest.mat_final, 0, sizeof(gTest.mat_final));
	gTest.mat_final[0] = gTest.mat_final[5] = gTest.mat_final[10] = gTest.mat_final[15] = 1.0;
	glUniformMatrix4fv( gTest.matrixLocation, 1, GL_FALSE, gTest.mat_final);
	
	/* Set rowsize for edge detect */
	if(testID == 11)
	{
		glUniform1f(glGetUniformLocation(uiProgramObject, "rowSize"), 256.0);
		glUniform1f(glGetUniformLocation(uiProgramObject, "columnSize"), 256.0);
	}
	else if(testID == 12)
	{
		glUniform1f(glGetUniformLocation(uiProgramObject, "rowSize"), 128.0);
		glUniform1f(glGetUniformLocation(uiProgramObject, "columnSize"), 160.0);
	}
	/* Set clear */
	glClearColor(0.2f, 0.8f, 1.0f, 1.0f); // blueish greenish red :)
	glClear(GL_COLOR_BUFFER_BIT);

		/*
		Do various tests
		*/
		switch(testID)
		{
			case 0:
				extensions = (char*)glGetString(GL_EXTENSIONS);
				SGXPERF_ERR_printf("\nTESTID = 0: GL SUPPORTED EXTENSIONS = \n%s\n", extensions);
                                extensions = (char*)eglQueryString(gTest.eglDisplay, EGL_EXTENSIONS);
                                SGXPERF_ERR_printf("\nTESTID = 0: EGL SUPPORTED EXTENSIONS = \n%s\n", extensions);
				break;
			case 1:
				/* Fill entire screen with single colour, no objects */
				test1(&gTest);
				break;
			case 2:
				/* Draw a coloured rectangle filling entire screen */
				test2(&gTest);
				break;
			case 3:
				/* Move a coloured rectangle of half screen size to another half with same parameters */
				test3(&gTest);
				break;
			case 4:
				/* Alpha blending full surface texture */
				test4(&gTest);	
				break;
			case 5:
				/* Alpha blending full surface WITHOUT texture */
				test5(&gTest);
				break;
			case 8:
#ifdef _ENABLE_TEST8
				/* GL_IMG_texture_stream */
				test8(&gTest);
#endif
				break;
			case 10:
				/* PVR2D test */
				test10(&gTest);
				break;
			case 11:
				/* Edge detection test - test3 with new shader */
				test3(&gTest);
				break;
#ifdef _ENABLE_TEST8
			case 12:
				/* Edge detection test - test8 with new shader */
				test8(&gTest);
				break;
#endif
			case 13:
				/* Line drawing */
				test13(&gTest);
				break;
#ifdef _ENABLE_TEST14				
			case 14:
				/* Context Switch */
				test14(&gTest);
				break;
#endif				
#ifdef _ENABLE_TEST15
			case 15:
				/* YUV-RGB conversion with PVR2D */
				test15(&gTest);
				break;
#endif
#ifdef _ENABLE_TEST16
			case 16:
				/* YUV-Streaming with EGLImage */
				test16(&gTest);
				break;
#endif
#ifdef _ENABLE_TEST17
			case 17:
				/* FBO */
				test17(&gTest);
				break;
#endif
			default:
				/* Sorry guys, we tried ! */
				SGXPERF_ERR_printf("No matching test code\n");
				break;
		}
#ifdef _ENABLE_CMEM
	/* PIXMAP loopback test  */
	if(gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_16 || gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_32) 
	{
#if 1
		/* Use this for checking out the output in the pixmap */
		/* For DEBUGGING ONLY */
		FILE *fp = fopen("pixmap.raw", "wb");
		int numbytes;
		if(gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_32) numbytes = 4; //ARGB8888
		if(gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_16) numbytes = 2; //RGB565
		SGXPERF_ERR_printf("Writing pixmap data to file pixmap.raw\n");
		fwrite((void*)pNativePixmap->lAddress, 1, gTest.inTextureWidth*gTest.inTextureHeight*numbytes, fp);
		fclose(fp);
#endif
	}
#endif //CMEM needed for pixmap loopback
	// Frees the OpenGL handles for the program and the 2 shaders
	glDeleteProgram(uiProgramObject);
	glDeleteShader(uiFragShader);
	glDeleteShader(uiVertShader);

cleanup:
	if(gTest._textureData) 
		free(gTest._textureData);
	common_egldeinit(&gTest, testID, pNativePixmap);
#ifdef _ENABLE_CMEM
	CMEM_exit();
#endif

	return 0;
}
Exemplo n.º 17
0
int main(int argc, char *argv[])
{
    unsigned int *ptr = NULL;
    pid_t newPid = 0;
    int pid = 0;
    int numProcesses;
    int r;
    int i;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s <Number of processes to fork>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    numProcesses = atoi(argv[1]);

    for (i=0; i<numProcesses; i++) {
        newPid = fork(); 

        if (newPid == -1) {
            fprintf(stderr, "Failed to fork off new process\n");
            exit(EXIT_FAILURE);
        }
        else if (newPid == 0) {
            pid = i;
            break;
        }

        printf("Forked off process %d\n", newPid);
    }

    if (newPid != 0) {
        printf("Main process exiting\n");
        exit(EXIT_SUCCESS);
    }

    /* First initialize the CMEM module */
    if (CMEM_init() == -1) {
        fprintf(stderr, "Process %d: Failed to initialize CMEM\n", pid);
        exit(EXIT_FAILURE);
    }

    printf("Process %d: CMEM initialized.\n", pid);

    /* First allocate a buffer from the pool that best fits */
    ptr = CMEM_alloc(BUFFER_SIZE, NULL);

    if (ptr == NULL) {
        fprintf(stderr, "Process %d: Failed to allocate buffer of size %d\n",
                pid, BUFFER_SIZE);
        exit(EXIT_FAILURE);
    }

    printf("Process %d: Allocated buffer at %#x\n", pid, (unsigned int) ptr);

    /* Write some data into this buffer */
    for (i=0; i < BUFFER_SIZE / sizeof(int) ; i++) {
        ptr[i] = 0xbeefbeef;
    }

#if 0
    srand(pid * 1024);

    r = 1 + (int) (DELAYSPAN * (rand() / (RAND_MAX + 1.0)));
#else
    r = (pid * 3) + 3;
#endif

    printf("Process %d: Sleeping for %d seconds\n", pid, r);

    sleep(r);

    if (pid % 2) {
        printf("Process %d: Freeing buffer at %#x\n", pid, (unsigned int) ptr);

        if (CMEM_free(ptr, NULL) < 0) {
            fprintf(stderr, "Process %d: Failed to free buffer at %#x\n",
                    pid, (unsigned int) ptr);
        }
    }
    else {
        printf("Process %d: intentionally neglecting to call CMEM_free()\n",
               pid);
    }


    if (pid != 0) {
        printf("Process %d: Exiting CMEM\n", pid);
        if (CMEM_exit() < 0) {
            fprintf(stderr, "Process %d: Failed to finalize the CMEM module\n",
                    pid);
        }
    }
    else {
        printf("Process %d: sleeping 5 ...\n", pid);
        sleep(5);
        printf("Process %d: exiting, intentionally forgetting to call "
               "CMEM_exit()\n", pid);
    }

    exit(EXIT_SUCCESS);
}