diff --git a/opencl/test/unit_test/mocks/mock_gmm_resource_info.h b/opencl/test/unit_test/mocks/mock_gmm_resource_info.h index 90c1e22f38..17fe099598 100644 --- a/opencl/test/unit_test/mocks/mock_gmm_resource_info.h +++ b/opencl/test/unit_test/mocks/mock_gmm_resource_info.h @@ -35,6 +35,8 @@ class MockGmmResourceInfo : public GmmResourceInfo { size_t getRenderPitch() override { return rowPitch; } + uint64_t getDriverProtectionBits() override { return driverProtectionBits; } + uint32_t getNumSamples() override { return mockResourceCreateParams.MSAA.NumSamples; } uint32_t getQPitch() override { return qPitch; } @@ -97,6 +99,7 @@ class MockGmmResourceInfo : public GmmResourceInfo { using GmmResourceInfo::clientContext; using GmmResourceInfo::createResourceInfo; + uint64_t driverProtectionBits = 0; uint32_t getOffsetCalled = 0u; uint32_t arrayIndexPassedToGetOffset = 0; SurfaceFormatInfo tempSurface{}; diff --git a/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp index 4a07c235a3..abf78da47b 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp @@ -387,9 +387,9 @@ TEST_F(Wddm20Tests, givenNullAllocationWhenCreateThenAllocateAndMap) { OsAgnosticMemoryManager mm(*executionEnvironment); WddmAllocation allocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 100, nullptr, MemoryPool::MemoryNull, 0u, 1u); - Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize(), getGmmClientContext()); + auto gmm = std::unique_ptr(GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize(), getGmmClientContext())); - allocation.setDefaultGmm(gmm); + allocation.setDefaultGmm(gmm.get()); auto status = wddm->createAllocation(&allocation); EXPECT_EQ(STATUS_SUCCESS, status); @@ -399,7 +399,6 @@ TEST_F(Wddm20Tests, givenNullAllocationWhenCreateThenAllocateAndMap) { EXPECT_NE(0u, allocation.getGpuAddress()); EXPECT_EQ(allocation.getGpuAddress(), GmmHelper::canonize(allocation.getGpuAddress())); - delete gmm; mm.freeSystemMemory(allocation.getUnderlyingBuffer()); } diff --git a/opencl/test/unit_test/test_files/igdrcl.config b/opencl/test/unit_test/test_files/igdrcl.config index ecbbaba05b..28ec8d841f 100644 --- a/opencl/test/unit_test/test_files/igdrcl.config +++ b/opencl/test/unit_test/test_files/igdrcl.config @@ -319,3 +319,4 @@ OverrideKernelSizeLimitForSmallDispatch = -1 SkipFlushingEventsOnGetStatusCalls = 0 AllowUnrestrictedSize = 0 DoNotFreeResources = 0 +OverrideGmmResourceUsageField = -1 diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index 7150b905fc..f4ba78b226 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -155,6 +155,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, OverrideMaxWorkGroupCount, -1, "-1: default, >0: DECLARE_DEBUG_VARIABLE(int32_t, OverrideCmdQueueSynchronousMode, -1, "Overrides all command queues synchronous mode: -1: do not override, 0: implicit driver behavior, 1: synchronous, 2: asynchronous") DECLARE_DEBUG_VARIABLE(int32_t, EnableStatelessCompression, -1, "-1: default, 0: disable, 1: Enable E2EC in SBA for all stateless accesses") DECLARE_DEBUG_VARIABLE(int32_t, EnableMultiTileCompression, -1, "-1: default, 0: disable, 1: enable, Enables compression in multi tile scenarios.") +DECLARE_DEBUG_VARIABLE(int32_t, OverrideGmmResourceUsageField, -1, "-1: default, >=0: gmm.resourceParams.Usage is set to this value") /*LOGGING FLAGS*/ DECLARE_DEBUG_VARIABLE(int32_t, PrintDriverDiagnostics, -1, "prints driver diagnostics messages to standard output, value corresponds to hint level") diff --git a/shared/source/gmm_helper/CMakeLists.txt b/shared/source/gmm_helper/CMakeLists.txt index dd1aaadeb5..5dbbb03bff 100644 --- a/shared/source/gmm_helper/CMakeLists.txt +++ b/shared/source/gmm_helper/CMakeLists.txt @@ -6,6 +6,7 @@ set(NEO_CORE_GMM_HELPER ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/resource_info_${DRIVER_MODEL}.cpp ${CMAKE_CURRENT_SOURCE_DIR}/client_context/gmm_client_context.cpp ${CMAKE_CURRENT_SOURCE_DIR}/client_context/gmm_client_context.h ${CMAKE_CURRENT_SOURCE_DIR}/gmm.cpp diff --git a/shared/source/gmm_helper/gmm.cpp b/shared/source/gmm_helper/gmm.cpp index de44684819..a05c3dd33c 100644 --- a/shared/source/gmm_helper/gmm.cpp +++ b/shared/source/gmm_helper/gmm.cpp @@ -61,12 +61,14 @@ Gmm::Gmm(GmmClientContext *clientContext, const void *alignedPtr, size_t aligned applyAuxFlagsForBuffer(preferRenderCompressed); applyMemoryFlags(systemMemoryPool, storageInfo); applyAppResource(storageInfo); + applyDebugOverrides(); gmmResourceInfo.reset(GmmResourceInfo::create(clientContext, &resourceParams)); } Gmm::Gmm(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmm) : clientContext(clientContext) { gmmResourceInfo.reset(GmmResourceInfo::create(clientContext, inputGmm)); + applyDebugOverrides(); } Gmm::~Gmm() = default; @@ -76,6 +78,7 @@ Gmm::Gmm(GmmClientContext *clientContext, ImageInfo &inputOutputImgInfo, Storage setupImageResourceParams(inputOutputImgInfo); applyMemoryFlags(!inputOutputImgInfo.useLocalMemory, storageInfo); applyAppResource(storageInfo); + applyDebugOverrides(); this->gmmResourceInfo.reset(GmmResourceInfo::create(clientContext, &this->resourceParams)); UNRECOVERABLE_IF(this->gmmResourceInfo == nullptr); @@ -121,6 +124,7 @@ void Gmm::setupImageResourceParams(ImageInfo &imgInfo) { resourceParams.NoGfxMemory = 1; // dont allocate, only query for params resourceParams.Usage = GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE; + resourceParams.Format = imgInfo.surfaceFormat->GMMSurfaceFormat; resourceParams.Flags.Gpu.Texture = 1; resourceParams.BaseWidth64 = imageWidth; @@ -374,4 +378,10 @@ void Gmm::applyMemoryFlags(bool systemMemoryPool, StorageInfo &storageInfo) { } } } + +void Gmm::applyDebugOverrides() { + if (-1 != DebugManager.flags.OverrideGmmResourceUsageField.get()) { + resourceParams.Usage = static_cast(DebugManager.flags.OverrideGmmResourceUsageField.get()); + } +} } // namespace NEO diff --git a/shared/source/gmm_helper/gmm.h b/shared/source/gmm_helper/gmm.h index f726bb223f..7e42a9b74f 100644 --- a/shared/source/gmm_helper/gmm.h +++ b/shared/source/gmm_helper/gmm.h @@ -58,6 +58,7 @@ class Gmm { void setupImageResourceParams(ImageInfo &imgInfo); bool extraMemoryFlagsRequired(); void applyExtraMemoryFlags(const StorageInfo &storageInfo); + void applyDebugOverrides(); GmmClientContext *clientContext = nullptr; }; } // namespace NEO diff --git a/shared/source/gmm_helper/resource_info.h b/shared/source/gmm_helper/resource_info.h index 0691a2ba25..ca5ab41730 100644 --- a/shared/source/gmm_helper/resource_info.h +++ b/shared/source/gmm_helper/resource_info.h @@ -33,6 +33,8 @@ class GmmResourceInfo { MOCKABLE_VIRTUAL size_t getRenderPitch() { return static_cast(resourceInfo->GetRenderPitch()); } + MOCKABLE_VIRTUAL uint64_t getDriverProtectionBits(); + MOCKABLE_VIRTUAL uint32_t getNumSamples() { return resourceInfo->GetNumSamples(); } MOCKABLE_VIRTUAL uint32_t getQPitch() { return resourceInfo->GetQPitch(); } diff --git a/shared/source/gmm_helper/resource_info_drm.cpp b/shared/source/gmm_helper/resource_info_drm.cpp new file mode 100644 index 0000000000..411518d9a6 --- /dev/null +++ b/shared/source/gmm_helper/resource_info_drm.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/gmm_helper/resource_info.h" + +namespace NEO { + +uint64_t GmmResourceInfo::getDriverProtectionBits() { + return 0u; +} +} // namespace NEO \ No newline at end of file diff --git a/shared/source/gmm_helper/resource_info_drm_or_wddm.cpp b/shared/source/gmm_helper/resource_info_drm_or_wddm.cpp new file mode 100644 index 0000000000..411518d9a6 --- /dev/null +++ b/shared/source/gmm_helper/resource_info_drm_or_wddm.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/gmm_helper/resource_info.h" + +namespace NEO { + +uint64_t GmmResourceInfo::getDriverProtectionBits() { + return 0u; +} +} // namespace NEO \ No newline at end of file diff --git a/shared/source/gmm_helper/resource_info_wddm.cpp b/shared/source/gmm_helper/resource_info_wddm.cpp new file mode 100644 index 0000000000..411518d9a6 --- /dev/null +++ b/shared/source/gmm_helper/resource_info_wddm.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/gmm_helper/resource_info.h" + +namespace NEO { + +uint64_t GmmResourceInfo::getDriverProtectionBits() { + return 0u; +} +} // namespace NEO \ No newline at end of file diff --git a/shared/source/os_interface/windows/CMakeLists.txt b/shared/source/os_interface/windows/CMakeLists.txt index 4554ea9f86..db4bd5b17d 100644 --- a/shared/source/os_interface/windows/CMakeLists.txt +++ b/shared/source/os_interface/windows/CMakeLists.txt @@ -25,16 +25,16 @@ set(NEO_CORE_OS_INTERFACE_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/os_memory_win.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_memory_win.h ${CMAKE_CURRENT_SOURCE_DIR}/os_socket.h - ${CMAKE_CURRENT_SOURCE_DIR}/os_time_win.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/os_time_win.h ${CMAKE_CURRENT_SOURCE_DIR}/os_thread_win.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_thread_win.h + ${CMAKE_CURRENT_SOURCE_DIR}/os_time_win.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/os_time_win.h ${CMAKE_CURRENT_SOURCE_DIR}/page_table_manager_functions.cpp ${CMAKE_CURRENT_SOURCE_DIR}/print.cpp ${CMAKE_CURRENT_SOURCE_DIR}/trim_callback.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/wddm/adapter_factory_create_with_fallback.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wddm/adapter_factory_dxgi.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wddm/adapter_factory_dxgi.h - ${CMAKE_CURRENT_SOURCE_DIR}/wddm/adapter_factory_create_with_fallback.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wddm/read_preemption_regkey.cpp ${CMAKE_CURRENT_SOURCE_DIR}/windows_inc.cpp ) @@ -43,6 +43,7 @@ set(NEO_CORE_OS_INTERFACE_WDDM ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/wddm_additional_context_flags.cpp ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/wddm_allocation.cpp + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/wddm_apply_additional_map_gpu_va_fields.cpp ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/wddm_engine_mapper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/d3dkmthk_wrapper.h ${CMAKE_CURRENT_SOURCE_DIR}/dxgi_wrapper.h diff --git a/shared/source/os_interface/windows/wddm/wddm.cpp b/shared/source/os_interface/windows/wddm/wddm.cpp index 8993260a5b..70aeb7e00e 100644 --- a/shared/source/os_interface/windows/wddm/wddm.cpp +++ b/shared/source/os_interface/windows/wddm/wddm.cpp @@ -431,6 +431,7 @@ bool Wddm::mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTUAL_A MapGPUVA.hPagingQueue = pagingQueue; MapGPUVA.hAllocation = handle; MapGPUVA.Protection = protectionType; + MapGPUVA.SizeInPages = size / MemoryConstants::pageSize; MapGPUVA.OffsetInPages = 0; @@ -438,6 +439,8 @@ bool Wddm::mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTUAL_A MapGPUVA.MinimumAddress = minimumAddress; MapGPUVA.MaximumAddress = maximumAddress; + applyAdditionalMapGPUVAFields(MapGPUVA, gmm); + NTSTATUS status = getGdi()->mapGpuVirtualAddress(&MapGPUVA); gpuPtr = GmmHelper::canonize(MapGPUVA.VirtualAddress); diff --git a/shared/source/os_interface/windows/wddm/wddm.h b/shared/source/os_interface/windows/wddm/wddm.h index 8dcc25db30..e9f80c8fd7 100644 --- a/shared/source/os_interface/windows/wddm/wddm.h +++ b/shared/source/os_interface/windows/wddm/wddm.h @@ -75,6 +75,7 @@ class Wddm : public DriverModel { MOCKABLE_VIRTUAL D3DGPU_VIRTUAL_ADDRESS reserveGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS minimumAddress, D3DGPU_VIRTUAL_ADDRESS maximumAddress, D3DGPU_SIZE_T size); MOCKABLE_VIRTUAL bool createContext(OsContextWin &osContext); MOCKABLE_VIRTUAL void applyAdditionalContextFlags(CREATECONTEXT_PVTDATA &privateData, OsContextWin &osContext, const HardwareInfo &hwInfo); + MOCKABLE_VIRTUAL void applyAdditionalMapGPUVAFields(D3DDDI_MAPGPUVIRTUALADDRESS &MapGPUVA, Gmm *gmm); MOCKABLE_VIRTUAL bool freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size); MOCKABLE_VIRTUAL NTSTATUS createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle, D3DKMT_HANDLE &outResourceHandle, D3DKMT_HANDLE *outSharedHandle); MOCKABLE_VIRTUAL bool createAllocation(const Gmm *gmm, D3DKMT_HANDLE &outHandle); diff --git a/shared/source/os_interface/windows/wddm_additional_context_flags.cpp b/shared/source/os_interface/windows/wddm_additional_context_flags.cpp index 6e47ecd7bf..f7ed17d9a6 100644 --- a/shared/source/os_interface/windows/wddm_additional_context_flags.cpp +++ b/shared/source/os_interface/windows/wddm_additional_context_flags.cpp @@ -10,4 +10,5 @@ namespace NEO { void Wddm::applyAdditionalContextFlags(CREATECONTEXT_PVTDATA &privateData, OsContextWin &osContext, const HardwareInfo &hwInfo) { } + } // namespace NEO diff --git a/shared/source/os_interface/windows/wddm_apply_additional_map_gpu_va_fields.cpp b/shared/source/os_interface/windows/wddm_apply_additional_map_gpu_va_fields.cpp new file mode 100644 index 0000000000..45fc3dec53 --- /dev/null +++ b/shared/source/os_interface/windows/wddm_apply_additional_map_gpu_va_fields.cpp @@ -0,0 +1,13 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/windows/wddm/wddm.h" + +namespace NEO { +void Wddm::applyAdditionalMapGPUVAFields(D3DDDI_MAPGPUVIRTUALADDRESS &mapGPUVA, Gmm *gmm) { +} +} // namespace NEO