/* * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "opencl/source/sharings/d3d/d3d_sharing.h" #include "shared/source/gmm_helper/gmm.h" #include "opencl/source/context/context.h" #include "opencl/source/mem_obj/image.h" using namespace NEO; template D3DSharing::D3DSharing(Context *context, D3DResource *resource, D3DResource *resourceStaging, unsigned int subresource, bool sharedResource) : context(context), resource(resource), resourceStaging(resourceStaging), sharedResource(sharedResource), subresource(subresource) { sharingFunctions = context->getSharing>(); if (sharingFunctions) { sharingFunctions->addRef(resource); sharingFunctions->createQuery(&this->d3dQuery); sharingFunctions->track(resource, subresource); } }; template D3DSharing::~D3DSharing() { if (sharingFunctions) { sharingFunctions->untrack(resource, subresource); if (!sharedResource) { sharingFunctions->release(resourceStaging); } sharingFunctions->release(resource); sharingFunctions->release(d3dQuery); } }; template void D3DSharing::synchronizeObject(UpdateData &updateData) { std::unique_lock lock(this->mtx); sharingFunctions->getDeviceContext(d3dQuery); if (!sharedResource) { sharingFunctions->copySubresourceRegion(resourceStaging, 0, resource, subresource); sharingFunctions->flushAndWait(d3dQuery); } else if (!context->getInteropUserSyncEnabled()) { sharingFunctions->flushAndWait(d3dQuery); } sharingFunctions->releaseDeviceContext(d3dQuery); updateData.synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL; } template void D3DSharing::releaseResource(MemObj *memObject, uint32_t rootDeviceIndex) { if (!sharedResource) { std::unique_lock lock(this->mtx); sharingFunctions->getDeviceContext(d3dQuery); sharingFunctions->copySubresourceRegion(resource, subresource, resourceStaging, 0); if (!context->getInteropUserSyncEnabled()) { sharingFunctions->flushAndWait(d3dQuery); } sharingFunctions->releaseDeviceContext(d3dQuery); } } template void D3DSharing::updateImgInfoAndDesc(Gmm *gmm, ImageInfo &imgInfo, ImagePlane imagePlane, cl_uint arrayIndex) { gmm->updateImgInfoAndDesc(imgInfo, arrayIndex, imagePlane); } template const ClSurfaceFormatInfo *D3DSharing::findSurfaceFormatInfo(int gmmFormat, cl_mem_flags flags, bool supportsOcl20Features, bool packedSupported) { ArrayRef formats = SurfaceFormats::surfaceFormats(flags, supportsOcl20Features); for (auto &format : formats) { if (gmmFormat == format.surfaceFormat.gmmSurfaceFormat) { return &format; } } if (packedSupported) { formats = SurfaceFormats::packed(); for (auto &format : formats) { if (gmmFormat == format.surfaceFormat.gmmSurfaceFormat) { return &format; } } } return nullptr; } template bool D3DSharing::isFormatWithPlane1(DXGI_FORMAT format) { switch (format) { case DXGI_FORMAT_NV12: case DXGI_FORMAT_P010: case DXGI_FORMAT_P016: case DXGI_FORMAT_420_OPAQUE: case DXGI_FORMAT_NV11: case DXGI_FORMAT_P208: return true; default: return false; } } template class NEO::D3DSharing; template class NEO::D3DSharing; template class NEO::D3DSharing;