mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 14:36:36 +08:00
Merge pull request #20921 from sivanov-work:atl_patch
G-API: FIX OpenVINO build - Add CComPtr RAII replacement into G-API sample * Add CComPtr RAII replacement into G-API sample * Remove completely `atlbase.h'
This commit is contained in:
parent
7febec49b2
commit
d376fe9e17
@ -25,7 +25,6 @@
|
|||||||
#define D3D11_NO_HELPERS
|
#define D3D11_NO_HELPERS
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#include <cldnn/cldnn_config.hpp>
|
#include <cldnn/cldnn_config.hpp>
|
||||||
#include <atlbase.h>
|
|
||||||
#include <d3d11.h>
|
#include <d3d11.h>
|
||||||
#pragma comment(lib, "dxgi")
|
#pragma comment(lib, "dxgi")
|
||||||
#undef NOMINMAX
|
#undef NOMINMAX
|
||||||
@ -64,9 +63,29 @@ std::string get_weights_path(const std::string &model_path) {
|
|||||||
#ifdef HAVE_DIRECTX
|
#ifdef HAVE_DIRECTX
|
||||||
#ifdef HAVE_D3D11
|
#ifdef HAVE_D3D11
|
||||||
|
|
||||||
using AccelParamsType = std::tuple<CComPtr<ID3D11Device>, CComPtr<ID3D11DeviceContext>>;
|
// Since ATL headers might not be available on specific MSVS Build Tools
|
||||||
|
// we use simple `CComPtr` implementation like as `ComPtrGuard`
|
||||||
|
// which is not supposed to be the full functional replacement of `CComPtr`
|
||||||
|
// and it uses as RAII to make sure utilization is correct
|
||||||
|
template <typename COMNonManageableType>
|
||||||
|
void release(COMNonManageableType *ptr) {
|
||||||
|
if (ptr) {
|
||||||
|
ptr->Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AccelParamsType create_device_with_ctx(CComPtr<IDXGIAdapter> adapter) {
|
template <typename COMNonManageableType>
|
||||||
|
using ComPtrGuard = std::unique_ptr<COMNonManageableType, decltype(&release<COMNonManageableType>)>;
|
||||||
|
|
||||||
|
template <typename COMNonManageableType>
|
||||||
|
ComPtrGuard<COMNonManageableType> createCOMPtrGuard(COMNonManageableType *ptr = nullptr) {
|
||||||
|
return ComPtrGuard<COMNonManageableType> {ptr, &release<COMNonManageableType>};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
using AccelParamsType = std::tuple<ComPtrGuard<ID3D11Device>, ComPtrGuard<ID3D11DeviceContext>>;
|
||||||
|
|
||||||
|
AccelParamsType create_device_with_ctx(IDXGIAdapter* adapter) {
|
||||||
UINT flags = 0;
|
UINT flags = 0;
|
||||||
D3D_FEATURE_LEVEL feature_levels[] = { D3D_FEATURE_LEVEL_11_1,
|
D3D_FEATURE_LEVEL feature_levels[] = { D3D_FEATURE_LEVEL_11_1,
|
||||||
D3D_FEATURE_LEVEL_11_0,
|
D3D_FEATURE_LEVEL_11_0,
|
||||||
@ -85,7 +104,8 @@ AccelParamsType create_device_with_ctx(CComPtr<IDXGIAdapter> adapter) {
|
|||||||
std::to_string(HRESULT_CODE(err)));
|
std::to_string(HRESULT_CODE(err)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_tuple(ret_device_ptr, ret_ctx_ptr);
|
return std::make_tuple(createCOMPtrGuard(ret_device_ptr),
|
||||||
|
createCOMPtrGuard(ret_ctx_ptr));
|
||||||
}
|
}
|
||||||
#endif // HAVE_D3D11
|
#endif // HAVE_D3D11
|
||||||
#endif // HAVE_DIRECTX
|
#endif // HAVE_DIRECTX
|
||||||
@ -270,12 +290,11 @@ int main(int argc, char *argv[]) {
|
|||||||
#ifdef HAVE_INF_ENGINE
|
#ifdef HAVE_INF_ENGINE
|
||||||
#ifdef HAVE_DIRECTX
|
#ifdef HAVE_DIRECTX
|
||||||
#ifdef HAVE_D3D11
|
#ifdef HAVE_D3D11
|
||||||
CComPtr<ID3D11Device> dx11_dev;
|
auto dx11_dev = createCOMPtrGuard<ID3D11Device>();
|
||||||
CComPtr<ID3D11DeviceContext> dx11_ctx;
|
auto dx11_ctx = createCOMPtrGuard<ID3D11DeviceContext>();
|
||||||
|
|
||||||
if (device_id.find("GPU") != std::string::npos) {
|
if (device_id.find("GPU") != std::string::npos) {
|
||||||
CComPtr<IDXGIFactory> adapter_factory;
|
auto adapter_factory = createCOMPtrGuard<IDXGIFactory>();
|
||||||
CComPtr<IDXGIAdapter> intel_adapters;
|
|
||||||
{
|
{
|
||||||
IDXGIFactory* out_factory = nullptr;
|
IDXGIFactory* out_factory = nullptr;
|
||||||
HRESULT err = CreateDXGIFactory(__uuidof(IDXGIFactory),
|
HRESULT err = CreateDXGIFactory(__uuidof(IDXGIFactory),
|
||||||
@ -284,10 +303,10 @@ int main(int argc, char *argv[]) {
|
|||||||
std::cerr << "Cannot create CreateDXGIFactory, error: " << HRESULT_CODE(err) << std::endl;
|
std::cerr << "Cannot create CreateDXGIFactory, error: " << HRESULT_CODE(err) << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
adapter_factory.Attach(out_factory);
|
adapter_factory = createCOMPtrGuard(out_factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
CComPtr<IDXGIAdapter> intel_adapter;
|
auto intel_adapter = createCOMPtrGuard<IDXGIAdapter>();
|
||||||
UINT adapter_index = 0;
|
UINT adapter_index = 0;
|
||||||
const unsigned int refIntelVendorID = 0x8086;
|
const unsigned int refIntelVendorID = 0x8086;
|
||||||
IDXGIAdapter* out_adapter = nullptr;
|
IDXGIAdapter* out_adapter = nullptr;
|
||||||
@ -296,7 +315,7 @@ int main(int argc, char *argv[]) {
|
|||||||
DXGI_ADAPTER_DESC desc{};
|
DXGI_ADAPTER_DESC desc{};
|
||||||
out_adapter->GetDesc(&desc);
|
out_adapter->GetDesc(&desc);
|
||||||
if (desc.VendorId == refIntelVendorID) {
|
if (desc.VendorId == refIntelVendorID) {
|
||||||
intel_adapter.Attach(out_adapter);
|
intel_adapter = createCOMPtrGuard(out_adapter);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++adapter_index;
|
++adapter_index;
|
||||||
@ -307,9 +326,9 @@ int main(int argc, char *argv[]) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tie(dx11_dev, dx11_ctx) = create_device_with_ctx(intel_adapter);
|
std::tie(dx11_dev, dx11_ctx) = create_device_with_ctx(intel_adapter.get());
|
||||||
accel_device_ptr = reinterpret_cast<void*>(dx11_dev.p);
|
accel_device_ptr = reinterpret_cast<void*>(dx11_dev.get());
|
||||||
accel_ctx_ptr = reinterpret_cast<void*>(dx11_ctx.p);
|
accel_ctx_ptr = reinterpret_cast<void*>(dx11_ctx.get());
|
||||||
|
|
||||||
// put accel type description for VPL source
|
// put accel type description for VPL source
|
||||||
source_cfgs.push_back(cfg::create_from_string(
|
source_cfgs.push_back(cfg::create_from_string(
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <opencv2/gapi/util/variant.hpp>
|
#include <opencv2/gapi/util/variant.hpp>
|
||||||
|
|
||||||
#include "streaming/onevpl/cfg_param_device_selector.hpp"
|
#include "streaming/onevpl/cfg_param_device_selector.hpp"
|
||||||
|
#include "streaming/onevpl/utils.hpp"
|
||||||
#include "logger.hpp"
|
#include "logger.hpp"
|
||||||
|
|
||||||
#ifdef HAVE_DIRECTX
|
#ifdef HAVE_DIRECTX
|
||||||
@ -19,7 +20,6 @@
|
|||||||
// get rid of generate macro max/min/etc from DX side
|
// get rid of generate macro max/min/etc from DX side
|
||||||
#define D3D11_NO_HELPERS
|
#define D3D11_NO_HELPERS
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#include <atlbase.h>
|
|
||||||
#include <d3d11.h>
|
#include <d3d11.h>
|
||||||
#include <d3d11_4.h>
|
#include <d3d11_4.h>
|
||||||
#pragma comment(lib, "dxgi")
|
#pragma comment(lib, "dxgi")
|
||||||
@ -113,8 +113,7 @@ CfgParamDeviceSelector::CfgParamDeviceSelector(const CfgParams& cfg_params) :
|
|||||||
};
|
};
|
||||||
D3D_FEATURE_LEVEL featureLevel;
|
D3D_FEATURE_LEVEL featureLevel;
|
||||||
|
|
||||||
CComPtr<IDXGIFactory> adapter_factory;
|
auto adapter_factory = createCOMPtrGuard<IDXGIFactory>();
|
||||||
CComPtr<IDXGIAdapter> intel_adapters;
|
|
||||||
{
|
{
|
||||||
IDXGIFactory* out_factory = nullptr;
|
IDXGIFactory* out_factory = nullptr;
|
||||||
HRESULT err = CreateDXGIFactory(__uuidof(IDXGIFactory),
|
HRESULT err = CreateDXGIFactory(__uuidof(IDXGIFactory),
|
||||||
@ -122,10 +121,10 @@ CfgParamDeviceSelector::CfgParamDeviceSelector(const CfgParams& cfg_params) :
|
|||||||
if (FAILED(err)) {
|
if (FAILED(err)) {
|
||||||
throw std::runtime_error("Cannot create CreateDXGIFactory, error: " + std::to_string(HRESULT_CODE(err)));
|
throw std::runtime_error("Cannot create CreateDXGIFactory, error: " + std::to_string(HRESULT_CODE(err)));
|
||||||
}
|
}
|
||||||
adapter_factory.Attach(out_factory);
|
adapter_factory = createCOMPtrGuard(out_factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
CComPtr<IDXGIAdapter> intel_adapter;
|
auto intel_adapter = createCOMPtrGuard<IDXGIAdapter>();
|
||||||
UINT adapter_index = 0;
|
UINT adapter_index = 0;
|
||||||
const unsigned int refIntelVendorID = 0x8086;
|
const unsigned int refIntelVendorID = 0x8086;
|
||||||
IDXGIAdapter* out_adapter = nullptr;
|
IDXGIAdapter* out_adapter = nullptr;
|
||||||
@ -134,7 +133,7 @@ CfgParamDeviceSelector::CfgParamDeviceSelector(const CfgParams& cfg_params) :
|
|||||||
DXGI_ADAPTER_DESC desc{};
|
DXGI_ADAPTER_DESC desc{};
|
||||||
out_adapter->GetDesc(&desc);
|
out_adapter->GetDesc(&desc);
|
||||||
if (desc.VendorId == refIntelVendorID) {
|
if (desc.VendorId == refIntelVendorID) {
|
||||||
intel_adapter.Attach(out_adapter);
|
intel_adapter = createCOMPtrGuard(out_adapter);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++adapter_index;
|
++adapter_index;
|
||||||
@ -145,7 +144,7 @@ CfgParamDeviceSelector::CfgParamDeviceSelector(const CfgParams& cfg_params) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the Direct3D 11 API device object and a corresponding context.
|
// Create the Direct3D 11 API device object and a corresponding context.
|
||||||
HRESULT err = D3D11CreateDevice(intel_adapter,
|
HRESULT err = D3D11CreateDevice(intel_adapter.get(),
|
||||||
D3D_DRIVER_TYPE_UNKNOWN,
|
D3D_DRIVER_TYPE_UNKNOWN,
|
||||||
nullptr, creationFlags,
|
nullptr, creationFlags,
|
||||||
featureLevels, ARRAYSIZE(featureLevels),
|
featureLevels, ARRAYSIZE(featureLevels),
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <vpl/mfxvideo.h>
|
#include <vpl/mfxvideo.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <opencv2/gapi/streaming/onevpl/cfg_params.hpp>
|
#include <opencv2/gapi/streaming/onevpl/cfg_params.hpp>
|
||||||
@ -26,6 +27,26 @@ namespace gapi {
|
|||||||
namespace wip {
|
namespace wip {
|
||||||
namespace onevpl {
|
namespace onevpl {
|
||||||
|
|
||||||
|
// Since ATL headers might not be available on specific MSVS Build Tools
|
||||||
|
// we use simple `CComPtr` implementation like as `ComPtrGuard`
|
||||||
|
// which is not supposed to be the full functional replacement of `CComPtr`
|
||||||
|
// and it uses as RAII to make sure utilization is correct
|
||||||
|
template <typename COMNonManageableType>
|
||||||
|
void release(COMNonManageableType *ptr) {
|
||||||
|
if (ptr) {
|
||||||
|
ptr->Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename COMNonManageableType>
|
||||||
|
using ComPtrGuard = std::unique_ptr<COMNonManageableType, decltype(&release<COMNonManageableType>)>;
|
||||||
|
|
||||||
|
template <typename COMNonManageableType>
|
||||||
|
ComPtrGuard<COMNonManageableType> createCOMPtrGuard(COMNonManageableType *ptr = nullptr) {
|
||||||
|
return ComPtrGuard<COMNonManageableType> {ptr, &release<COMNonManageableType>};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const char* mfx_impl_to_cstr(const mfxIMPL impl);
|
const char* mfx_impl_to_cstr(const mfxIMPL impl);
|
||||||
|
|
||||||
mfxIMPL cstr_to_mfx_impl(const char* cstr);
|
mfxIMPL cstr_to_mfx_impl(const char* cstr);
|
||||||
|
Loading…
Reference in New Issue
Block a user