diff --git a/runtime/os_interface/windows/wddm.cpp b/runtime/os_interface/windows/wddm.cpp index b2a2d303cf..baaf3877e5 100644 --- a/runtime/os_interface/windows/wddm.cpp +++ b/runtime/os_interface/windows/wddm.cpp @@ -720,7 +720,7 @@ void Wddm::kmDafLock(WddmAllocation *wddmAllocation) { kmDafListener->notifyLock(featureTable->ftrKmdDaf, adapter, device, wddmAllocation->handle, 0, gdi->escape); } -D3DKMT_HANDLE Wddm::createContext() { +bool Wddm::createContext() { NTSTATUS status = STATUS_UNSUCCESSFUL; D3DKMT_CREATECONTEXTVIRTUAL CreateContext = {0}; CREATECONTEXT_PVTDATA PrivateData = {{0}}; @@ -747,10 +747,9 @@ D3DKMT_HANDLE Wddm::createContext() { CreateContext.hDevice = device; status = gdi->createContext(&CreateContext); - if (status == STATUS_SUCCESS) { - return CreateContext.hContext; - } - return static_cast(0); + context = CreateContext.hContext; + + return status == STATUS_SUCCESS; } bool Wddm::destroyContext(D3DKMT_HANDLE context) { @@ -761,7 +760,7 @@ bool Wddm::destroyContext(D3DKMT_HANDLE context) { DestroyContext.hContext = context; status = gdi->destroyContext(&DestroyContext); } - return status == STATUS_SUCCESS ? true : false; + return status == STATUS_SUCCESS; } bool Wddm::submit(uint64_t commandBuffer, size_t size, void *commandHeader) { diff --git a/runtime/os_interface/windows/wddm.h b/runtime/os_interface/windows/wddm.h index 74c3ff8953..003ee7dbbc 100644 --- a/runtime/os_interface/windows/wddm.h +++ b/runtime/os_interface/windows/wddm.h @@ -79,7 +79,7 @@ class Wddm { MOCKABLE_VIRTUAL bool makeResident(D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim); bool mapGpuVirtualAddress(WddmAllocation *allocation, void *cpuPtr, uint64_t size, bool allocation32bit, bool use64kbPages, bool useHeap1); bool mapGpuVirtualAddress(AllocationStorageData *allocationStorageData, bool allocation32bit, bool use64kbPages); - MOCKABLE_VIRTUAL D3DKMT_HANDLE createContext(); + MOCKABLE_VIRTUAL bool createContext(); MOCKABLE_VIRTUAL bool freeGpuVirtualAddres(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size); MOCKABLE_VIRTUAL NTSTATUS createAllocation(WddmAllocation *alloc); MOCKABLE_VIRTUAL bool createAllocation64k(WddmAllocation *alloc); diff --git a/runtime/os_interface/windows/wddm.inl b/runtime/os_interface/windows/wddm.inl index 94cbb10913..f62b87a88b 100644 --- a/runtime/os_interface/windows/wddm.inl +++ b/runtime/os_interface/windows/wddm.inl @@ -39,38 +39,32 @@ bool Wddm::configureDeviceAddressSpace() { template bool Wddm::init() { - bool success = false; if (gdi != nullptr && gdi->isInitialized() && !initialized) { - do { - success = openAdapter(); - if (!success) - break; - success = queryAdapterInfo(); - if (!success) - break; - success = createDevice(); - if (!success) - break; - success = createPagingQueue(); - if (!success) - break; - success = Gmm::initContext(gfxPlatform.get(), - featureTable.get(), - waTable.get(), - gtSystemInfo.get()); - if (!success) - break; - success = configureDeviceAddressSpace(); - if (!success) - break; - context = createContext(); - if (context == static_cast(0)) - break; - success = createMonitoredFence(); - if (!success) - break; - initialized = true; - } while (!success); + if (!openAdapter()) { + return false; + } + if (!queryAdapterInfo()) { + return false; + } + if (!createDevice()) { + return false; + } + if (!createPagingQueue()) { + return false; + } + if (!Gmm::initContext(gfxPlatform.get(), featureTable.get(), waTable.get(), gtSystemInfo.get())) { + return false; + } + if (!configureDeviceAddressSpace()) { + return false; + } + if (!createContext()) { + return false; + } + if (!createMonitoredFence()) { + return false; + } + initialized = true; } return initialized; } diff --git a/unit_tests/os_interface/windows/wddm_fixture.h b/unit_tests/os_interface/windows/wddm_fixture.h index 047d389950..55dea20080 100644 --- a/unit_tests/os_interface/windows/wddm_fixture.h +++ b/unit_tests/os_interface/windows/wddm_fixture.h @@ -194,11 +194,9 @@ class WddmMock : public Wddm { } } - D3DKMT_HANDLE createContext() override { + bool createContext() override { createContextResult.called++; - D3DKMT_HANDLE context = Wddm::createContext(); - createContextResult.success = context != 0; - return context; + return createContextResult.success = Wddm::createContext(); } bool destroyContext(D3DKMT_HANDLE context) override { destroyContextResult.called++; diff --git a/unit_tests/os_interface/windows/wddm_tests.cpp b/unit_tests/os_interface/windows/wddm_tests.cpp index c2d848c0dc..a005c429ad 100644 --- a/unit_tests/os_interface/windows/wddm_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_tests.cpp @@ -172,12 +172,16 @@ TEST(WddmTestEnumAdapters, devIdExpectFalse) { } HWTEST_F(WddmTest, context) { + EXPECT_TRUE(wddm->getOsDeviceContext() == static_cast(0)); wddm->init(); ASSERT_TRUE(wddm->isInitialized()); - D3DKMT_HANDLE context = wddm->createContext(); + + EXPECT_TRUE(wddm->createContext()); + + auto context = wddm->getOsDeviceContext(); EXPECT_TRUE(context != static_cast(0)); - bool error = wddm->destroyContext(context); - EXPECT_TRUE(error); + + EXPECT_TRUE(wddm->destroyContext(context)); } HWTEST_F(WddmTest, allocation) {