tests/cuda3.2/tests/SobelFilter/SobelFilter.cpp
void display(void) 
{  
    cutilCheckError(cutStartTimer(timer));  

    // Sobel operation
    Pixel *data = NULL;

    // map PBO to get CUDA device pointer
	cutilSafeCall(cudaGraphicsMapResources(1, &cuda_pbo_resource, 0));
    size_t num_bytes; 
    cutilSafeCall(cudaGraphicsResourceGetMappedPointer((void **)&data, &num_bytes,  
						       cuda_pbo_resource));
    //printf("CUDA mapped PBO: May access %ld bytes\n", num_bytes);
	
	sobelFilter(data, imWidth, imHeight, g_SobelDisplayMode, imageScale );
    cutilSafeCall(cudaGraphicsUnmapResources(1, &cuda_pbo_resource, 0));

    glClear(GL_COLOR_BUFFER_BIT);

    glBindTexture(GL_TEXTURE_2D, texid);
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo_buffer);
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, imWidth, imHeight, 
                   GL_LUMINANCE, GL_UNSIGNED_BYTE, OFFSET(0));
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);

    glDisable(GL_DEPTH_TEST);
    glEnable(GL_TEXTURE_2D);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        
    glBegin(GL_QUADS);
    glVertex2f(0, 0); glTexCoord2f(0, 0);
    glVertex2f(0, 1); glTexCoord2f(1, 0);
    glVertex2f(1, 1); glTexCoord2f(1, 1);
    glVertex2f(1, 0); glTexCoord2f(0, 1);
    glEnd();
    glBindTexture(GL_TEXTURE_2D, 0);

    if (g_CheckRender && g_CheckRender->IsQAReadback() && g_Verify) {
        printf("> (Frame %d) readback BackBuffer\n", frameCount);
        g_CheckRender->readback( imWidth, imHeight );
        g_CheckRender->savePPM ( sOriginal_ppm[g_Index], true, NULL );
        if (!g_CheckRender->PPMvsPPM(sOriginal_ppm[g_Index], sReference_ppm[g_Index], MAX_EPSILON_ERROR, 0.15f)) {
            g_TotalErrors++;
        }
        g_Verify = false;
    }
    glutSwapBuffers();

    cutilCheckError(cutStopTimer(timer));  

    computeFPS();

    glutPostRedisplay();
}
// This is the normal display path
This is the normal display path
This is the normal display path
void display(void) 
{  
    cutilCheckError(cutStartTimer(timer));  
    Pixel *data = NULL;
	cutilSafeCall(cudaGraphicsMapResources(1, &cuda_pbo_resource, 0));
    size_t num_bytes; 
    cutilSafeCall(cudaGraphicsResourceGetMappedPointer((void **)&data, &num_bytes,  
						       cuda_pbo_resource));
	sobelFilter(data, imWidth, imHeight, g_SobelDisplayMode, imageScale );
    cutilSafeCall(cudaGraphicsUnmapResources(1, &cuda_pbo_resource, 0));
    glClear(GL_COLOR_BUFFER_BIT);
    glBindTexture(GL_TEXTURE_2D, texid);
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo_buffer);
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, imWidth, imHeight, 
                   GL_LUMINANCE, GL_UNSIGNED_BYTE, OFFSET(0));
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
    glDisable(GL_DEPTH_TEST);
    glEnable(GL_TEXTURE_2D);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glBegin(GL_QUADS);
    glVertex2f(0, 0); glTexCoord2f(0, 0);
    glVertex2f(0, 1); glTexCoord2f(1, 0);
    glVertex2f(1, 1); glTexCoord2f(1, 1);
    glVertex2f(1, 0); glTexCoord2f(0, 1);
    glEnd();
    glBindTexture(GL_TEXTURE_2D, 0);
    if (g_CheckRender && g_CheckRender->IsQAReadback() && g_Verify) {
        printf("> (Frame %d) readback BackBuffer\n", frameCount);
        g_CheckRender->readback( imWidth, imHeight );
        g_CheckRender->savePPM ( sOriginal_ppm[g_Index], true, NULL );
        if (!g_CheckRender->PPMvsPPM(sOriginal_ppm[g_Index], sReference_ppm[g_Index], MAX_EPSILON_ERROR, 0.15f)) {
            g_TotalErrors++;
        }
        g_Verify = false;
    }
    glutSwapBuffers();
    cutilCheckError(cutStopTimer(timer));  
    computeFPS();
    glutPostRedisplay();
}
void display ( void ) { cutilCheckError ( cutStartTimer ( timer ) ) ; Pixel * data = NULL ; cutilSafeCall ( cudaGraphicsMapResources ( 1 , & cuda_pbo_resource , 0 ) ) ; size_t num_bytes ; cutilSafeCall ( cudaGraphicsResourceGetMappedPointer ( ( void * * ) & data , & num_bytes , cuda_pbo_resource ) ) ; sobelFilter ( data , imWidth , imHeight , g_SobelDisplayMode , imageScale ) ; cutilSafeCall ( cudaGraphicsUnmapResources ( 1 , & cuda_pbo_resource , 0 ) ) ; glClear ( GL_COLOR_BUFFER_BIT ) ; glBindTexture ( GL_TEXTURE_2D , texid ) ; glBindBuffer ( GL_PIXEL_UNPACK_BUFFER , pbo_buffer ) ; glTexSubImage2D ( GL_TEXTURE_2D , 0 , 0 , 0 , imWidth , imHeight , GL_LUMINANCE , GL_UNSIGNED_BYTE , OFFSET ( 0 ) ) ; glBindBuffer ( GL_PIXEL_UNPACK_BUFFER , 0 ) ; glDisable ( GL_DEPTH_TEST ) ; glEnable ( GL_TEXTURE_2D ) ; glTexParameterf ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ) ; glTexParameterf ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ) ; glTexParameterf ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , GL_REPEAT ) ; glTexParameterf ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_REPEAT ) ; glBegin ( GL_QUADS ) ; glVertex2f ( 0 , 0 ) ; glTexCoord2f ( 0 , 0 ) ; glVertex2f ( 0 , 1 ) ; glTexCoord2f ( 1 , 0 ) ; glVertex2f ( 1 , 1 ) ; glTexCoord2f ( 1 , 1 ) ; glVertex2f ( 1 , 0 ) ; glTexCoord2f ( 0 , 1 ) ; glEnd ( ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; if ( g_CheckRender && g_CheckRender -> IsQAReadback ( ) && g_Verify ) { printf ( " \n " , frameCount ) ; g_CheckRender -> readback ( imWidth , imHeight ) ; g_CheckRender -> savePPM ( sOriginal_ppm [ g_Index ] , true , NULL ) ; if ( ! g_CheckRender -> PPMvsPPM ( sOriginal_ppm [ g_Index ] , sReference_ppm [ g_Index ] , MAX_EPSILON_ERROR , 0.15f ) ) { g_TotalErrors ++ ; } g_Verify = false ; } glutSwapBuffers ( ) ; cutilCheckError ( cutStopTimer ( timer ) ) ; computeFPS ( ) ; glutPostRedisplay ( ) ; }
This is the normal display path
This is the normal display path
// Sobel operation // map PBO to get CUDA device pointer //printf("CUDA mapped PBO: May access %ld bytes\n", num_bytes);