static void _update_pf_viewer(QSP_ARG_DECL Platform_Viewer *pvp, Data_Obj *dp) { #ifdef HAVE_OPENGL int t; //cudaError_t e; // unmap buffer before using w/ GL if( BUF_IS_MAPPED(dp) ){ if( (*PF_UNMAPBUF_FN(PFDEV_PLATFORM(OBJ_PFDEV(dp)))) (QSP_ARG dp) < 0 ) { warn("update_pf_viewer: buffer unmap error!?"); } CLEAR_OBJ_FLAG_BITS(dp, DT_BUF_MAPPED); // propagate change to children and parents propagate_flag(dp,DT_BUF_MAPPED); } glClear(GL_COLOR_BUFFER_BIT); glBindTexture(GL_TEXTURE_2D, OBJ_TEX_ID(dp)); // is glBindBuffer REALLY part of libGLEW??? //#ifdef HAVE_LIBGLEW glBindBuffer(GL_PIXEL_UNPACK_BUFFER, OBJ_BUF_ID(dp)); //#endif // HAVE_LIBGLEW t=gl_pixel_type(dp); glTexSubImage2D(GL_TEXTURE_2D, 0, // target, level 0, 0, // x0, y0 OBJ_COLS(dp), OBJ_ROWS(dp), // dx, dy t, GL_UNSIGNED_BYTE, // type OFFSET(0)); // offset into PIXEL_UNPACK_BUFFER //#ifdef HAVE_LIBGLEW glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); //#endif // HAVE_LIBGLEW glBegin(GL_QUADS); glTexCoord2f(0, 1); glVertex2f(-1.0, -1.0); glTexCoord2f(0, 0); glVertex2f(-1.0, 1.0); glTexCoord2f(1, 0); glVertex2f(1.0, 1.0); glTexCoord2f(1, 1); glVertex2f(1.0, -1.0); glEnd(); glBindTexture(GL_TEXTURE_2D, 0); if( (*PF_MAPBUF_FN(PFDEV_PLATFORM(OBJ_PFDEV(dp))))(QSP_ARG dp) < 0 ){ warn("update_pf_viewer: Error mapping buffer!?"); } SET_OBJ_FLAG_BITS(dp, DT_BUF_MAPPED); // propagate change to children and parents propagate_flag(dp,DT_BUF_MAPPED); #else // ! HAVE_OPENGL NO_OGL_MSG #endif // ! HAVE_OPENGL }
static int _ocl_obj_alloc(QSP_ARG_DECL Data_Obj *dp, dimension_t size, int align ) { OBJ_DATA_PTR(dp) = ocl_mem_alloc(OBJ_PFDEV(dp), size, align ); if( OBJ_DATA_PTR(dp) == NULL ){ sprintf(ERROR_STRING,"ocl_obj_alloc: error allocating memory for object %s!?",OBJ_NAME(dp)); warn(ERROR_STRING); return -1; } return 0; }
static int ocl_unmap_buf(QSP_ARG_DECL Data_Obj *dp) { #ifdef HAVE_OPENGL cl_int status; // Release ownership of GL texture for OpenCL Image status = clEnqueueReleaseGLObjects(//cl_cmd_queue, OCLDEV_QUEUE(OBJ_PFDEV(dp)), 1, // num objects (const cl_mem *)(& OBJ_DATA_PTR(dp)), // cl_mem *mem_objects 0, // num_events_in_wait_list NULL, // const cl_event *wait_list NULL // cl_event *event ); if( status != CL_SUCCESS ){ report_ocl_error(status, "clEnqueueReleaseGLObjects"); return -1; } // Force pending CL commands to get executed status = clFlush( OCLDEV_QUEUE(OBJ_PFDEV(dp)) ); if( status != CL_SUCCESS ){ report_ocl_error(status, "clFlush"); } // Bind GL texture and use for rendering glBindTexture( //gl_texture_target, GL_TEXTURE_2D, //gl_texture_id OBJ_TEX_ID(dp) ); return 0; #else // ! HAVE_OPENGL warn("ocl_unmap_buf: Sorry, no OpenGL support in this build!?"); return -1; #endif // ! HAVE_OPENGL }
static int ocl_register_buf(QSP_ARG_DECL Data_Obj *dp) { if( opengl_prohibited ) error1("ocl_register_buf: Need to specify GL window BEFORE initializing OpenCL!?"); #ifdef HAVE_OPENGL cl_mem img; cl_int status; // Texture2D deprecated on Apple //fprintf(stderr,"obj %s has texture id %d\n",OBJ_NAME(dp),OBJ_TEX_ID(dp)); //fprintf(stderr,"obj %s has platform device %s\n",OBJ_NAME(dp),PFDEV_NAME(OBJ_PFDEV(dp))); //advise("ocl_register_buf calling clCreateFromGLBuffer"); //longlist(QSP_ARG dp); // Used to call clCreateFromGLTexture, but this works: img = clCreateFromGLBuffer( OCLDEV_CTX( OBJ_PFDEV(dp) ), // OCL context CL_MEM_READ_WRITE, // flags OBJ_TEX_ID(dp), // from glBufferData? &status); if( status != CL_SUCCESS ){ report_ocl_error(status, "clCreateFromGLTexture"); return -1; } else { SET_OBJ_DATA_PTR(dp,img); } // dp is a special buffer object... //cl_mem memobj; //cl_mem = clCreate return 0; #else // ! HAVE_OPENGL warn("ocl_register_buf: Sorry, no OpenGL support in this build!?"); return -1; #endif // ! HAVE_OPENGL }
static int ocl_map_buf(QSP_ARG_DECL Data_Obj *dp) { cl_int status; glFlush(); // Acquire ownership of GL texture for OpenCL Image status = clEnqueueAcquireGLObjects(//cl_cmd_queue, OCLDEV_QUEUE(OBJ_PFDEV(dp)), 1, // num_images (const cl_mem *)(& OBJ_DATA_PTR(dp)), 0, 0, 0); if( status != CL_SUCCESS ){ report_ocl_error(status, "clEnqueueAcquireGLObjects"); return -1; } // Now ready to execute kernel or other OpenCL operations ... ? return 0; }
// This is the normal display path static void update_pf_viewer(QSP_ARG_DECL Platform_Viewer *pvp, Data_Obj *dp) { #ifdef HAVE_OPENGL int t; //cudaError_t e; // unmap buffer before using w/ GL if( BUF_IS_MAPPED(dp) ){ if( (*PF_UNMAPBUF_FN(PFDEV_PLATFORM(OBJ_PFDEV(dp)))) (QSP_ARG dp) < 0 ) { WARN("update_pf_viewer: buffer unmap error!?"); } #ifdef FOOBAR e = cudaGLUnmapBufferObject( OBJ_BUF_ID(dp) ); if( e != cudaSuccess ){ describe_cuda_driver_error2("update_pf_viewer", "cudaGLUnmapBufferObject",e); NERROR1("failed to unmap buffer object"); } #endif // FOOBAR CLEAR_OBJ_FLAG_BITS(dp, DT_BUF_MAPPED); // propagate change to children and parents propagate_flag(dp,DT_BUF_MAPPED); } // //bind_texture(OBJ_DATA_PTR(dp)); glClear(GL_COLOR_BUFFER_BIT); /* sprintf(ERROR_STRING,"update_pf_viewer: tex_id = %d, buf_id = %d", OBJ_TEX_ID(dp),OBJ_BUF_ID(dp)); advise(ERROR_STRING); */ glBindTexture(GL_TEXTURE_2D, OBJ_TEX_ID(dp)); // is glBindBuffer REALLY part of libGLEW??? //#ifdef HAVE_LIBGLEW glBindBuffer(GL_PIXEL_UNPACK_BUFFER, OBJ_BUF_ID(dp)); //#endif // HAVE_LIBGLEW #ifdef FOOBAR switch(OBJ_COMPS(dp)){ /* what used to be here??? */ } #endif /* FOOBAR */ t=gl_pixel_type(dp); glTexSubImage2D(GL_TEXTURE_2D, 0, // target, level 0, 0, // x0, y0 OBJ_COLS(dp), OBJ_ROWS(dp), // dx, dy t, GL_UNSIGNED_BYTE, // type OFFSET(0)); // offset into PIXEL_UNPACK_BUFFER //#ifdef HAVE_LIBGLEW glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); //#endif // HAVE_LIBGLEW glBegin(GL_QUADS); glTexCoord2f(0, 1); glVertex2f(-1.0, -1.0); glTexCoord2f(0, 0); glVertex2f(-1.0, 1.0); glTexCoord2f(1, 0); glVertex2f(1.0, 1.0); glTexCoord2f(1, 1); glVertex2f(1.0, -1.0); glEnd(); glBindTexture(GL_TEXTURE_2D, 0); #ifdef FOOBAR e = cudaGLMapBufferObject( &OBJ_DATA_PTR(dp), OBJ_BUF_ID(dp) ); if( e != cudaSuccess ){ WARN("Error mapping buffer object!?"); // should we return now, with possibly other cleanup??? } #endif // FOOBAR if( (*PF_MAPBUF_FN(PFDEV_PLATFORM(OBJ_PFDEV(dp))))(QSP_ARG dp) < 0 ){ WARN("update_pf_viewer: Error mapping buffer!?"); } SET_OBJ_FLAG_BITS(dp, DT_BUF_MAPPED); // propagate change to children and parents propagate_flag(dp,DT_BUF_MAPPED); #else // ! HAVE_OPENGL NO_OGL_MSG #endif // ! HAVE_OPENGL }
static int change_size(QSP_ARG_DECL Data_Obj *dst_dp,Data_Obj *src_dp ) { Dimension_Set ef, *enlargement_factor=&ef; Dimension_Set rf, *reduction_factor=&rf; Vec_Obj_Args oa1, *oap=&oa1; Dimension_Set size_ds, n_ds; Dimension_Set *size_dsp=(&size_ds), *n_dsp=(&n_ds); Data_Obj *src_ss_dp, *dst_ss_dp; dimension_t i,j,k,l,m; index_t offsets[N_DIMENSIONS]={0,0,0,0,0}; incr_t dst_incrs[N_DIMENSIONS], src_incrs[N_DIMENSIONS]; index_t dst_indices[N_DIMENSIONS]={0,0,0,0,0}, src_indices[N_DIMENSIONS]={0,0,0,0,0}; /* For simplicity, we don't allow size changes to be combined with conversions */ if( !dp_same_prec(QSP_ARG dst_dp,src_dp,"change_size") ) return(-1); for(i=0;i<N_DIMENSIONS;i++){ if( OBJ_TYPE_DIM(dst_dp,i) > OBJ_TYPE_DIM(src_dp,i) ){ /* enlargement - subsample the destination */ SET_DIMENSION(enlargement_factor,i, floor( OBJ_TYPE_DIM(dst_dp,i) / OBJ_TYPE_DIM(src_dp,i) ) ); SET_DIMENSION(reduction_factor,i, 0); SET_DIMENSION(size_dsp,i, OBJ_TYPE_DIM(src_dp,i) ); SET_DIMENSION(n_dsp,i, DIMENSION(enlargement_factor,i) ); dst_incrs[i] = DIMENSION(n_dsp,i); src_incrs[i] = 1; } else { /* reduction - subsample the source */ SET_DIMENSION(reduction_factor,i, ceil( OBJ_TYPE_DIM(src_dp,i) / OBJ_TYPE_DIM(dst_dp,i) ) ); SET_DIMENSION(enlargement_factor,i, 0 ); SET_DIMENSION(size_dsp,i, floor( OBJ_TYPE_DIM(src_dp,i) / DIMENSION(reduction_factor,i) ) ); /* We don't need to do this multiple times, just pick one and do it */ /*SET_DIMENSION(n_dsp,i, DIMENSION(reduction_factor,i) ); */ SET_DIMENSION(n_dsp,i, 1); src_incrs[i] = DIMENSION(reduction_factor,i); dst_incrs[i] = 1; } } /* make the subsamples. * the column increment is expressed in columns, etc. */ dst_ss_dp=make_subsamp(QSP_ARG "chngsize_dst_obj",dst_dp,size_dsp,offsets,dst_incrs); src_ss_dp=make_subsamp(QSP_ARG "chngsize_src_obj",src_dp,size_dsp,offsets,src_incrs); clear_obj_args(oap); SET_OA_DEST(oap,dst_ss_dp); SET_OA_SRC_OBJ(oap,0, src_ss_dp); SET_OA_ARGSTYPE(oap, REAL_ARGS); SET_OA_PFDEV(oap,OBJ_PFDEV(dst_dp)); for(i=0;i<DIMENSION(n_dsp,4);i++){ /* foreach sequence to copy */ if( dst_incrs[4] > 1 ) dst_indices[4]=i; else src_indices[4]=i; for(j=0;j<DIMENSION(n_dsp,3);j++){ /* foreach frame to copy */ if( dst_incrs[3] > 1 ) dst_indices[3]=j; else src_indices[3]=j; for(k=0;k<DIMENSION(n_dsp,2);k++){ /* foreach row */ if( dst_incrs[2] > 1 ) dst_indices[2]=k; else src_indices[2]=k; for(l=0;l<DIMENSION(n_dsp,1);l++){ /* foreach col */ if( dst_incrs[1] > 1 ) dst_indices[1]=l; else src_indices[1]=l; for(m=0;m<DIMENSION(n_dsp,0);m++){ /* foreach comp */ if( dst_incrs[0] > 1 ) dst_indices[0]=m; else src_indices[0]=m; /* relocate the appropriate subsample */ SET_OBJ_DATA_PTR(dst_ss_dp, multiply_indexed_data(dst_dp,dst_indices) ); SET_OBJ_DATA_PTR(src_ss_dp, multiply_indexed_data(src_dp,src_indices) ); // This doesn't check for cuda obj... //vmov(oap); perf_vfunc(QSP_ARG FVMOV, oap ); } } } } } delvec(QSP_ARG dst_ss_dp); delvec(QSP_ARG src_ss_dp); SET_OBJ_FLAG_BITS(dst_dp, DT_ASSIGNED); return(0); }