@@ -588,68 +588,40 @@ class DXDevice : public hlsltest::Device {
588
588
return llvm::Error::success ();
589
589
}
590
590
};
591
+ } // namespace
591
592
592
- class DirectXContext {
593
- private:
594
- CComPtr<IDXGIFactory2> Factory;
595
- CComPtr<ID3D12Debug> Debug;
596
- CComPtr<ID3D12Debug1> Debug1; // I hate this name!
597
- llvm::SmallVector<std::shared_ptr<DXDevice>> Devices;
598
-
599
- DirectXContext () = default ;
600
- ~DirectXContext () = default ;
601
-
602
- public:
603
- llvm::Error initialize () {
604
-
593
+ llvm::Error InitializeDXDevices () {
605
594
#ifndef NDEBUG
606
- if (auto Err = HR::toError (D3D12GetDebugInterface (IID_PPV_ARGS (&Debug)),
607
- " failed to create D3D12 Debug Interface" ))
608
- return Err;
595
+ CComPtr<ID3D12Debug1> Debug1;
609
596
610
- if (auto Err = HR::toError (Debug->QueryInterface (IID_PPV_ARGS (&Debug1)),
611
- " Failed to queryy Debug interface" ))
612
- return Err;
613
- Debug->EnableDebugLayer ();
614
- Debug1->SetEnableGPUBasedValidation (true );
615
- #endif
597
+ if (auto Err = HR::toError (D3D12GetDebugInterface (IID_PPV_ARGS (&Debug1)),
598
+ " failed to create D3D12 Debug Interface" ))
599
+ return Err;
616
600
617
- if (auto Err = HR::toError (CreateDXGIFactory2 (0 , IID_PPV_ARGS (&Factory)),
618
- " Failed to create DXGI Factory" )) {
619
- return Err;
620
- }
621
- for (unsigned AdapterIndex = 0 ;;) {
622
- CComPtr<IDXGIAdapter1> Adapter;
623
-
624
- HRESULT HR = Factory->EnumAdapters1 (AdapterIndex++, &Adapter);
625
-
626
- if (DXGI_ERROR_NOT_FOUND == HR)
627
- return llvm::Error::success ();
601
+ Debug1->EnableDebugLayer ();
602
+ Debug1->SetEnableGPUBasedValidation (true );
603
+ #endif
628
604
629
- if (auto Err = HR::toError (HR, " " ))
630
- return Err;
631
- auto ExDevice = DXDevice::Create (Adapter);
632
- if (!ExDevice)
633
- return ExDevice.takeError ();
634
- auto ShPtr = std::make_shared<DXDevice>(*ExDevice);
635
- Devices.push_back (ShPtr);
636
- Device::registerDevice (std::static_pointer_cast<Device>(ShPtr));
637
- }
638
- return llvm::Error::success ();
605
+ CComPtr<IDXGIFactory2> Factory;
606
+ if (auto Err = HR::toError (CreateDXGIFactory2 (0 , IID_PPV_ARGS (&Factory)),
607
+ " Failed to create DXGI Factory" )) {
608
+ return Err;
639
609
}
610
+ for (unsigned AdapterIndex = 0 ;;) {
611
+ CComPtr<IDXGIAdapter1> Adapter;
640
612
641
- using iterator = llvm::SmallVector<std::shared_ptr<DXDevice>>::iterator ;
613
+ HRESULT HR = Factory-> EnumAdapters1 (AdapterIndex++, &Adapter) ;
642
614
643
- iterator begin () { return Devices. begin (); }
644
- iterator end () { return Devices. end (); }
615
+ if (DXGI_ERROR_NOT_FOUND == HR)
616
+ return llvm::Error::success ();
645
617
646
- static DirectXContext &Instance () {
647
- static DirectXContext Ctx;
648
- return Ctx;
618
+ if (auto Err = HR::toError (HR, " " ))
619
+ return Err;
620
+ auto ExDevice = DXDevice::Create (Adapter);
621
+ if (!ExDevice)
622
+ return ExDevice.takeError ();
623
+ auto ShPtr = std::make_shared<DXDevice>(*ExDevice);
624
+ Device::registerDevice (std::static_pointer_cast<Device>(ShPtr));
649
625
}
650
- };
651
- } // namespace
652
-
653
- llvm::Error InitializeDXDevices () {
654
- return DirectXContext::Instance ().initialize ();
626
+ return llvm::Error::success ();
655
627
}
0 commit comments