Debian Codegraph @

opencl/source/sharings/d3d/d3d_sharing.cpp

raw
1 /*
2 * Copyright (C) 2018-2023 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #include "opencl/source/sharings/d3d/d3d_sharing.h"
9
10 #include "shared/source/gmm_helper/gmm.h"
11
12 #include "opencl/source/context/context.h"
13 #include "opencl/source/mem_obj/image.h"
14
15 using namespace NEO;
16
17 template <typename D3D>
18 D3DSharing<D3D>::D3DSharing(Context *context, D3DResource *resource, D3DResource *resourceStaging, unsigned int subresource, bool sharedResource)
19 : context(context), resource(resource), resourceStaging(resourceStaging), sharedResource(sharedResource), subresource(subresource) {
20 sharingFunctions = context->getSharing<D3DSharingFunctions<D3D>>();
21 if (sharingFunctions) {
22 sharingFunctions->addRef(resource);
23 sharingFunctions->createQuery(&this->d3dQuery);
24 sharingFunctions->track(resource, subresource);
25 }
26 };
27
28 template <typename D3D>
29 D3DSharing<D3D>::~D3DSharing() {
30 if (sharingFunctions) {
31 sharingFunctions->untrack(resource, subresource);
32 if (!sharedResource) {
33 sharingFunctions->release(resourceStaging);
34 }
35 sharingFunctions->release(resource);
36 sharingFunctions->release(d3dQuery);
37 }
38 };
39
40 template <typename D3D>
41 void D3DSharing<D3D>::synchronizeObject(UpdateData &updateData) {
42 std::unique_lock<std::mutex> lock(this->mtx);
43 sharingFunctions->getDeviceContext(d3dQuery);
44 if (!sharedResource) {
45 sharingFunctions->copySubresourceRegion(resourceStaging, 0, resource, subresource);
46 sharingFunctions->flushAndWait(d3dQuery);
47 } else if (!context->getInteropUserSyncEnabled()) {
48 sharingFunctions->flushAndWait(d3dQuery);
49 }
50 sharingFunctions->releaseDeviceContext(d3dQuery);
51
52 updateData.synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL;
53 }
54
55 template <typename D3D>
56 void D3DSharing<D3D>::releaseResource(MemObj *memObject, uint32_t rootDeviceIndex) {
57 if (!sharedResource) {
58 std::unique_lock<std::mutex> lock(this->mtx);
59 sharingFunctions->getDeviceContext(d3dQuery);
60 sharingFunctions->copySubresourceRegion(resource, subresource, resourceStaging, 0);
61 if (!context->getInteropUserSyncEnabled()) {
62 sharingFunctions->flushAndWait(d3dQuery);
63 }
64 sharingFunctions->releaseDeviceContext(d3dQuery);
65 }
66 }
67
68 template <typename D3D>
69 void D3DSharing<D3D>::updateImgInfoAndDesc(Gmm *gmm, ImageInfo &imgInfo, ImagePlane imagePlane, cl_uint arrayIndex) {
70 gmm->updateImgInfoAndDesc(imgInfo, arrayIndex, imagePlane);
71 }
72
73 template <typename D3D>
74 const ClSurfaceFormatInfo *D3DSharing<D3D>::findSurfaceFormatInfo(int gmmFormat, cl_mem_flags flags, bool supportsOcl20Features, bool packedSupported) {
75 ArrayRef<const ClSurfaceFormatInfo> formats = SurfaceFormats::surfaceFormats(flags, supportsOcl20Features);
76 for (auto &format : formats) {
77 if (gmmFormat == format.surfaceFormat.gmmSurfaceFormat) {
78 return &format;
79 }
80 }
81 if (packedSupported) {
82 formats = SurfaceFormats::packed();
83 for (auto &format : formats) {
84 if (gmmFormat == format.surfaceFormat.gmmSurfaceFormat) {
85 return &format;
86 }
87 }
88 }
89
90 return nullptr;
91 }
92
93 template <typename D3D>
94 bool D3DSharing<D3D>::isFormatWithPlane1(DXGI_FORMAT format) {
95 switch (format) {
96 case DXGI_FORMAT_NV12:
97 case DXGI_FORMAT_P010:
98 case DXGI_FORMAT_P016:
99 case DXGI_FORMAT_420_OPAQUE:
100 case DXGI_FORMAT_NV11:
101 case DXGI_FORMAT_P208:
102 return true;
103 default:
104 return false;
105 }
106 }
107
108 template class NEO::D3DSharing<D3DTypesHelper::D3D9>;
109 template class NEO::D3DSharing<D3DTypesHelper::D3D10>;
110 template class NEO::D3DSharing<D3DTypesHelper::D3D11>;