Debian Codegraph @

opencl/source/sharings/d3d/enable_d3d.cpp

raw
1 /*
2 * Copyright (C) 2018-2023 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #ifdef _WIN32
9
10 #include "opencl/source/sharings/d3d/enable_d3d.h"
11
12 #include "shared/source/os_interface/windows/driver_info_windows.h"
13
14 #include "opencl/source/api/api.h"
15 #include "opencl/source/context/context.h"
16 #include "opencl/source/context/context.inl"
17 #include "opencl/source/os_interface/windows/d3d_sharing_functions.h"
18 #include "opencl/source/sharings/d3d/cl_d3d_api.h"
19 #include "opencl/source/sharings/sharing_factory.h"
20 #include "opencl/source/sharings/sharing_factory.inl"
21
22 #include <memory>
23
24 namespace NEO {
25
26 template <>
27 bool D3DSharingContextBuilder<D3DTypesHelper::D3D9>::processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue) {
28 if (contextData.get() == nullptr) {
29 contextData = std::make_unique<D3DCreateContextProperties<D3DTypesHelper::D3D9>>();
30 }
31
32 switch (propertyType) {
33 case CL_CONTEXT_ADAPTER_D3D9_KHR:
34 case CL_CONTEXT_ADAPTER_D3D9EX_KHR:
35 case CL_CONTEXT_ADAPTER_DXVA_KHR:
36 case CL_CONTEXT_D3D9_DEVICE_INTEL:
37 case CL_CONTEXT_D3D9EX_DEVICE_INTEL:
38 case CL_CONTEXT_DXVA_DEVICE_INTEL:
39 contextData->pDevice = (D3DTypesHelper::D3D9::D3DDevice *)propertyValue;
40 contextData->argumentsDefined = true;
41 return true;
42 }
43 return false;
44 }
45
46 template <>
47 bool D3DSharingContextBuilder<D3DTypesHelper::D3D10>::processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue) {
48 if (contextData.get() == nullptr) {
49 contextData = std::make_unique<D3DCreateContextProperties<D3DTypesHelper::D3D10>>();
50 }
51
52 switch (propertyType) {
53 case CL_CONTEXT_D3D10_DEVICE_KHR:
54 contextData->pDevice = (D3DTypesHelper::D3D10::D3DDevice *)propertyValue;
55 contextData->argumentsDefined = true;
56 return true;
57 }
58 return false;
59 }
60
61 template <>
62 bool D3DSharingContextBuilder<D3DTypesHelper::D3D11>::processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue) {
63 if (contextData.get() == nullptr) {
64 contextData = std::make_unique<D3DCreateContextProperties<D3DTypesHelper::D3D11>>();
65 }
66
67 switch (propertyType) {
68 case CL_CONTEXT_D3D11_DEVICE_KHR:
69 contextData->pDevice = (D3DTypesHelper::D3D11::D3DDevice *)propertyValue;
70 contextData->argumentsDefined = true;
71 return true;
72 }
73 return false;
74 }
75
76 template <>
77 void Context::registerSharing(D3DSharingFunctions<D3DTypesHelper::D3D10> *sharing) {
78 this->sharingFunctions[D3DSharingFunctions<D3DTypesHelper::D3D10>::sharingId].reset(sharing);
79 this->preferD3dSharedResources = 1u;
80 }
81
82 template <>
83 void Context::registerSharing(D3DSharingFunctions<D3DTypesHelper::D3D11> *sharing) {
84 this->sharingFunctions[D3DSharingFunctions<D3DTypesHelper::D3D11>::sharingId].reset(sharing);
85 this->preferD3dSharedResources = 1u;
86 }
87
88 template <typename D3D>
89 bool D3DSharingContextBuilder<D3D>::finalizeProperties(Context &context, int32_t &errcodeRet) {
90 if (contextData.get() == nullptr)
91 return true;
92
93 if (contextData->argumentsDefined) {
94 context.registerSharing(new D3DSharingFunctions<D3D>(contextData->pDevice));
95 }
96
97 return true;
98 }
99
100 template <typename D3D>
101 std::unique_ptr<SharingContextBuilder> D3DSharingBuilderFactory<D3D>::createContextBuilder() {
102 return std::make_unique<D3DSharingContextBuilder<D3D>>();
103 };
104
105 template <>
106 std::string D3DSharingBuilderFactory<D3DTypesHelper::D3D9>::getExtensions(DriverInfo *driverInfo) {
107 return extensionEnabled ? "cl_intel_dx9_media_sharing cl_khr_dx9_media_sharing " : "";
108 }
109
110 template <>
111 std::string D3DSharingBuilderFactory<D3DTypesHelper::D3D10>::getExtensions(DriverInfo *driverInfo) {
112 return extensionEnabled ? "cl_khr_d3d10_sharing " : "";
113 }
114
115 template <>
116 std::string D3DSharingBuilderFactory<D3DTypesHelper::D3D11>::getExtensions(DriverInfo *driverInfo) {
117 return extensionEnabled ? "cl_khr_d3d11_sharing cl_intel_d3d11_nv12_media_sharing " : "";
118 }
119
120 template <>
121 void D3DSharingBuilderFactory<D3DTypesHelper::D3D9>::fillGlobalDispatchTable() {
122 icdGlobalDispatchTable.clGetDeviceIDsFromDX9MediaAdapterKHR = clGetDeviceIDsFromDX9MediaAdapterKHR;
123 icdGlobalDispatchTable.clCreateFromDX9MediaSurfaceKHR = clCreateFromDX9MediaSurfaceKHR;
124 icdGlobalDispatchTable.clEnqueueReleaseDX9MediaSurfacesKHR = clEnqueueReleaseDX9MediaSurfacesKHR;
125 icdGlobalDispatchTable.clEnqueueAcquireDX9MediaSurfacesKHR = clEnqueueAcquireDX9MediaSurfacesKHR;
126
127 crtGlobalDispatchTable.clGetDeviceIDsFromDX9INTEL = clGetDeviceIDsFromDX9INTEL;
128 crtGlobalDispatchTable.clCreateFromDX9MediaSurfaceINTEL = clCreateFromDX9MediaSurfaceINTEL;
129 crtGlobalDispatchTable.clEnqueueAcquireDX9ObjectsINTEL = clEnqueueAcquireDX9ObjectsINTEL;
130 crtGlobalDispatchTable.clEnqueueReleaseDX9ObjectsINTEL = clEnqueueReleaseDX9ObjectsINTEL;
131 }
132
133 template <>
134 void D3DSharingBuilderFactory<D3DTypesHelper::D3D10>::fillGlobalDispatchTable() {
135 icdGlobalDispatchTable.clCreateFromD3D10BufferKHR = clCreateFromD3D10BufferKHR;
136 icdGlobalDispatchTable.clCreateFromD3D10Texture2DKHR = clCreateFromD3D10Texture2DKHR;
137 icdGlobalDispatchTable.clCreateFromD3D10Texture3DKHR = clCreateFromD3D10Texture3DKHR;
138 icdGlobalDispatchTable.clEnqueueAcquireD3D10ObjectsKHR = clEnqueueAcquireD3D10ObjectsKHR;
139 icdGlobalDispatchTable.clEnqueueReleaseD3D10ObjectsKHR = clEnqueueReleaseD3D10ObjectsKHR;
140 icdGlobalDispatchTable.clGetDeviceIDsFromD3D10KHR = clGetDeviceIDsFromD3D10KHR;
141 }
142
143 template <>
144 void D3DSharingBuilderFactory<D3DTypesHelper::D3D11>::fillGlobalDispatchTable() {
145 icdGlobalDispatchTable.clCreateFromD3D11BufferKHR = clCreateFromD3D11BufferKHR;
146 icdGlobalDispatchTable.clCreateFromD3D11Texture2DKHR = clCreateFromD3D11Texture2DKHR;
147 icdGlobalDispatchTable.clCreateFromD3D11Texture3DKHR = clCreateFromD3D11Texture3DKHR;
148 icdGlobalDispatchTable.clEnqueueAcquireD3D11ObjectsKHR = clEnqueueAcquireD3D11ObjectsKHR;
149 icdGlobalDispatchTable.clEnqueueReleaseD3D11ObjectsKHR = clEnqueueReleaseD3D11ObjectsKHR;
150 icdGlobalDispatchTable.clGetDeviceIDsFromD3D11KHR = clGetDeviceIDsFromD3D11KHR;
151 }
152
153 template <>
154 void *D3DSharingBuilderFactory<D3DTypesHelper::D3D9>::getExtensionFunctionAddress(const std::string &functionName) {
155 if (debugManager.flags.EnableFormatQuery.get() &&
156 functionName == "clGetSupportedDX9MediaSurfaceFormatsINTEL") {
157 return ((void *)(clGetSupportedDX9MediaSurfaceFormatsINTEL));
158 }
159 return nullptr;
160 }
161
162 template <>
163 void *D3DSharingBuilderFactory<D3DTypesHelper::D3D10>::getExtensionFunctionAddress(const std::string &functionName) {
164 if (debugManager.flags.EnableFormatQuery.get() &&
165 functionName == "clGetSupportedD3D10TextureFormatsINTEL") {
166 return ((void *)(clGetSupportedD3D10TextureFormatsINTEL));
167 }
168 return nullptr;
169 }
170
171 template <>
172 void *D3DSharingBuilderFactory<D3DTypesHelper::D3D11>::getExtensionFunctionAddress(const std::string &functionName) {
173 if (debugManager.flags.EnableFormatQuery.get() &&
174 functionName == "clGetSupportedD3D11TextureFormatsINTEL") {
175 return ((void *)(clGetSupportedD3D11TextureFormatsINTEL));
176 }
177 return nullptr;
178 }
179
180 template <>
181 void D3DSharingBuilderFactory<D3DTypesHelper::D3D9>::setExtensionEnabled(DriverInfo *driverInfo) {
182 auto driverInfoWin = driverInfo->as<DriverInfoWindows>();
183 extensionEnabled = driverInfo->getMediaSharingSupport() && driverInfoWin->containsSetting(is64bit ? "UserModeDriverName" : "UserModeDriverNameWOW");
184 }
185
186 template <>
187 void D3DSharingBuilderFactory<D3DTypesHelper::D3D10>::setExtensionEnabled(DriverInfo *driverInfo) {
188 extensionEnabled = driverInfo->getMediaSharingSupport();
189 }
190
191 template <>
192 void D3DSharingBuilderFactory<D3DTypesHelper::D3D11>::setExtensionEnabled(DriverInfo *driverInfo) {
193 extensionEnabled = driverInfo->getMediaSharingSupport();
194 }
195
196 static SharingFactory::RegisterSharing<D3DSharingBuilderFactory<D3DTypesHelper::D3D9>, D3DSharingFunctions<D3DTypesHelper::D3D9>> registerD3D9Sharing;
197 static SharingFactory::RegisterSharing<D3DSharingBuilderFactory<D3DTypesHelper::D3D10>, D3DSharingFunctions<D3DTypesHelper::D3D10>> registerD3D10Sharing;
198 static SharingFactory::RegisterSharing<D3DSharingBuilderFactory<D3DTypesHelper::D3D11>, D3DSharingFunctions<D3DTypesHelper::D3D11>> registerD3D11Sharing;
199 } // namespace NEO
200 #endif