refactor: remove not needed createGraphicsAllocationFromNTHandle method

Related-To: NEO-11498
Signed-off-by: Jaroslaw Warchulski <jaroslaw.warchulski@intel.com>
This commit is contained in:
Jaroslaw Warchulski
2024-06-18 12:10:24 +00:00
committed by Compute-Runtime-Automation
parent bd46361e26
commit daec249430
40 changed files with 104 additions and 246 deletions

View File

@@ -111,7 +111,7 @@ ze_result_t ContextImp::allocHostMem(const ze_host_mem_alloc_desc_t *hostDesc,
} else {
UNRECOVERABLE_IF(!lookupTable.sharedHandleType.isNTHandle);
*ptr = this->driverHandle->importNTHandle(this->devices.begin()->second,
lookupTable.sharedHandleType.ntHnadle,
lookupTable.sharedHandleType.ntHandle,
NEO::AllocationType::bufferHostMemory);
if (*ptr == nullptr) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
@@ -239,7 +239,7 @@ ze_result_t ContextImp::allocDeviceMem(ze_device_handle_t hDevice,
} else {
UNRECOVERABLE_IF(!lookupTable.sharedHandleType.isNTHandle);
*ptr = this->driverHandle->importNTHandle(hDevice,
lookupTable.sharedHandleType.ntHnadle,
lookupTable.sharedHandleType.ntHandle,
NEO::AllocationType::buffer);
if (*ptr == nullptr) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;

View File

@@ -886,7 +886,11 @@ void *DriverHandleImp::importNTHandle(ze_device_handle_t hDevice, void *handle,
bool isHostIpcAllocation = (allocationType == NEO::AllocationType::bufferHostMemory) ? true : false;
NEO::MemoryManager::OsHandleData osHandleData{handle};
auto alloc = this->getMemoryManager()->createGraphicsAllocationFromNTHandle(osHandleData, neoDevice->getRootDeviceIndex(), NEO::AllocationType::sharedBuffer);
NEO::AllocationProperties properties{neoDevice->getRootDeviceIndex(),
MemoryConstants::pageSize,
allocationType,
neoDevice->getDeviceBitfield()};
auto alloc = this->getMemoryManager()->createGraphicsAllocationFromSharedHandle(osHandleData, properties, false, false, false, nullptr);
if (alloc == nullptr) {
return nullptr;

View File

@@ -63,7 +63,7 @@ struct StructuresLookupTable {
} imageProperties;
struct SharedHandleType {
void *ntHnadle;
void *ntHandle;
int fd;
bool isSupportedHandle;
bool isDMABUFHandle;
@@ -107,7 +107,7 @@ inline ze_result_t prepareL0StructuresLookupTable(StructuresLookupTable &lookupT
(windowsExternalMemoryImportDesc->flags == ZE_EXTERNAL_MEMORY_TYPE_FLAG_D3D12_RESOURCE)) {
lookupTable.sharedHandleType.isSupportedHandle = true;
lookupTable.sharedHandleType.isNTHandle = true;
lookupTable.sharedHandleType.ntHnadle = windowsExternalMemoryImportDesc->handle;
lookupTable.sharedHandleType.ntHandle = windowsExternalMemoryImportDesc->handle;
} else {
lookupTable.sharedHandleType.isSupportedHandle = false;
return ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION;

View File

@@ -113,17 +113,18 @@ ze_result_t ImageCoreFamily<gfxCoreFamily>::initialize(Device *device, const ze_
return ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
if (lookupTable.sharedHandleType.isDMABUFHandle) {
NEO::MemoryManager::OsHandleData osHandleData{static_cast<NEO::osHandle>(lookupTable.sharedHandleType.fd)};
NEO::AllocationProperties properties(device->getRootDeviceIndex(), true, &imgInfo, NEO::AllocationType::sharedImage, device->getNEODevice()->getDeviceBitfield());
NEO::MemoryManager::ExtendedOsHandleData osHandleData{static_cast<NEO::osHandle>(lookupTable.sharedHandleType.fd)};
allocation = device->getNEODevice()->getMemoryManager()->createGraphicsAllocationFromSharedHandle(osHandleData, properties, false, false, true, nullptr);
device->getNEODevice()->getMemoryManager()->closeSharedHandle(allocation);
} else if (lookupTable.sharedHandleType.isNTHandle) {
auto verifyResult = device->getNEODevice()->getMemoryManager()->verifyHandle(NEO::toOsHandle(lookupTable.sharedHandleType.ntHnadle), device->getNEODevice()->getRootDeviceIndex(), true);
auto verifyResult = device->getNEODevice()->getMemoryManager()->verifyHandle(NEO::toOsHandle(lookupTable.sharedHandleType.ntHandle), device->getNEODevice()->getRootDeviceIndex(), true);
if (!verifyResult) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
NEO::MemoryManager::ExtendedOsHandleData osHandleData{lookupTable.sharedHandleType.ntHnadle};
allocation = device->getNEODevice()->getMemoryManager()->createGraphicsAllocationFromNTHandle(osHandleData, device->getNEODevice()->getRootDeviceIndex(), NEO::AllocationType::sharedImage);
NEO::MemoryManager::OsHandleData osHandleData{lookupTable.sharedHandleType.ntHandle};
NEO::AllocationProperties properties(device->getRootDeviceIndex(), true, &imgInfo, NEO::AllocationType::sharedImage, device->getNEODevice()->getDeviceBitfield());
allocation = device->getNEODevice()->getMemoryManager()->createGraphicsAllocationFromSharedHandle(osHandleData, properties, false, false, true, nullptr);
allocation->getDefaultGmm()->queryImageParams(imgInfo);
}
} else {

View File

@@ -379,22 +379,6 @@ NEO::GraphicsAllocation *MemoryManagerOpenIpcMock::createGraphicsAllocationFromM
alloc->setGpuBaseAddress(0xabcd);
return alloc;
}
NEO::GraphicsAllocation *MemoryManagerOpenIpcMock::createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) {
auto ptr = reinterpret_cast<void *>(sharedHandleAddress);
sharedHandleAddress += 0x1000;
auto gmmHelper = getGmmHelper(0);
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr));
auto alloc = new IpcImplicitScalingMockGraphicsAllocation(0u,
NEO::AllocationType::buffer,
ptr,
0x1000,
0u,
MemoryPool::system4KBPages,
MemoryManager::maxOsContextCount,
canonizedGpuAddress);
alloc->setGpuBaseAddress(0xabcd);
return alloc;
};
ze_result_t ContextIpcMock::getIpcMemHandle(const void *ptr, ze_ipc_mem_handle_t *pIpcHandle) {
uint64_t handle = mockFd;
@@ -493,26 +477,6 @@ NEO::GraphicsAllocation *MemoryManagerIpcImplicitScalingMock::createGraphicsAllo
return alloc;
}
NEO::GraphicsAllocation *MemoryManagerIpcImplicitScalingMock::createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) {
if (failOnCreateGraphicsAllocationFromNTHandle) {
return nullptr;
}
auto ptr = reinterpret_cast<void *>(sharedHandleAddress);
sharedHandleAddress += 0x1000;
auto gmmHelper = getGmmHelper(0);
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr));
auto alloc = new IpcImplicitScalingMockGraphicsAllocation(0u,
NEO::AllocationType::buffer,
ptr,
0x1000,
0u,
MemoryPool::system4KBPages,
MemoryManager::maxOsContextCount,
canonizedGpuAddress);
alloc->setGpuBaseAddress(0xabcd);
return alloc;
}
NEO::GraphicsAllocation *MemoryManagerIpcImplicitScalingMock::createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) {
if (failOnCreateGraphicsAllocationFromSharedHandle) {
return nullptr;

View File

@@ -194,7 +194,6 @@ class MemoryManagerIpcMock : public NEO::MemoryManager {
NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; }
void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{};
void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{};
NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; };
AllocationStatus populateOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override { return AllocationStatus::Success; };
void cleanOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override{};
void freeGraphicsMemoryImpl(NEO::GraphicsAllocation *gfxAllocation) override{};
@@ -279,7 +278,6 @@ class MemoryManagerOpenIpcMock : public MemoryManagerIpcMock {
bool reuseSharedAllocation, void *mapPointer) override;
NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles,
AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override;
NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override;
void freeGraphicsMemory(GraphicsAllocation *gfxAllocation) override {
delete gfxAllocation;
@@ -365,7 +363,6 @@ class MemoryManagerIpcImplicitScalingMock : public NEO::MemoryManager {
NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles,
AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override;
NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override;
NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties,
bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override;
@@ -376,7 +373,6 @@ class MemoryManagerIpcImplicitScalingMock : public NEO::MemoryManager {
uint64_t sharedHandleAddress = 0x1234;
bool failOnCreateGraphicsAllocationFromSharedHandle = false;
bool failOnCreateGraphicsAllocationFromNTHandle = true;
};
struct MemoryExportImportImplicitScalingTest : public ::testing::Test {

View File

@@ -1387,7 +1387,6 @@ class ReserveMemoryManagerMock : public NEO::MemoryManager {
NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; }
void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{};
void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{};
NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; };
AllocationStatus populateOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override { return AllocationStatus::Success; };
void cleanOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override{};
void freeGraphicsMemoryImpl(NEO::GraphicsAllocation *gfxAllocation) override{};

View File

@@ -275,10 +275,10 @@ class MemoryManagerNTHandleMock : public NEO::OsAgnosticMemoryManager {
public:
MemoryManagerNTHandleMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::OsAgnosticMemoryManager(executionEnvironment) {}
NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override {
auto graphicsAllocation = createMemoryAllocation(allocType, nullptr, reinterpret_cast<void *>(1), 1,
NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override {
auto graphicsAllocation = createMemoryAllocation(properties.allocationType, nullptr, reinterpret_cast<void *>(1), 1,
4096u, osHandleData.handle, MemoryPool::systemCpuInaccessible,
rootDeviceIndex, false, false, false);
properties.rootDeviceIndex, false, false, false);
graphicsAllocation->setSharedHandle(osHandleData.handle);
graphicsAllocation->set32BitAllocation(false);
GmmRequirements gmmRequirements{};

View File

@@ -70,7 +70,6 @@ class MemoryManagerEventPoolFailMock : public NEO::MemoryManager {
NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; }
void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{};
void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{};
NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; };
AllocationStatus populateOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override { return AllocationStatus::Success; };
void cleanOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override{};
void freeGraphicsMemoryImpl(NEO::GraphicsAllocation *gfxAllocation) override{};

View File

@@ -116,7 +116,7 @@ TEST(L0StructuresLookupTableTests, givenL0StructuresWithNTHandleWhenPrepareLooku
EXPECT_TRUE(l0LookupTable.isSharedHandle);
EXPECT_TRUE(l0LookupTable.sharedHandleType.isSupportedHandle);
EXPECT_TRUE(l0LookupTable.sharedHandleType.isNTHandle);
EXPECT_EQ(l0LookupTable.sharedHandleType.ntHnadle, importNTHandle.handle);
EXPECT_EQ(l0LookupTable.sharedHandleType.ntHandle, importNTHandle.handle);
}
TEST(L0StructuresLookupTableTests, givenL0StructuresWithSupportedExportHandlesWhenPrepareLookupTableThenProperFieldsInLookupTableAreSet) {

View File

@@ -486,10 +486,10 @@ class MemoryManagerNTHandleMock : public NEO::OsAgnosticMemoryManager {
public:
MemoryManagerNTHandleMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::OsAgnosticMemoryManager(executionEnvironment) {}
NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override {
NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override {
auto graphicsAllocation = createMemoryAllocation(AllocationType::internalHostMemory, nullptr, reinterpret_cast<void *>(1), 1,
4096u, osHandleData.handle, MemoryPool::systemCpuInaccessible,
rootDeviceIndex, false, false, false);
properties.rootDeviceIndex, false, false, false);
graphicsAllocation->setSharedHandle(osHandleData.handle);
graphicsAllocation->set32BitAllocation(false);
GmmRequirements gmmRequirements{};

View File

@@ -67,7 +67,6 @@ class MemoryManagerIpcImplicitScalingObtainFdMock : public NEO::DrmMemoryManager
NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; }
void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{};
void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{};
NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; };
AllocationStatus populateOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override { return AllocationStatus::Success; };
void cleanOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override{};
void freeGraphicsMemoryImpl(NEO::GraphicsAllocation *gfxAllocation) override{};
@@ -484,7 +483,6 @@ class MemoryManagerIpcObtainFdMock : public NEO::DrmMemoryManager {
NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; }
void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{};
void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{};
NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; };
AllocationStatus populateOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override { return AllocationStatus::Success; };
void cleanOsHandles(NEO::OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override{};
void freeGraphicsMemoryImpl(NEO::GraphicsAllocation *gfxAllocation) override{};

View File

@@ -240,7 +240,6 @@ TEST_F(MemoryExportImportImplicitScalingTest,
uint32_t numIpcHandles = 0;
result = context->getIpcMemHandles(ptr, &numIpcHandles, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
this->currMemoryManager->failOnCreateGraphicsAllocationFromNTHandle = false;
auto usmManager = context->getDriverHandle()->getSvmAllocsManager();
auto currentAllocationCount = usmManager->allocationsCounter.load();
@@ -330,7 +329,6 @@ TEST_F(MemoryExportImportImplicitScalingTest,
IpcMemoryData &ipcData = *reinterpret_cast<IpcMemoryData *>(ipcHandle.data);
ipcData.type = static_cast<uint8_t>(ZE_MEMORY_TYPE_HOST);
currMemoryManager->failOnCreateGraphicsAllocationFromSharedHandle = true;
currMemoryManager->failOnCreateGraphicsAllocationFromNTHandle = true;
result = context->openIpcMemHandle(device->toHandle(), ipcHandle, flags, &ipcPtr);
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);

View File

@@ -89,7 +89,7 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo
AllocationType::sharedImage,
false, // isMultiStorageAllocation
context->getDeviceBitfieldForAllocation(rootDeviceIndex));
MemoryManager::ExtendedOsHandleData osHandleData{surfaceInfo->shared_handle};
MemoryManager::OsHandleData osHandleData{surfaceInfo->shared_handle};
alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(osHandleData, allocProperties,
false, false, true, nullptr);
updateImgInfoAndDesc(alloc->getDefaultGmm(), imgInfo, imagePlane, 0u);

View File

@@ -73,31 +73,22 @@ Image *D3DTexture<D3D>::create2d(Context *context, D3DTexture2d *d3dTexture, cl_
auto memoryManager = context->getMemoryManager();
auto rootDeviceIndex = context->getDevice(0)->getRootDeviceIndex();
if (textureDesc.MiscFlags & D3DResourceFlags::MISC_SHARED_NTHANDLE) {
sharingFcns->getSharedNTHandle(textureStaging, &sharedHandle);
if (memoryManager->verifyHandle(toOsHandle(sharedHandle), rootDeviceIndex, true)) {
MemoryManager::ExtendedOsHandleData osHandleData{sharedHandle, arrayIndex};
alloc = memoryManager->createGraphicsAllocationFromNTHandle(osHandleData, rootDeviceIndex, AllocationType::sharedImage);
} else {
err.set(CL_INVALID_D3D11_RESOURCE_KHR);
return nullptr;
}
} else {
sharingFcns->getSharedHandle(textureStaging, &sharedHandle);
bool ntHandle = textureDesc.MiscFlags & D3DResourceFlags::MISC_SHARED_NTHANDLE;
ntHandle ? sharingFcns->getSharedNTHandle(textureStaging, &sharedHandle) : sharingFcns->getSharedHandle(textureStaging, &sharedHandle);
AllocationProperties allocProperties(rootDeviceIndex,
false, // allocateMemory
0u, // size
AllocationType::sharedImage,
false, // isMultiStorageAllocation
context->getDeviceBitfieldForAllocation(rootDeviceIndex));
if (memoryManager->verifyHandle(toOsHandle(sharedHandle), rootDeviceIndex, false)) {
MemoryManager::ExtendedOsHandleData osHandleData{sharedHandle, arrayIndex};
if (memoryManager->verifyHandle(toOsHandle(sharedHandle), rootDeviceIndex, ntHandle)) {
MemoryManager::OsHandleData osHandleData{sharedHandle, arrayIndex};
alloc = memoryManager->createGraphicsAllocationFromSharedHandle(osHandleData, allocProperties, false, false, true, nullptr);
} else {
err.set(CL_INVALID_D3D11_RESOURCE_KHR);
return nullptr;
}
}
if (alloc == nullptr) {
err.set(CL_OUT_OF_HOST_MEMORY);
return nullptr;
@@ -168,31 +159,22 @@ Image *D3DTexture<D3D>::create3d(Context *context, D3DTexture3d *d3dTexture, cl_
auto memoryManager = context->getMemoryManager();
auto rootDeviceIndex = context->getDevice(0)->getRootDeviceIndex();
if (textureDesc.MiscFlags & D3DResourceFlags::MISC_SHARED_NTHANDLE) {
sharingFcns->getSharedNTHandle(textureStaging, &sharedHandle);
if (memoryManager->verifyHandle(toOsHandle(sharedHandle), rootDeviceIndex, true)) {
MemoryManager::ExtendedOsHandleData osHandleData{sharedHandle};
alloc = memoryManager->createGraphicsAllocationFromNTHandle(osHandleData, rootDeviceIndex, AllocationType::sharedImage);
} else {
err.set(CL_INVALID_D3D11_RESOURCE_KHR);
return nullptr;
}
} else {
sharingFcns->getSharedHandle(textureStaging, &sharedHandle);
bool ntHandle = textureDesc.MiscFlags & D3DResourceFlags::MISC_SHARED_NTHANDLE;
ntHandle ? sharingFcns->getSharedNTHandle(textureStaging, &sharedHandle) : sharingFcns->getSharedHandle(textureStaging, &sharedHandle);
AllocationProperties allocProperties(rootDeviceIndex,
false, // allocateMemory
0u, // size
AllocationType::sharedImage,
false, // isMultiStorageAllocation
context->getDeviceBitfieldForAllocation(rootDeviceIndex));
if (memoryManager->verifyHandle(toOsHandle(sharedHandle), rootDeviceIndex, false)) {
MemoryManager::ExtendedOsHandleData osHandleData{sharedHandle};
if (memoryManager->verifyHandle(toOsHandle(sharedHandle), rootDeviceIndex, ntHandle)) {
MemoryManager::OsHandleData osHandleData{sharedHandle};
alloc = memoryManager->createGraphicsAllocationFromSharedHandle(osHandleData, allocProperties, false, false, true, nullptr);
} else {
err.set(CL_INVALID_D3D11_RESOURCE_KHR);
return nullptr;
}
}
bool is3DUavOrRtv = false;
if (textureDesc.BindFlags & D3DBindFLags::D3D11_BIND_RENDER_TARGET || textureDesc.BindFlags & D3DBindFLags::D3D11_BIND_UNORDERED_ACCESS) {
is3DUavOrRtv = true;

View File

@@ -145,7 +145,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl
&imgInfo,
AllocationType::sharedImage,
context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex()));
MemoryManager::ExtendedOsHandleData osHandleData{texInfo.globalShareHandle};
MemoryManager::OsHandleData osHandleData{texInfo.globalShareHandle};
auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(osHandleData, allocProperties, false, false, false, nullptr);
if (alloc == nullptr) {

View File

@@ -59,7 +59,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl
AllocationType::sharedImage,
false, // isMultiStorageAllocation
context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex()));
MemoryManager::ExtendedOsHandleData osHandleData{texInfo.globalShareHandle};
MemoryManager::OsHandleData osHandleData{texInfo.globalShareHandle};
auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(osHandleData, allocProperties, false, false, true, nullptr);
if (alloc == nullptr) {

View File

@@ -40,13 +40,10 @@ GraphicsAllocation *UnifiedSharing::createGraphicsAllocation(Context *context, U
GraphicsAllocation *UnifiedSharing::createGraphicsAllocation(Context *context, UnifiedSharingMemoryDescription description, ImageInfo *imgInfo, AllocationType allocationType) {
auto memoryManager = context->getMemoryManager();
switch (description.type) {
case UnifiedSharingHandleType::win32Nt: {
MemoryManager::OsHandleData osHandleData{description.handle};
return memoryManager->createGraphicsAllocationFromNTHandle(osHandleData, context->getDevice(0)->getRootDeviceIndex(), allocationType);
}
case UnifiedSharingHandleType::linuxFd:
case UnifiedSharingHandleType::win32Shared: {
if (description.type != UnifiedSharingHandleType::win32Nt && description.type != UnifiedSharingHandleType::linuxFd && description.type != UnifiedSharingHandleType::win32Shared)
return nullptr;
const AllocationProperties properties{context->getDevice(0)->getRootDeviceIndex(),
false, // allocateMemory
imgInfo,
@@ -55,10 +52,6 @@ GraphicsAllocation *UnifiedSharing::createGraphicsAllocation(Context *context, U
MemoryManager::OsHandleData osHandleData{description.handle};
return memoryManager->createGraphicsAllocationFromSharedHandle(osHandleData, properties, false, false, true, nullptr);
}
default:
return nullptr;
}
}
template <>
UnifiedSharingFunctions *Context::getSharing() {

View File

@@ -59,16 +59,6 @@ class D3DTests : public PlatformFixture, public ::testing::Test {
gmmOwnershipPassed = true;
return alloc;
}
GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override {
if (failAlloc) {
return nullptr;
}
AllocationProperties properties(rootDeviceIndex, true, 0, AllocationType::internalHostMemory, false, false, 0);
auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(osHandleData, properties, false, false, true, nullptr);
alloc->setDefaultGmm(forceGmm);
gmmOwnershipPassed = true;
return alloc;
}
bool verifyValue = true;
bool verifyHandle(osHandle handle, uint32_t rootDeviceIndex, bool) override { return verifyValue; }

View File

@@ -14,13 +14,13 @@ using namespace NEO;
struct ImageWindowsTestsMockMemoryManager : MockMemoryManager {
using MockMemoryManager::MockMemoryManager;
GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override {
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override {
auto graphicsAllocation = createMemoryAllocation(allocType, nullptr, reinterpret_cast<void *>(1), 1,
auto graphicsAllocation = createMemoryAllocation(properties.allocationType, nullptr, reinterpret_cast<void *>(1), 1,
4096u, osHandleData.handle, MemoryPool::systemCpuInaccessible,
rootDeviceIndex, false, false, false);
properties.rootDeviceIndex, false, false, false);
graphicsAllocation->setDefaultGmm(new MockGmm(executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getGmmHelper()));
graphicsAllocation->setDefaultGmm(new MockGmm(executionEnvironment.rootDeviceEnvironments[properties.rootDeviceIndex]->getGmmHelper()));
graphicsAllocation->getDefaultGmm()->gmmResourceInfo->peekGmmResourceInfo()->OverrideSurfaceType(RESOURCE_BUFFER);
return graphicsAllocation;

View File

@@ -60,17 +60,17 @@ struct UnifiedSharingContextFixture : ::testing::Test {
template <bool validMemoryManager>
struct UnifiedSharingMockMemoryManager : MockMemoryManager {
using MockMemoryManager::MockMemoryManager;
GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override {
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override {
if (!validMemoryManager) {
return nullptr;
}
auto graphicsAllocation = createMemoryAllocation(AllocationType::internalHostMemory, nullptr, reinterpret_cast<void *>(1), 1,
4096u, osHandleData.handle, MemoryPool::systemCpuInaccessible,
rootDeviceIndex, false, false, false);
properties.rootDeviceIndex, false, false, false);
graphicsAllocation->setSharedHandle(osHandleData.handle);
graphicsAllocation->set32BitAllocation(false);
graphicsAllocation->setDefaultGmm(new MockGmm(executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getGmmHelper()));
graphicsAllocation->setDefaultGmm(new MockGmm(executionEnvironment.rootDeviceEnvironments[properties.rootDeviceIndex]->getGmmHelper()));
return graphicsAllocation;
}
};

View File

@@ -110,8 +110,8 @@ class MockProductHelper : public ProductHelperHw<IGFX_UNKNOWN> {
};
struct MemoryManagerReturningCompressedAllocations : UnifiedSharingMockMemoryManager<true> {
GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override {
auto allocation = UnifiedSharingMockMemoryManager<true>::createGraphicsAllocationFromNTHandle(osHandleData, rootDeviceIndex, AllocationType::sharedImage);
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override {
auto allocation = UnifiedSharingMockMemoryManager<true>::createGraphicsAllocationFromSharedHandle(osHandleData, properties, false, false, false, nullptr);
auto gmm = allocation->getDefaultGmm();
auto mockGmmResourceInfo = std::make_unique<MockGmmResourceInfo>(gmm->gmmResourceInfo->peekGmmResourceInfo());

View File

@@ -164,19 +164,13 @@ struct UnifiedSharingCreateAllocationTests : UnifiedSharingTestsWithMemoryManage
struct MemoryManagerCheckingAllocationMethod : MockMemoryManager {
using MockMemoryManager::MockMemoryManager;
GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override {
this->createFromNTHandleCalled = true;
this->handle = osHandleData.handle;
return nullptr;
}
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override {
this->createFromSharedHandleCalled = true;
this->handle = osHandleData.handle;
this->properties = std::make_unique<AllocationProperties>(properties);
this->handle = osHandleData.handle;
return nullptr;
}
bool createFromNTHandleCalled = false;
bool createFromSharedHandleCalled = false;
osHandle handle;
std::unique_ptr<AllocationProperties> properties;
@@ -196,15 +190,14 @@ struct UnifiedSharingCreateAllocationTests : UnifiedSharingTestsWithMemoryManage
std::unique_ptr<VariableBackup<MemoryManager *>> memoryManagerBackup;
};
TEST_F(UnifiedSharingCreateAllocationTests, givenWindowsNtHandleWhenCreateGraphicsAllocationIsCalledThenUseNtHandleMethod) {
TEST_F(UnifiedSharingCreateAllocationTests, givenWindowsNtHandleWhenCreateGraphicsAllocationIsCalledThenUseSharedHandleMethod) {
UnifiedSharingMemoryDescription desc{};
desc.handle = reinterpret_cast<void *>(0x1234);
desc.type = UnifiedSharingHandleType::win32Nt;
AllocationType allocationType = AllocationType::sharedImage;
MockSharingHandler::createGraphicsAllocation(this->context.get(), desc, allocationType);
EXPECT_TRUE(memoryManager->createFromNTHandleCalled);
EXPECT_FALSE(memoryManager->createFromSharedHandleCalled);
EXPECT_TRUE(memoryManager->createFromSharedHandleCalled);
EXPECT_EQ(toOsHandle(desc.handle), memoryManager->handle);
}
@@ -215,7 +208,6 @@ TEST_F(UnifiedSharingCreateAllocationTests, givenWindowsSharedHandleWhenCreateGr
AllocationType allocationType = AllocationType::sharedImage;
MockSharingHandler::createGraphicsAllocation(this->context.get(), desc, allocationType);
EXPECT_FALSE(memoryManager->createFromNTHandleCalled);
EXPECT_TRUE(memoryManager->createFromSharedHandleCalled);
EXPECT_EQ(toOsHandle(desc.handle), memoryManager->handle);
const AllocationProperties expectedProperties{0u, false, 0u, allocationType, false, {}};
@@ -229,7 +221,6 @@ TEST_F(UnifiedSharingCreateAllocationTests, givenLinuxSharedHandleWhenCreateGrap
AllocationType allocationType = AllocationType::sharedImage;
MockSharingHandler::createGraphicsAllocation(this->context.get(), desc, allocationType);
EXPECT_FALSE(memoryManager->createFromNTHandleCalled);
EXPECT_TRUE(memoryManager->createFromSharedHandleCalled);
EXPECT_EQ(toOsHandle(desc.handle), memoryManager->handle);
const AllocationProperties expectedProperties{0u, false, 0u, allocationType, false, {}};

View File

@@ -97,18 +97,11 @@ class MemoryManager {
struct OsHandleData {
osHandle handle;
uint32_t arrayIndex;
OsHandleData(uint64_t handle) : handle(static_cast<osHandle>(handle)){};
OsHandleData(void *handle) : handle(toOsHandle(handle)){};
};
struct ExtendedOsHandleData : public OsHandleData {
uint32_t arrayIndex = 0;
ExtendedOsHandleData(uint64_t handle) : OsHandleData(handle){};
ExtendedOsHandleData(void *handle) : OsHandleData(handle){};
ExtendedOsHandleData(osHandle handle, uint32_t arrayIndex) : OsHandleData(handle), arrayIndex(arrayIndex){};
ExtendedOsHandleData(void *handle, uint32_t arrayIndex) : OsHandleData(handle), arrayIndex(arrayIndex){};
OsHandleData(uint64_t handle, uint32_t arrayIndex = 0) : handle(static_cast<osHandle>(handle)), arrayIndex(arrayIndex){};
OsHandleData(void *handle, uint32_t arrayIndex = 0) : handle(toOsHandle(handle)), arrayIndex(arrayIndex){};
OsHandleData(osHandle handle, uint32_t arrayIndex = 0) : handle(handle), arrayIndex(arrayIndex){};
};
MemoryManager(ExecutionEnvironment &executionEnvironment);
@@ -139,7 +132,6 @@ class MemoryManager {
virtual GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) = 0;
virtual void closeSharedHandle(GraphicsAllocation *graphicsAllocation){};
virtual void closeInternalHandle(uint64_t &handle, uint32_t handleId, GraphicsAllocation *graphicsAllocation){};
virtual GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) = 0;
virtual bool mapAuxGpuVA(GraphicsAllocation *graphicsAllocation);

View File

@@ -25,7 +25,6 @@ class OsAgnosticMemoryManager : public MemoryManager {
~OsAgnosticMemoryManager() override;
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override;
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override;
GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }
void addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) override;
void removeAllocationFromHostPtrManager(GraphicsAllocation *gfxAllocation) override;

View File

@@ -44,8 +44,6 @@ class DrmMemoryManager : public MemoryManager {
void closeSharedHandle(GraphicsAllocation *gfxAllocation) override;
void closeInternalHandle(uint64_t &handle, uint32_t handleId, GraphicsAllocation *graphicsAllocation) override;
GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }
uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override;
uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) override;
double getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) override;

View File

@@ -828,7 +828,7 @@ bool Wddm::verifySharedHandle(D3DKMT_HANDLE osHandle) {
return status == STATUS_SUCCESS;
}
bool Wddm::openSharedHandle(const MemoryManager::ExtendedOsHandleData &osHandleData, WddmAllocation *alloc) {
bool Wddm::openSharedHandle(const MemoryManager::OsHandleData &osHandleData, WddmAllocation *alloc) {
D3DKMT_QUERYRESOURCEINFO queryResourceInfo = {};
queryResourceInfo.hDevice = device;
queryResourceInfo.hGlobalShare = osHandleData.handle;
@@ -878,7 +878,7 @@ bool Wddm::verifyNTHandle(HANDLE handle) {
return status == STATUS_SUCCESS;
}
bool Wddm::openNTHandle(const MemoryManager::ExtendedOsHandleData &osHandleData, WddmAllocation *alloc) {
bool Wddm::openNTHandle(const MemoryManager::OsHandleData &osHandleData, WddmAllocation *alloc) {
D3DKMT_QUERYRESOURCEINFOFROMNTHANDLE queryResourceInfoFromNtHandle = {};
queryResourceInfoFromNtHandle.hDevice = device;
queryResourceInfoFromNtHandle.hNtHandle = reinterpret_cast<HANDLE>(static_cast<uintptr_t>(osHandleData.handle));

View File

@@ -79,9 +79,9 @@ class Wddm : public DriverModel {
MOCKABLE_VIRTUAL NTSTATUS createAllocationsAndMapGpuVa(OsHandleStorage &osHandles);
MOCKABLE_VIRTUAL bool destroyAllocations(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle);
MOCKABLE_VIRTUAL bool verifySharedHandle(D3DKMT_HANDLE osHandle);
MOCKABLE_VIRTUAL bool openSharedHandle(const MemoryManager::ExtendedOsHandleData &osHandleData, WddmAllocation *alloc);
MOCKABLE_VIRTUAL bool openSharedHandle(const MemoryManager::OsHandleData &osHandleData, WddmAllocation *alloc);
MOCKABLE_VIRTUAL bool verifyNTHandle(HANDLE handle);
bool openNTHandle(const MemoryManager::ExtendedOsHandleData &osHandleData, WddmAllocation *alloc);
bool openNTHandle(const MemoryManager::OsHandleData &osHandleData, WddmAllocation *alloc);
MOCKABLE_VIRTUAL void *lockResource(const D3DKMT_HANDLE &handle, bool applyMakeResidentPriorToLock, size_t size);
MOCKABLE_VIRTUAL void unlockResource(const D3DKMT_HANDLE &handle);
MOCKABLE_VIRTUAL void kmDafLock(D3DKMT_HANDLE handle);

View File

@@ -599,16 +599,14 @@ bool WddmMemoryManager::isNTHandle(osHandle handle, uint32_t rootDeviceIndex) {
return status;
}
GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(const OsHandleData &osHandleData, bool requireSpecificBitness, bool ntHandle, AllocationType allocationType, uint32_t rootDeviceIndex, void *mapPointer) {
auto allocation = std::make_unique<WddmAllocation>(rootDeviceIndex, allocationType, nullptr, 0, osHandleData.handle, MemoryPool::systemCpuInaccessible, maxOsContextCount, 0llu);
GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) {
auto allocation = std::make_unique<WddmAllocation>(properties.rootDeviceIndex, properties.allocationType, nullptr, 0, osHandleData.handle, MemoryPool::systemCpuInaccessible, maxOsContextCount, 0llu);
bool status = false;
if (allocationType == AllocationType::sharedImage) {
status = ntHandle ? getWddm(rootDeviceIndex).openNTHandle(static_cast<const ExtendedOsHandleData &>(osHandleData), allocation.get()) : getWddm(rootDeviceIndex).openSharedHandle(static_cast<const ExtendedOsHandleData &>(osHandleData), allocation.get());
} else {
MemoryManager::ExtendedOsHandleData extendedOsHandleData{osHandleData.handle};
status = ntHandle ? getWddm(rootDeviceIndex).openNTHandle(extendedOsHandleData, allocation.get()) : getWddm(rootDeviceIndex).openSharedHandle(extendedOsHandleData, allocation.get());
}
bool status;
if (verifyHandle(osHandleData.handle, properties.rootDeviceIndex, false))
status = getWddm(properties.rootDeviceIndex).openSharedHandle(osHandleData, allocation.get());
else
status = getWddm(properties.rootDeviceIndex).openNTHandle(osHandleData, allocation.get());
if (!status) {
return nullptr;
@@ -621,7 +619,7 @@ GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(const OsHandle
if (mapPointer == nullptr) {
if (is32bit) {
void *ptr = nullptr;
if (!getWddm(rootDeviceIndex).reserveValidAddressRange(size, ptr)) {
if (!getWddm(properties.rootDeviceIndex).reserveValidAddressRange(size, ptr)) {
return nullptr;
}
allocation->setReservedAddressRange(ptr, size);
@@ -644,18 +642,6 @@ GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(const OsHandle
return allocation.release();
}
GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) {
return nullptr;
}
GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) {
return createAllocationFromHandle(osHandleData, requireSpecificBitness, false, properties.allocationType, properties.rootDeviceIndex, mapPointer);
}
GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) {
return createAllocationFromHandle(osHandleData, false, true, allocType, rootDeviceIndex, nullptr);
}
void WddmMemoryManager::addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) {
WddmAllocation *wddmMemory = static_cast<WddmAllocation *>(gfxAllocation);
FragmentStorage fragment = {};

View File

@@ -35,9 +35,8 @@ class WddmMemoryManager : public MemoryManager {
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation, bool isImportedAllocation) override;
void handleFenceCompletion(GraphicsAllocation *allocation) override;
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override;
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; }
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override;
GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override;
void addAllocationToHostPtrManager(GraphicsAllocation *memory) override;
void removeAllocationFromHostPtrManager(GraphicsAllocation *memory) override;

View File

@@ -480,7 +480,7 @@ NTSTATUS __stdcall mockD3DKMTOpenResourceFromNtHandle(IN OUT D3DKMT_OPENRESOURCE
}
NTSTATUS __stdcall mockD3DKMTQueryResourceInfo(IN OUT D3DKMT_QUERYRESOURCEINFO *queryResourceInfo) {
if (queryResourceInfo->hDevice != DEVICE_HANDLE || queryResourceInfo->hGlobalShare == INVALID_HANDLE) {
if (queryResourceInfo->hDevice != DEVICE_HANDLE || queryResourceInfo->hGlobalShare == INVALID_HANDLE || queryResourceInfo->hGlobalShare == NT_ALLOCATION_HANDLE) {
return STATUS_INVALID_PARAMETER;
}
queryResourceInfo->TotalPrivateDriverDataSize = totalPrivateSize;

View File

@@ -232,20 +232,6 @@ GraphicsAllocation *MockMemoryManager::createGraphicsAllocationFromSharedHandle(
}
}
GraphicsAllocation *MockMemoryManager::createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) {
if (osHandleData.handle != invalidSharedHandle) {
auto graphicsAllocation = createMemoryAllocation(NEO::AllocationType::sharedBuffer, nullptr, reinterpret_cast<void *>(1), 1,
ipcAllocationSize, osHandleData.handle, MemoryPool::systemCpuInaccessible, rootDeviceIndex,
false, false, false);
graphicsAllocation->setSharedHandle(osHandleData.handle);
this->capturedSharedHandle = osHandleData.handle;
return graphicsAllocation;
} else {
this->capturedSharedHandle = osHandleData.handle;
return nullptr;
}
}
bool MockMemoryManager::copyMemoryToAllocationBanks(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy, DeviceBitfield handleMask) {
copyMemoryToAllocationBanksCalled++;
copyMemoryToAllocationBanksParamsPassed.push_back({graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy, handleMask});

View File

@@ -84,7 +84,6 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptr) override;
GraphicsAllocation *createGraphicsAllocationFromExistingStorage(AllocationProperties &properties, void *ptr, MultiGraphicsAllocation &multiGraphicsAllocation) override;
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override;
GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override;
void *allocateSystemMemory(size_t size, size_t alignment) override;
@@ -329,9 +328,6 @@ class FailMemoryManager : public MockMemoryManager {
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override {
return nullptr;
}
GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override {
return nullptr;
}
void *lockResourceImpl(GraphicsAllocation &gfxAllocation) override { return nullptr; };
void unlockResourceImpl(GraphicsAllocation &gfxAllocation) override{};

View File

@@ -161,7 +161,7 @@ bool WddmMock::destroyAllocation(WddmAllocation *alloc, OsContextWin *osContext)
return success;
}
bool WddmMock::openSharedHandle(const MemoryManager::ExtendedOsHandleData &osHandleData, WddmAllocation *alloc) {
bool WddmMock::openSharedHandle(const MemoryManager::OsHandleData &osHandleData, WddmAllocation *alloc) {
if (failOpenSharedHandle) {
return false;
} else {

View File

@@ -77,7 +77,7 @@ class WddmMock : public Wddm {
NTSTATUS createAllocation(WddmAllocation *wddmAllocation);
bool createAllocation64k(WddmAllocation *wddmAllocation);
bool destroyAllocation(WddmAllocation *alloc, OsContextWin *osContext);
bool openSharedHandle(const MemoryManager::ExtendedOsHandleData &osHandleData, WddmAllocation *alloc) override;
bool openSharedHandle(const MemoryManager::OsHandleData &osHandleData, WddmAllocation *alloc) override;
bool createContext(OsContextWin &osContext) override;
void applyAdditionalContextFlags(CREATECONTEXT_PVTDATA &privateData, OsContextWin &osContext) override;
bool destroyContext(D3DKMT_HANDLE context) override;

View File

@@ -509,7 +509,6 @@ TEST_F(DeviceGetCapsTest, givenFlagEnabled64kbPagesWhenCallConstructorMemoryMana
void removeAllocationFromHostPtrManager(GraphicsAllocation *memory) override{};
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; }
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; };
GraphicsAllocation *createGraphicsAllocationFromNTHandle(const OsHandleData &osHandleData, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; };
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override { return AllocationStatus::Success; };
void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override{};
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override{};

View File

@@ -1358,14 +1358,6 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocat
memoryManager.freeGraphicsMemory(sharedAllocation);
}
TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenCreateAllocationFromNtHandleIsCalledThenReturnNullptr) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
OsAgnosticMemoryManager memoryManager(executionEnvironment);
OsAgnosticMemoryManager::ExtendedOsHandleData osHandleData{(void *)1};
auto graphicsAllocation = memoryManager.createGraphicsAllocationFromNTHandle(osHandleData, 0, AllocationType::sharedImage);
EXPECT_EQ(nullptr, graphicsAllocation);
}
TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenLockUnlockCalledThenReturnCpuPtr) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
OsAgnosticMemoryManager memoryManager(executionEnvironment);

View File

@@ -2304,12 +2304,6 @@ TEST_F(DrmMemoryManagerTest, givenTwoGraphicsAllocationsThatDoesnShareTheSameBuf
memoryManager->freeGraphicsMemory(graphicsAllocation2);
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenCreateAllocationFromNtHandleIsCalledThenReturnNullptr) {
TestedDrmMemoryManager::ExtendedOsHandleData osHandleData{1u};
auto graphicsAllocation = memoryManager->createGraphicsAllocationFromNTHandle(osHandleData, 0, AllocationType::sharedImage);
EXPECT_EQ(nullptr, graphicsAllocation);
}
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledThenReturnPtr) {
mock->ioctlExpected.gemUserptr = 1;
mock->ioctlExpected.gemSetDomain = 1;

View File

@@ -522,7 +522,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandlesWhenCreateGraphicsAllocation
AllocationProperties properties(0, false, 4096u, AllocationType::sharedImage, false, {});
for (uint32_t i = 0; i < 3; i++) {
WddmMemoryManager::ExtendedOsHandleData osHandleData{ALLOCATION_HANDLE, i};
WddmMemoryManager::OsHandleData osHandleData{ALLOCATION_HANDLE, i};
auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(osHandleData, properties, false, false, true, nullptr);
auto wddmAllocation = (WddmAllocation *)graphicsAllocation;
@@ -970,7 +970,7 @@ NTSTATUS APIENTRY queryResourceInfoMock(D3DKMT_QUERYRESOURCEINFO *pData) {
}
TEST_F(Wddm20Tests, givenOpenSharedHandleWhenZeroAllocationsThenReturnNull) {
MockMemoryManager::ExtendedOsHandleData osHandleData{static_cast<uint64_t>(0ull)};
MockMemoryManager::OsHandleData osHandleData{static_cast<uint64_t>(0ull)};
WddmAllocation *alloc = nullptr;
gdi->queryResourceInfo = reinterpret_cast<PFND3DKMT_QUERYRESOURCEINFO>(queryResourceInfoMock);

View File

@@ -972,7 +972,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenSharedHandleWhenCreateGraphicsAllocatio
TEST_F(WddmMemoryManagerSimpleTest, givenAllocationPropertiesWhenCreateAllocationFromHandleIsCalledThenCorrectAllocationTypeIsSet) {
memoryManager.reset(new MockWddmMemoryManager(false, false, executionEnvironment));
MockMemoryManager::ExtendedOsHandleData osHandleData{1u};
MockMemoryManager::OsHandleData osHandleData{1u};
gdi->getQueryResourceInfoArgOut().NumAllocations = 1;
GmmRequirements gmmRequirements{};
gmmRequirements.allowLargePages = true;
@@ -2626,7 +2626,7 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandleIs
memoryManager->freeGraphicsMemory(gpuAllocation);
}
TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromNTHandleIsCalledThenNonNullGraphicsAllocationsAreReturned) {
TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandleIsCalledThenNonNullGraphicsAllocationsAreReturned) {
void *pSysMem = reinterpret_cast<void *>(0x1000);
GmmRequirements gmmRequirements{};
gmmRequirements.allowLargePages = true;
@@ -2637,8 +2637,9 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromNTHandleIsCall
setSizesFcn(gmmPtrArray, 2u, 1024u, 1u);
for (uint32_t i = 0; i < 3; i++) {
MockWddmMemoryManager::ExtendedOsHandleData osHandleData{1u, i};
auto *gpuAllocation = memoryManager->createGraphicsAllocationFromNTHandle(osHandleData, 0, AllocationType::sharedImage);
MockWddmMemoryManager::OsHandleData osHandleData{NT_ALLOCATION_HANDLE, i};
AllocationProperties properties(0, false, 0u, AllocationType::sharedImage, false, 0);
auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandleData, properties, false, false, false, nullptr);
auto wddmAlloc = static_cast<WddmAllocation *>(gpuAllocation);
ASSERT_NE(nullptr, gpuAllocation);
EXPECT_EQ(NT_RESOURCE_HANDLE, wddmAlloc->getResourceHandle());
@@ -2654,7 +2655,7 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromNTHandleIsCall
}
}
TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromNTHandleIsCalledWithUmKmDataTranslatorEnabledThenNonNullGraphicsAllocationIsReturned) {
TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandleIsCalledWithUmKmDataTranslatorEnabledThenNonNullGraphicsAllocationIsReturned) {
struct MockUmKmDataTranslator : UmKmDataTranslator {
using UmKmDataTranslator::isEnabled;
};
@@ -2676,8 +2677,9 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromNTHandleIsCall
void *gmmPtrArray[]{gmm->gmmResourceInfo.get()};
setSizesFcn(gmmPtrArray, 1u, 1024u, 1u);
MockWddmMemoryManager::ExtendedOsHandleData osHandleData{1u};
auto *gpuAllocation = memoryManager->createGraphicsAllocationFromNTHandle(osHandleData, 0, AllocationType::sharedImage);
MockWddmMemoryManager::OsHandleData osHandleData{NT_ALLOCATION_HANDLE};
AllocationProperties properties(0, false, 0u, AllocationType::sharedImage, false, 0);
auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandleData, properties, false, false, false, nullptr);
auto wddmAlloc = static_cast<WddmAllocation *>(gpuAllocation);
ASSERT_NE(nullptr, gpuAllocation);
EXPECT_EQ(NT_RESOURCE_HANDLE, wddmAlloc->getResourceHandle());