예제 #1
0
int OCLDeviceManager::init(eDeviceType type) {
    bool isCpu = type == CPU;
    ocl_args_d_t** oclArgs;
    if (isCpu) {
        if (ocl_cpu)
            return 0;
        ocl_cpu = new ocl_args_d_t();
        oclArgs = &ocl_cpu;

    } else {

        if (ocl_gpu)
            return 0;
        ocl_gpu = new ocl_args_d_t();
        oclArgs = &ocl_gpu;

    }
    data_args_d_t args;
    args.preferGpu = !isCpu;
    args.preferCpu = isCpu;
    args.vendorName = NULL;
    int error_code;
    error_code = InitOpenCL(*oclArgs, &args);
    if (CL_SUCCESS != error_code)
    {
        LogError("InitOpenCL returned %s.", TranslateOpenCLError(error_code));
        delete *oclArgs;
        *oclArgs = NULL;;
    }
    return error_code;

}
예제 #2
0
int main(int argc, char* argv[])
{
    InitOpenCL();
    
    memset(viewMatrix, 0, sizeof(float)*16);
    viewMatrix[0] = viewMatrix[5] = viewMatrix[10] = viewMatrix[15] = 1;
    
    
    SDL_Init(SDL_INIT_EVERYTHING);

        Uint32 flags = SDL_WINDOW_OPENGL;
        if ( kFullscreen ){
            flags |= SDL_WINDOW_FULLSCREEN;

            SDL_ShowCursor(0);
        }

        window = SDL_CreateWindow("RayTracer",
                SDL_WINDOWPOS_UNDEFINED,
                SDL_WINDOWPOS_UNDEFINED,
                kWidth, kHeight,
                flags);
    
    SDL_GL_CreateContext(window);
    
    SDL_WarpMouseInWindow(window, kWidth/2.0f, kHeight/2.0f);
    
    glEnable(GL_TEXTURE_2D);
    
        bool loop = true;
        int lastTicks = SDL_GetTicks();
        while(loop){
            int delta = SDL_GetTicks() - lastTicks;
            lastTicks = SDL_GetTicks();
            SDL_Event e;
            while(SDL_PollEvent(&e)){
                if ( e.type == SDL_QUIT){
                    loop = false;
                }
                else if ( e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE){
                    loop = false;
                }
            }
        
            delta *= 0.1;
        Update(delta);
        Render(delta);
        
            std::stringstream ss;
            ss << 1000.0f / delta ;
            SDL_SetWindowTitle(window, ss.str().c_str());
        }
    
    SDL_DestroyWindow(window);
    return 0;
}
예제 #3
0
void OCL_Environment::Initialize()
{
	InitOpenCL();

	// Add programs
	AddProgram(
		CreateProgram<VectorAddProgram> (m_context, m_deviceId, "vector_add_kernel.cl")
	);

}
예제 #4
0
파일: raytracer.cpp 프로젝트: 3dct/open_iA
Engine::Engine(SETTINGS * settings, float * dc_cuda_avpl_buff,	float * dc_cuda_dipang_buff  )
{
	cuda_avpl_buff = dc_cuda_avpl_buff;
	cuda_dipang_buff = dc_cuda_dipang_buff;
	m_batchSize = settings->BATCH_SIZE;
	m_Scene = new Scene();
	//renders = a_renders;
	position[0] = position[1] = position[2] = 0.0f;
	curBatchRenders = new RenderFromPosition[m_batchSize];
	m_cut_AABBs = 0;
	m_cutAABBList = 0;
	m_cutAABBListSize = 0;
	s = settings;
	InitOpenCL();
}
LayerSegmentsTreeGPU* SegmentsTreeGPU::CreateNewLayer()
{
    countLayer++;

    size_t dim = scanData->sizeX * scanData->sizeY * scanData->sizeZ;

    LayerSegmentsTreeGPU* oldLayer = GetOldLayer();

    int iNumElements0 = oldLayer->segmentCount + 1;	// Length of float arrays to process (odd # for illustration)
    size_t szGlobalWorkSize0;        // 1D var for Total # of work items
    size_t szLocalWorkSize0;		    // 1D var for # of work items in the work group
    // set and log Global and Local work size dimensions
    szLocalWorkSize0 = 256;
    szGlobalWorkSize0 = size_t(ceil(double(iNumElements0) / double (szLocalWorkSize0)) * szLocalWorkSize0);  // rounded up to the nearest multiple of the LocalWorkSize

    int iNumElements1 = dim + 2;	// Length of float arrays to process (odd # for illustration)
    size_t szGlobalWorkSize1;        // 1D var for Total # of work items
    size_t szLocalWorkSize1;		    // 1D var for # of work items in the work group
    // set and log Global and Local work size dimensions
    szLocalWorkSize1 = 256;
    szGlobalWorkSize1 = size_t(ceil(double(iNumElements1) / double (szLocalWorkSize1)) * szLocalWorkSize1);  // rounded up to the nearest multiple of the LocalWorkSize

    int iNumElements2 = (dim + 2) * 7;	// Length of float arrays to process (odd # for illustration)
    size_t szGlobalWorkSize2;        // 1D var for Total # of work items
    size_t szLocalWorkSize2;		    // 1D var for # of work items in the work group
    // set and log Global and Local work size dimensions
    szLocalWorkSize2 = 256;
    szGlobalWorkSize2 = size_t(ceil(double(iNumElements2) / double (szLocalWorkSize2)) * szLocalWorkSize2);  // rounded up to the nearest multiple of the LocalWorkSize



    //создание нового уровня
    LayerSegmentsTreeGPU* newLayer = new LayerSegmentsTreeGPU();
    oldLayer->up = newLayer;
    newLayer->down = oldLayer;

    newLayer->indexSegments = new size_t [szGlobalWorkSize1];
    newLayer->indexVoxel = new VoxelGPU [dim + 2];

    for (size_t i = 0; i < dim; i++)
    {
        newLayer->indexSegments[i] = oldLayer->indexSegments[i];
        newLayer->indexVoxel[i].index = oldLayer->indexVoxel[i].index;
        if (oldLayer->indexVoxel[i].next != 0)
            newLayer->indexVoxel[i].next = &newLayer->indexVoxel[oldLayer->indexVoxel[i].next->index];
        else
            newLayer->indexVoxel[i].next = 0;
    }

    for (size_t i = 0; i < dim; i++)
    {
        if (oldLayer->indexVoxel[i].next != 0)
            if ((newLayer->indexVoxel[i].next->index - oldLayer->indexVoxel[i].next->index) != 0)
                int ttttt = 0;
    }

    size_t* countVoxel = new size_t [oldLayer->segmentCount + 1];
    short* weightSegment = new short [szGlobalWorkSize0];
    size_t* startIndexVoxel = new size_t [oldLayer->segmentCount + 1];
    for(size_t i = 0; i < oldLayer->segmentCount; i++)
    {
        startIndexVoxel[i] = oldLayer->startIndexVoxel[i];
        countVoxel[i] = oldLayer->countVoxel[i];
        weightSegment[i] = oldLayer->maxWeight[i];
    }

    size_t tt = sizeof(short);
    size_t uuu = size_t(tt * (dim + 2) * 26 / (1024 * 1024));

    short* segmentAdjacents = new short [szGlobalWorkSize2];
    for (size_t i = 0; i < ((dim + 2) * 7); i++)
    {
        segmentAdjacents[i] = maxValue;
    }

    bool* isNotSegmentVisit = new bool [oldLayer->segmentCount + 2];
    for (size_t i = 0; i < oldLayer->segmentCount + 2; i++)
        isNotSegmentVisit[i] = true;

    //индексы смещения
    char relativeIndexMatrix[8][3] = {//i,j,k
        {0,0,0},//0
        {0,0,1},//1
        {0,1,0},//2
        {0,1,1},//3
        {1,0,0},//4
        {1,0,1},//5
        {1,1,0},//6
        {1,1,1},//7

    };

    bool f = false;
    size_t gi = 0;





    InitOpenCL(iNumElements0, szGlobalWorkSize0, szLocalWorkSize0, iNumElements1, szGlobalWorkSize1, szLocalWorkSize1,
               iNumElements2, szGlobalWorkSize2, szLocalWorkSize2, scanData->sizeX, scanData->sizeY, scanData->sizeZ);



    while ((!f) && (gi < oldLayer->segmentCount))
    {
        f = true;

        //Kernel(scanData->sizeX, scanData->sizeY, scanData->sizeZ, weightSegment, newLayer->indexSegments, segmentAdjacents);
        KernelOpenCl(weightSegment, newLayer->indexSegments, segmentAdjacents, iNumElements0, szGlobalWorkSize0, szLocalWorkSize0,
                     iNumElements1, szGlobalWorkSize1, szLocalWorkSize1,
                     iNumElements2, szGlobalWorkSize2, szLocalWorkSize2, scanData->sizeX, scanData->sizeY, scanData->sizeZ);

        int indexAdjacentsVoxel = 0;
        size_t indexCurrentSegment = 0;
        size_t indexAdjacentsSegment = 0;

        VoxelGPU* currentVoxel = 0;
        VoxelGPU newVoxels;
        VoxelGPU* newVoxelsEnd = 0;
        VoxelGPU* oldVoxel = 0;
        VoxelGPU* currentAdjacentsVoxel = 0;


        for (size_t t = 0; t < oldLayer->segmentCount; t++)
        {
            if (isNotSegmentVisit[t])
            {
                currentVoxel = &newLayer->indexVoxel[startIndexVoxel[t]];
                newVoxels.next = 0;
                newVoxelsEnd = 0;
                oldVoxel = 0;
                currentAdjacentsVoxel = 0;
                while (currentVoxel != 0)
                {
                    int indexAdjacentsVoxel = 0;

                    for (size_t k = 1; k < 8; k++)
                    {
                        indexAdjacentsVoxel = currentVoxel->index * 7 + k - 1;
                        size_t siindexAdjacentsVoxel2 = currentVoxel->index + relativeIndexMatrix[k][0] + relativeIndexMatrix[k][1] * scanData->sizeX +
                                                        relativeIndexMatrix[k][2] * scanData->sizeX * scanData->sizeY;
                        if (siindexAdjacentsVoxel2 < dim)
                        {
                            indexAdjacentsSegment = oldLayer->indexSegments[siindexAdjacentsVoxel2];
                            indexCurrentSegment = t;
                            if (isNotSegmentVisit[indexAdjacentsSegment] && isNotSegmentVisit[indexCurrentSegment])
                            {

                                if ((segmentAdjacents[indexAdjacentsVoxel] < step) && (indexAdjacentsSegment != indexCurrentSegment))
                                {

                                    if (newVoxels.next != 0)
                                    {
                                        newVoxelsEnd->next = &newLayer->indexVoxel[startIndexVoxel[indexAdjacentsSegment]];
                                    }
                                    else
                                    {
                                        newVoxels.next = &newLayer->indexVoxel[startIndexVoxel[indexAdjacentsSegment]];
                                    }
                                    currentAdjacentsVoxel = &newLayer->indexVoxel[startIndexVoxel[indexAdjacentsSegment]];
                                    isNotSegmentVisit[indexAdjacentsSegment] = false;

                                    while (currentAdjacentsVoxel->next != 0)
                                    {
                                        newLayer->indexSegments[currentAdjacentsVoxel->index] = indexCurrentSegment;
                                        currentAdjacentsVoxel = currentAdjacentsVoxel->next;
                                    }
                                    newVoxelsEnd = currentAdjacentsVoxel;
                                    newLayer->indexSegments[currentAdjacentsVoxel->index] = indexCurrentSegment;
                                    weightSegment[indexCurrentSegment] = max(weightSegment[indexCurrentSegment], weightSegment[indexAdjacentsSegment]);
                                    countVoxel[indexCurrentSegment] = countVoxel[indexCurrentSegment] + countVoxel[indexAdjacentsSegment];
                                }
                            }
                        }
                    }

                    oldVoxel = currentVoxel;
                    currentVoxel = currentVoxel->next;
                }
                if (newVoxels.next != 0)
                    f = false;
                oldVoxel->next = newVoxels.next;
                size_t yyy = 0;
                currentVoxel = &newLayer->indexVoxel[startIndexVoxel[t]];
                while (currentVoxel != 0)
                {
                    yyy++;
                    currentVoxel = currentVoxel->next;
                }
                if (yyy != countVoxel[t])
                    int ggg = 0;

            }
        }
        gi++;
    }

    newLayer->segmentCount = 0;
    for (size_t i = 0; i < oldLayer->segmentCount; i++)
    {
        if (isNotSegmentVisit[i])
        {
            newLayer->segmentCount++;
        }
    }

    newLayer->countVoxel = new size_t [newLayer->segmentCount + 2];
    newLayer->startIndexVoxel = new size_t [newLayer->segmentCount + 2];
    newLayer->maxWeight = new short [newLayer->segmentCount + 2];
    newLayer->minWeight = new short [newLayer->segmentCount + 2];

    size_t ind = 0;
    VoxelGPU* voxel = 0;
    newLayer->maxCapacity = 0;
    size_t count = 0;
    size_t c2 = 0;
    short minw = 0;
    for (size_t i = 0; i < oldLayer->segmentCount; i++)
    {
        minw = 0;
        if (isNotSegmentVisit[i])
        {
            voxel = &newLayer->indexVoxel[startIndexVoxel[i]];
            while (voxel != 0)
            {
                newLayer->indexSegments[voxel->index] = ind;

                count++;
                if (minw > scanData->data[voxel->index])
                    minw = scanData->data[voxel->index];
                voxel = voxel->next;
            }
            newLayer->countVoxel[ind] = countVoxel[i];
            c2 += countVoxel[i];
            newLayer->startIndexVoxel[ind] = startIndexVoxel[i];
            newLayer->maxWeight[ind] = weightSegment[i];
            newLayer->minWeight[ind] = minw;
            newLayer->maxCapacity = max (newLayer->maxCapacity, newLayer->countVoxel[ind]);
            ind++;
        }
    }

    if (count != dim)
        int ggg = 0;

    ReleaseOpenCL();
    // Free host memory



    delete [] countVoxel;
    delete [] weightSegment;
    delete [] startIndexVoxel;
    delete [] isNotSegmentVisit;
    delete [] segmentAdjacents;
    newLayer->segmentsTree = this;
    return newLayer;
}
예제 #6
0
	void TestCamera()
	{
		InitOpenCL();
		//TCHAR szDeviceName[80];
		//TCHAR szDeviceVersion[80];

		//for (int wIndex = 0; wIndex < 10; wIndex++) 
		//{
		//	if (capGetDriverDescription(
		//		wIndex, 
		//		szDeviceName, 
		//		sizeof (szDeviceName), 
		//		szDeviceVersion, 
		//		sizeof (szDeviceVersion)
		//		)) 
		//	{
		//		// Append name to list of installed capture drivers
		//		// and then let the user select a driver to use.
		//	}
		//} 

		//HWND hWndC = capCreateCaptureWindow(TEXT("PunkCapture"),
		//	WS_CHILD | WS_VISIBLE, 0, 0, 160, 120, *System::Window::Instance(), 1);

		//SendMessage (hWndC, WM_CAP_DRIVER_CONNECT, 0, 0L); 
		//// 
		//// Or, use the macro to connect to the MSVIDEO driver: 
		//// fOK = capDriverConnect(hWndC, 0); 
		//// 
		//// Place code to set up and capture video here. 
		//// 
		////capDriverDisconnect (hWndC); 

		//CAPDRIVERCAPS CapDriverCaps = { }; 
		//CAPSTATUS     CapStatus = { };

		//capDriverGetCaps(hWndC, &CapDriverCaps, sizeof(CAPDRIVERCAPS)); 

		//// Video source dialog box. 
		//if (CapDriverCaps.fHasDlgVideoSource)
		//{
		//	capDlgVideoSource(hWndC); 
		//}

		//// Video format dialog box. 
		//if (CapDriverCaps.fHasDlgVideoFormat) 
		//{
		//	capDlgVideoFormat(hWndC); 

		//	// Are there new image dimensions?
		//	capGetStatus(hWndC, &CapStatus, sizeof (CAPSTATUS));

		//	// If so, notify the parent of a size change.
		//} 

		//// Video display dialog box. 
		//if (CapDriverCaps.fHasDlgVideoDisplay)
		//{
		//	capDlgVideoDisplay(hWndC); 
		//}


		HRESULT hr;
		IGraphBuilder*  graph= 0;  hr = CoCreateInstance( CLSID_FilterGraph, 0, CLSCTX_INPROC,IID_IGraphBuilder, (void **)&graph );
		IMediaControl*  ctrl = 0;  hr = graph->QueryInterface( IID_IMediaControl, (void **)&ctrl );

		ICreateDevEnum* devs = 0;  hr = CoCreateInstance (CLSID_SystemDeviceEnum, 0, CLSCTX_INPROC, IID_ICreateDevEnum, (void **) &devs);
		IEnumMoniker*   cams = 0;  hr = devs?devs->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &cams, 0):0;  
		IMoniker*       mon  = 0;  hr = cams->Next (1,&mon,0);  // get first found capture device (webcam?)    
		IBaseFilter*    cam  = 0;  hr = mon->BindToObject(0,0,IID_IBaseFilter, (void**)&cam);
		hr = graph->AddFilter(cam, L"Capture Source"); // add web cam to graph as source
		IEnumPins*      pins = 0;  hr = cam?cam->EnumPins(&pins):0;   // we need output pin to autogenerate rest of the graph
		IPin*           pin  = 0;  hr = pins?pins->Next(1,&pin, 0):0; // via graph->Render
		hr = graph->Render(pin); // graph builder now builds whole filter chain including MJPG decompression on some webcams
		IEnumFilters*   fil  = 0;  hr = graph->EnumFilters(&fil); // from all newly added filters
		IBaseFilter*    rnd  = 0;  hr = fil->Next(1,&rnd,0); // we find last one (renderer)
		hr = rnd->EnumPins(&pins);  // because data we are intersted in are pumped to renderers input pin 
		hr = pins->Next(1,&pin, 0); // via Receive member of IMemInputPin interface
		IMemInputPin*   mem  = 0;  hr = pin->QueryInterface(IID_IMemInputPin,(void**)&mem);

		DsHook(mem,6,Receive); // so we redirect it to our own proc to grab image data

		hr = ctrl->Run();   

	};