diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index 5b473f8602..bd18faa2ee 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -361,6 +361,7 @@ DECLARE_DEBUG_VARIABLE(bool, DisableConcurrentBlockExecution, false, "disables c DECLARE_DEBUG_VARIABLE(bool, UseNoRingFlushesKmdMode, true, "Windows only, passes flag to KMD that informs KMD to not emit any ring buffer flushes.") DECLARE_DEBUG_VARIABLE(bool, DisableZeroCopyForUseHostPtr, false, "When active all buffer allocations created with CL_MEM_USE_HOST_PTR flag will not share memory with CPU.") DECLARE_DEBUG_VARIABLE(bool, ForceNonCoherentModeForTimestamps, false, "When active timestamp buffers are allocated in non coherent memory.") +DECLARE_DEBUG_VARIABLE(bool, SetAssumeNotInUse, true, "Set AssumeNotInUse flag in d3d destroy allocation.") DECLARE_DEBUG_VARIABLE(int32_t, EnableReusingGpuTimestamps, -1, "Reuse GPU timestamp for next device time requests. -1: os-specific, 0: disable, 1: enable") DECLARE_DEBUG_VARIABLE(int32_t, AllowZeroCopyWithoutCoherency, -1, "Use cacheline flush instead of memory copy for map/unmap mem object") DECLARE_DEBUG_VARIABLE(int32_t, EnableHostPtrTracking, -1, "Enable host ptr tracking: -1 - default platform setting, 0 - disabled, 1 - enabled") diff --git a/shared/source/gmm_helper/client_context/gmm_client_context.h b/shared/source/gmm_helper/client_context/gmm_client_context.h index 0b35d232bc..d919ae8e09 100644 --- a/shared/source/gmm_helper/client_context/gmm_client_context.h +++ b/shared/source/gmm_helper/client_context/gmm_client_context.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -16,6 +16,7 @@ struct RootDeviceEnvironment; class GmmHandleAllocator; class MapGpuVirtualAddressGmm; class FreeGpuVirtualAddressGmm; +class DeallocateGmm; class GmmClientContext { public: @@ -28,6 +29,7 @@ class GmmClientContext { MOCKABLE_VIRTUAL GMM_RESOURCE_INFO *createResInfoObject(GMM_RESCREATE_PARAMS *pCreateParams); MOCKABLE_VIRTUAL GMM_RESOURCE_INFO *copyResInfoObject(GMM_RESOURCE_INFO *pSrcRes); MOCKABLE_VIRTUAL void destroyResInfoObject(GMM_RESOURCE_INFO *pResInfo); + MOCKABLE_VIRTUAL long deallocate2(DeallocateGmm *deallocateGmm); MOCKABLE_VIRTUAL uint64_t mapGpuVirtualAddress(MapGpuVirtualAddressGmm *pMapGpuVa); MOCKABLE_VIRTUAL uint64_t freeGpuVirtualAddress(FreeGpuVirtualAddressGmm *pFreeGpuVa); GMM_CLIENT_CONTEXT *getHandle() const; diff --git a/shared/source/gmm_helper/client_context/gmm_client_context_drm.cpp b/shared/source/gmm_helper/client_context/gmm_client_context_drm.cpp index 78c638cc3d..d7719a159b 100644 --- a/shared/source/gmm_helper/client_context/gmm_client_context_drm.cpp +++ b/shared/source/gmm_helper/client_context/gmm_client_context_drm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -14,5 +14,8 @@ uint64_t GmmClientContext::mapGpuVirtualAddress(MapGpuVirtualAddressGmm *pMapGpu uint64_t GmmClientContext::freeGpuVirtualAddress(FreeGpuVirtualAddressGmm *pFreeGpuVa) { return 0; } +long GmmClientContext::deallocate2(DeallocateGmm *deallocateGmm) { + return 0; +} } // namespace NEO diff --git a/shared/source/gmm_helper/client_context/gmm_client_context_drm_or_wddm.cpp b/shared/source/gmm_helper/client_context/gmm_client_context_drm_or_wddm.cpp index d5c1ffd2ad..f720b63950 100644 --- a/shared/source/gmm_helper/client_context/gmm_client_context_drm_or_wddm.cpp +++ b/shared/source/gmm_helper/client_context/gmm_client_context_drm_or_wddm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -16,5 +16,8 @@ uint64_t GmmClientContext::mapGpuVirtualAddress(MapGpuVirtualAddressGmm *pMapGpu uint64_t GmmClientContext::freeGpuVirtualAddress(FreeGpuVirtualAddressGmm *pFreeGpuVa) { return 0; } +long GmmClientContext::deallocate2(DeallocateGmm *deallocateGmm) { + return deallocateGmm->gdi->destroyAllocation2(deallocateGmm->destroyAllocation2); +} } // namespace NEO diff --git a/shared/source/gmm_helper/client_context/gmm_client_context_wddm.cpp b/shared/source/gmm_helper/client_context/gmm_client_context_wddm.cpp index ab7143e08a..87e17989bd 100644 --- a/shared/source/gmm_helper/client_context/gmm_client_context_wddm.cpp +++ b/shared/source/gmm_helper/client_context/gmm_client_context_wddm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -31,5 +31,10 @@ uint64_t GmmClientContext::freeGpuVirtualAddress(FreeGpuVirtualAddressGmm *pFree return 0; } } +long GmmClientContext::deallocate2(DeallocateGmm *deallocateGmm) { + GMM_DESTROYALLOCATION2 gmmDestroyAllocation2{}; + memcpy_s(&gmmDestroyAllocation2.KmtObj, sizeof(D3DKMT_DESTROYALLOCATION2), deallocateGmm->destroyAllocation2, sizeof(D3DKMT_DESTROYALLOCATION2)); + return clientContext->DeAllocate2(&gmmDestroyAllocation2); +} } // namespace NEO diff --git a/shared/source/gmm_helper/client_context/map_gpu_va_gmm.h b/shared/source/gmm_helper/client_context/map_gpu_va_gmm.h index 1b09fd9a5e..5bbe2c8c74 100644 --- a/shared/source/gmm_helper/client_context/map_gpu_va_gmm.h +++ b/shared/source/gmm_helper/client_context/map_gpu_va_gmm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -31,4 +31,11 @@ class FreeGpuVirtualAddressGmm { Gdi *gdi; }; +class DeallocateGmm { + public: + DeallocateGmm(D3DKMT_DESTROYALLOCATION2 *destroyAllocation2, Gdi *gdi) : destroyAllocation2(destroyAllocation2), gdi(gdi) {} + D3DKMT_DESTROYALLOCATION2 *destroyAllocation2; + Gdi *gdi; +}; + } // namespace NEO \ No newline at end of file diff --git a/shared/source/gmm_helper/gmm.cpp b/shared/source/gmm_helper/gmm.cpp index 9ca252d487..645c4a7499 100644 --- a/shared/source/gmm_helper/gmm.cpp +++ b/shared/source/gmm_helper/gmm.cpp @@ -69,6 +69,7 @@ Gmm::Gmm(GmmHelper *gmmHelper, const void *alignedPtr, size_t alignedSize, size_ applyAuxFlagsForBuffer(gmmRequirements.preferCompressed && !storageInfo.isLockable); applyMemoryFlags(storageInfo); applyAppResource(storageInfo); + applyExtraInitFlag(); applyDebugOverrides(); gmmResourceInfo.reset(GmmResourceInfo::create(gmmHelper->getClientContext(), &resourceParams)); diff --git a/shared/source/gmm_helper/gmm.h b/shared/source/gmm_helper/gmm.h index 32d1f53a45..8a089a083a 100644 --- a/shared/source/gmm_helper/gmm.h +++ b/shared/source/gmm_helper/gmm.h @@ -80,6 +80,7 @@ class Gmm { void setupImageResourceParams(ImageInfo &imgInfo, bool preferCompressed); bool extraMemoryFlagsRequired(); void applyExtraMemoryFlags(const StorageInfo &storageInfo); + void applyExtraInitFlag(); void applyDebugOverrides(); GmmHelper *gmmHelper = nullptr; diff --git a/shared/source/gmm_helper/gmm_utils.cpp b/shared/source/gmm_helper/gmm_utils.cpp index d92880e487..09e42dd0c8 100644 --- a/shared/source/gmm_helper/gmm_utils.cpp +++ b/shared/source/gmm_helper/gmm_utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -13,3 +13,4 @@ using namespace NEO; void Gmm::applyExtraMemoryFlags(const StorageInfo &storageInfo) {} bool Gmm::extraMemoryFlagsRequired() { return false; } void Gmm::applyAppResource(const StorageInfo &storageInfo) {} +void Gmm::applyExtraInitFlag() {} diff --git a/shared/source/os_interface/windows/wddm/wddm.cpp b/shared/source/os_interface/windows/wddm/wddm.cpp index 4fa494d995..861fb90bf9 100644 --- a/shared/source/os_interface/windows/wddm/wddm.cpp +++ b/shared/source/os_interface/windows/wddm/wddm.cpp @@ -819,7 +819,9 @@ bool Wddm::destroyAllocations(const D3DKMT_HANDLE *handles, uint32_t allocationC if ((0U == allocationCount) && (0U == resourceHandle)) { return true; } + NTSTATUS status = STATUS_SUCCESS; + D3DKMT_DESTROYALLOCATION2 destroyAllocation = {}; DEBUG_BREAK_IF(!(allocationCount <= 1 || resourceHandle == 0)); @@ -827,10 +829,11 @@ bool Wddm::destroyAllocations(const D3DKMT_HANDLE *handles, uint32_t allocationC destroyAllocation.hResource = resourceHandle; destroyAllocation.phAllocationList = handles; destroyAllocation.AllocationCount = allocationCount; + destroyAllocation.Flags.AssumeNotInUse = debugManager.flags.SetAssumeNotInUse.get(); - destroyAllocation.Flags.AssumeNotInUse = 1; + DeallocateGmm deallocateGmm{&destroyAllocation, getGdi()}; - status = getGdi()->destroyAllocation2(&destroyAllocation); + status = static_cast(this->rootDeviceEnvironment.getGmmClientContext()->deallocate2(&deallocateGmm)); return status == STATUS_SUCCESS; } diff --git a/shared/test/common/mocks/mock_gmm_client_context_base.h b/shared/test/common/mocks/mock_gmm_client_context_base.h index 98cdebda3b..7313402f5b 100644 --- a/shared/test/common/mocks/mock_gmm_client_context_base.h +++ b/shared/test/common/mocks/mock_gmm_client_context_base.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -22,6 +22,7 @@ class MockGmmClientContextBase : public GmmClientContext { GMM_RESOURCE_INFO *createResInfoObject(GMM_RESCREATE_PARAMS *pCreateParams) override; GMM_RESOURCE_INFO *copyResInfoObject(GMM_RESOURCE_INFO *pSrcRes) override; void destroyResInfoObject(GMM_RESOURCE_INFO *pResInfo) override; + long deallocate2(DeallocateGmm *deallocateGmm) override; uint8_t getSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT format) override; uint8_t getMediaSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT format) override; void setGmmDeviceInfo(GMM_DEVICE_INFO *deviceInfo) override; diff --git a/shared/test/common/mocks/mock_gmm_client_context_base_drm.cpp b/shared/test/common/mocks/mock_gmm_client_context_base_drm.cpp index 88d86e84d3..70c203c61d 100644 --- a/shared/test/common/mocks/mock_gmm_client_context_base_drm.cpp +++ b/shared/test/common/mocks/mock_gmm_client_context_base_drm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -12,4 +12,7 @@ uint64_t MockGmmClientContextBase::mapGpuVirtualAddress(MapGpuVirtualAddressGmm mapGpuVirtualAddressCalled++; return 0; } +long MockGmmClientContextBase::deallocate2(DeallocateGmm *deallocateGmm) { + return 0; +} } // namespace NEO \ No newline at end of file diff --git a/shared/test/common/mocks/mock_gmm_client_context_base_drm_or_wddm.cpp b/shared/test/common/mocks/mock_gmm_client_context_base_drm_or_wddm.cpp index ec336eb9f7..312e2936c7 100644 --- a/shared/test/common/mocks/mock_gmm_client_context_base_drm_or_wddm.cpp +++ b/shared/test/common/mocks/mock_gmm_client_context_base_drm_or_wddm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -14,4 +14,7 @@ uint64_t MockGmmClientContextBase::mapGpuVirtualAddress(MapGpuVirtualAddressGmm mapGpuVirtualAddressCalled++; return pMapGpuVa->gdi->mapGpuVirtualAddress(pMapGpuVa->mapGpuVirtualAddressParams); } +long MockGmmClientContextBase::deallocate2(DeallocateGmm *deallocateGmm) { + return deallocateGmm->gdi->destroyAllocation2(deallocateGmm->destroyAllocation2); +} } // namespace NEO diff --git a/shared/test/common/mocks/mock_gmm_client_context_base_wddm.cpp b/shared/test/common/mocks/mock_gmm_client_context_base_wddm.cpp index dfbff22ffc..80b5b9c246 100644 --- a/shared/test/common/mocks/mock_gmm_client_context_base_wddm.cpp +++ b/shared/test/common/mocks/mock_gmm_client_context_base_wddm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -14,4 +14,7 @@ uint64_t MockGmmClientContextBase::mapGpuVirtualAddress(MapGpuVirtualAddressGmm mapGpuVirtualAddressCalled++; return pMapGpuVa->gdi->mapGpuVirtualAddress(pMapGpuVa->mapGpuVirtualAddressParams); } +long MockGmmClientContextBase::deallocate2(DeallocateGmm *deallocateGmm) { + return deallocateGmm->gdi->destroyAllocation2(deallocateGmm->destroyAllocation2); +} } // namespace NEO diff --git a/shared/test/common/test_files/igdrcl.config b/shared/test/common/test_files/igdrcl.config index 9656f6adf7..525a4df5f5 100644 --- a/shared/test/common/test_files/igdrcl.config +++ b/shared/test/common/test_files/igdrcl.config @@ -622,6 +622,7 @@ DeferStateInitSubmissionToFirstRegularUsage = -1 WaitForPagingFenceInController = -1 DirectSubmissionPrintSemaphoreUsage = -1 ForceNonCoherentModeForTimestamps = 0 +SetAssumeNotInUse = 1 ExperimentalUSMAllocationReuseVersion = -1 ForceNonWalkerSplitMemoryCopy = -1 DirectSubmissionSwitchSemaphoreMode = -1 diff --git a/shared/test/unit_test/os_interface/windows/wddm20_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm20_tests.cpp index 17a181822e..a842bb99e7 100644 --- a/shared/test/unit_test/os_interface/windows/wddm20_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm20_tests.cpp @@ -394,6 +394,30 @@ TEST_F(Wddm20WithMockGdiDllTests, GivenThreeOsHandlesWhenAskedForDestroyAllocati EXPECT_EQ(1u, ptrToDestroyAlloc2->Flags.AssumeNotInUse); } +TEST_F(Wddm20WithMockGdiDllTests, GivenSetAssumeNotInUseSetToFalseWhenDestroyAllocationsThenAssumeNotInUseNotSet) { + DebugManagerStateRestore restorer; + debugManager.flags.SetAssumeNotInUse.set(false); + + OsHandleStorage storage; + OsHandleWin osHandle1; + + osHandle1.handle = ALLOCATION_HANDLE; + + storage.fragmentStorageData[0].osHandleStorage = &osHandle1; + storage.fragmentStorageData[0].freeTheFragment = true; + + D3DKMT_HANDLE handles[1] = {ALLOCATION_HANDLE}; + bool retVal = wddm->destroyAllocations(handles, 1, 0); + EXPECT_TRUE(retVal); + + auto destroyWithResourceHandleCalled = 0u; + D3DKMT_DESTROYALLOCATION2 *ptrToDestroyAlloc2 = nullptr; + + getSizesFcn(destroyWithResourceHandleCalled, ptrToDestroyAlloc2); + + EXPECT_EQ(0u, ptrToDestroyAlloc2->Flags.AssumeNotInUse); +} + TEST_F(Wddm20Tests, WhenMappingAndFreeingGpuVaThenReturnIsCorrect) { OsAgnosticMemoryManager mm(*executionEnvironment); auto gmmHelper = getGmmHelper();