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