fix: correct flags for creating allocation with existing system memory

on Windows setup ReadOnly flag, it makes there is no ProbeForWrite call within
CreateAllocation2 function call

it doesn't force read-only access from GPU perspective, that access it
defined in MapGpuVa function

Related-To: NEO-12986, HSD-15016952776
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2025-01-30 19:43:45 +00:00
committed by Compute-Runtime-Automation
parent aace15d6bc
commit a924761ed1
15 changed files with 91 additions and 146 deletions

View File

@@ -97,7 +97,6 @@ set(NEO_CORE_OS_INTERFACE_WDDM
${CMAKE_CURRENT_SOURCE_DIR}/wddm/set_gmm_input_args_${DRIVER_MODEL}.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wddm/max_mem_alloc_size_${DRIVER_MODEL}.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wddm/helper_${DRIVER_MODEL}.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wddm/is_readonly_memory_${DRIVER_MODEL}.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wddm/skip_resource_cleanup_${DRIVER_MODEL}.cpp
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}map_tile_instanced_allocation_${DRIVER_MODEL}.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm.cpp

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2022 Intel Corporation
* Copyright (C) 2021-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -12,4 +12,7 @@ namespace NEO {
NTSTATUS Wddm::createNTHandle(const D3DKMT_HANDLE *resourceHandle, HANDLE *ntHandle) {
return getGdi()->shareObjects(1, resourceHandle, nullptr, SHARED_ALLOCATION_WRITE, ntHandle);
}
bool Wddm::getReadOnlyFlagValue(const void *alignedCpuPtr) const {
return false;
}
} // namespace NEO

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Intel Corporation
* Copyright (C) 2021-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -16,4 +16,8 @@ NTSTATUS Wddm::createNTHandle(const D3DKMT_HANDLE *resourceHandle, HANDLE *ntHan
return getGdi()->shareObjects(1, resourceHandle, &objAttr, SHARED_ALLOCATION_WRITE, ntHandle);
}
bool Wddm::getReadOnlyFlagValue(const void *alignedCpuPtr) const {
return alignedCpuPtr != nullptr;
}
} // namespace NEO

View File

@@ -1,14 +0,0 @@
/*
* Copyright (C) 2024-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/windows/wddm/wddm.h"
namespace NEO {
bool Wddm::isReadOnlyMemory(const void *ptr) {
return false;
}
} // namespace NEO

View File

@@ -1,21 +0,0 @@
/*
* Copyright (C) 2024-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/windows/sys_calls.h"
#include "shared/source/os_interface/windows/wddm/wddm.h"
namespace NEO {
bool Wddm::isReadOnlyMemory(const void *ptr) {
if (ptr) {
MEMORY_BASIC_INFORMATION info;
SysCalls::virtualQuery(ptr, &info, sizeof(info));
return info.Protect & PAGE_READONLY;
}
return false;
}
} // namespace NEO

View File

@@ -665,6 +665,7 @@ NTSTATUS Wddm::createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKM
createAllocation.Flags.CreateShared = outSharedHandle ? TRUE : FALSE;
createAllocation.Flags.NtSecuritySharing = outSharedHandle ? TRUE : FALSE;
createAllocation.Flags.CreateResource = outSharedHandle ? TRUE : FALSE;
createAllocation.Flags.ReadOnly = getReadOnlyFlagValue(alignedCpuPtr);
createAllocation.pAllocationInfo2 = &allocationInfo;
createAllocation.hDevice = device;
@@ -677,12 +678,6 @@ NTSTATUS Wddm::createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKM
}
status = getGdi()->createAllocation2(&createAllocation);
if (status != STATUS_SUCCESS) {
if (isReadOnlyMemory(alignedCpuPtr)) {
createAllocation.Flags.ReadOnly = true;
status = getGdi()->createAllocation2(&createAllocation);
}
}
if (status != STATUS_SUCCESS) {
DEBUG_BREAK_IF(true);
return status;
@@ -777,19 +772,13 @@ NTSTATUS Wddm::createAllocationsAndMapGpuVa(OsHandleStorage &osHandles) {
createAllocation.Flags.CreateShared = FALSE;
createAllocation.Flags.RestrictSharedAccess = FALSE;
createAllocation.Flags.CreateResource = FALSE;
createAllocation.Flags.ReadOnly = getReadOnlyFlagValue(allocationInfo[0].pSystemMem);
createAllocation.pAllocationInfo2 = allocationInfo;
createAllocation.hDevice = device;
while (status == STATUS_UNSUCCESSFUL) {
status = getGdi()->createAllocation2(&createAllocation);
if (status != STATUS_SUCCESS) {
if (isReadOnlyMemory(allocationInfo[0].pSystemMem)) {
createAllocation.Flags.ReadOnly = true;
status = getGdi()->createAllocation2(&createAllocation);
}
}
if (status != STATUS_SUCCESS) {
PRINT_DEBUG_STRING(debugManager.flags.PrintDebugMessages.get(), stderr, "%s status: %d", __FUNCTION__, status);
DEBUG_BREAK_IF(status != STATUS_GRAPHICS_NO_VIDEO_MEMORY);

View File

@@ -257,7 +257,7 @@ class Wddm : public DriverModel {
void setNewResourceBoundToPageTable();
void setProcessPowerThrottling();
void setThreadPriority();
bool isReadOnlyMemory(const void *ptr);
bool getReadOnlyFlagValue(const void *alignedCpuPtr) const;
GMM_GFX_PARTITIONING gfxPartition{};
ADAPTER_BDF adapterBDF{};