Merge pull request #1917 from alalek:ocl_d3d
This commit is contained in:
1134
modules/core/src/directx.cpp
Normal file
1134
modules/core/src/directx.cpp
Normal file
File diff suppressed because it is too large
Load Diff
55
modules/core/src/directx.inc.hpp
Normal file
55
modules/core/src/directx.inc.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors as is and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the copyright holders or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#if defined(HAVE_DIRECTX)
|
||||
#include <d3d11.h>
|
||||
#include <d3d10.h>
|
||||
#include <d3d9.h>
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
#include "opencv2/core/opencl/runtime/opencl_core.hpp"
|
||||
|
||||
#include <CL/cl_d3d11.h>
|
||||
#include <CL/cl_d3d10.h>
|
||||
#include <CL/cl_dx9_media_sharing.h>
|
||||
#endif // HAVE_OPENCL
|
||||
|
||||
#endif // HAVE_DIRECTX
|
@@ -1433,21 +1433,6 @@ void finish2()
|
||||
void release() { if( CV_XADD(&refcount, -1) == 1 ) delete this; } \
|
||||
int refcount
|
||||
|
||||
class Platform
|
||||
{
|
||||
public:
|
||||
Platform();
|
||||
~Platform();
|
||||
Platform(const Platform& p);
|
||||
Platform& operator = (const Platform& p);
|
||||
|
||||
void* ptr() const;
|
||||
static Platform& getDefault();
|
||||
protected:
|
||||
struct Impl;
|
||||
Impl* p;
|
||||
};
|
||||
|
||||
struct Platform::Impl
|
||||
{
|
||||
Impl()
|
||||
@@ -1843,6 +1828,12 @@ const Device& Device::getDefault()
|
||||
|
||||
struct Context2::Impl
|
||||
{
|
||||
Impl()
|
||||
{
|
||||
refcount = 1;
|
||||
handle = 0;
|
||||
}
|
||||
|
||||
Impl(int dtype0)
|
||||
{
|
||||
refcount = 1;
|
||||
@@ -1925,7 +1916,6 @@ struct Context2::Impl
|
||||
|
||||
cl_context handle;
|
||||
std::vector<Device> devices;
|
||||
bool initialized;
|
||||
|
||||
typedef ProgramSource2::hash_t hash_t;
|
||||
|
||||
@@ -2007,22 +1997,29 @@ const Device& Context2::device(size_t idx) const
|
||||
return !p || idx >= p->devices.size() ? dummy : p->devices[idx];
|
||||
}
|
||||
|
||||
Context2& Context2::getDefault()
|
||||
Context2& Context2::getDefault(bool initialize)
|
||||
{
|
||||
static Context2 ctx;
|
||||
if( !ctx.p && haveOpenCL() )
|
||||
if(!ctx.p && haveOpenCL())
|
||||
{
|
||||
// do not create new Context2 right away.
|
||||
// First, try to retrieve existing context of the same type.
|
||||
// In its turn, Platform::getContext() may call Context2::create()
|
||||
// if there is no such context.
|
||||
ctx.create(Device::TYPE_ACCELERATOR);
|
||||
if(!ctx.p)
|
||||
ctx.create(Device::TYPE_DGPU);
|
||||
if(!ctx.p)
|
||||
ctx.create(Device::TYPE_IGPU);
|
||||
if(!ctx.p)
|
||||
ctx.create(Device::TYPE_CPU);
|
||||
if (initialize)
|
||||
{
|
||||
// do not create new Context2 right away.
|
||||
// First, try to retrieve existing context of the same type.
|
||||
// In its turn, Platform::getContext() may call Context2::create()
|
||||
// if there is no such context.
|
||||
ctx.create(Device::TYPE_ACCELERATOR);
|
||||
if(!ctx.p)
|
||||
ctx.create(Device::TYPE_DGPU);
|
||||
if(!ctx.p)
|
||||
ctx.create(Device::TYPE_IGPU);
|
||||
if(!ctx.p)
|
||||
ctx.create(Device::TYPE_CPU);
|
||||
}
|
||||
else
|
||||
{
|
||||
ctx.p = new Impl();
|
||||
}
|
||||
}
|
||||
|
||||
return ctx;
|
||||
@@ -2034,6 +2031,30 @@ Program Context2::getProg(const ProgramSource2& prog,
|
||||
return p ? p->getProg(prog, buildopts, errmsg) : Program();
|
||||
}
|
||||
|
||||
void initializeContextFromHandle(Context2& ctx, void* platform, void* _context, void* _device)
|
||||
{
|
||||
cl_context context = (cl_context)_context;
|
||||
cl_device_id device = (cl_device_id)_device;
|
||||
|
||||
// cleanup old context
|
||||
Context2::Impl* impl = ctx._getImpl();
|
||||
if (impl->handle)
|
||||
{
|
||||
cl_int status = clReleaseContext(impl->handle);
|
||||
(void)status;
|
||||
}
|
||||
impl->devices.clear();
|
||||
|
||||
impl->handle = context;
|
||||
impl->devices.resize(1);
|
||||
impl->devices[0].set(device);
|
||||
|
||||
Platform& p = Platform::getDefault();
|
||||
Platform::Impl* pImpl = p._getImpl();
|
||||
pImpl->handle = (cl_platform_id)platform;
|
||||
}
|
||||
|
||||
|
||||
struct Queue::Impl
|
||||
{
|
||||
Impl(const Context2& c, const Device& d)
|
||||
|
@@ -43,6 +43,9 @@
|
||||
#ifndef __OPENCV_PRECOMP_H__
|
||||
#define __OPENCV_PRECOMP_H__
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
#include "cvconfig.h"
|
||||
|
||||
#include "opencv2/core/utility.hpp"
|
||||
#include "opencv2/core/core_c.h"
|
||||
#include "opencv2/core/cuda.hpp"
|
||||
|
Reference in New Issue
Block a user