Skip to content

Commit f207b52

Browse files
committed
Add D3D10 and D3D11 wrappers
These two new classes wrap the enumeration and creation of D3D10 and D3D11 adapters and logical devices. Adapters and their related devices are grouped together using simple `DeviceEntry` structs and tracked using a `std::vector` and `ComPtr` to avoid leaking resources.` No functional change, as these wrappers are not yet used. Signed-off-by: Ahmed Hesham <ahmed.hesham@arm.com>
1 parent de3b8c0 commit f207b52

2 files changed

Lines changed: 101 additions & 1 deletion

File tree

test_conformance/common/directx_wrapper/directx_wrapper.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,65 @@ DirectX12FenceWrapper::DirectX12FenceWrapper(ID3D12Device* dx_device)
7373
}
7474
}
7575
#endif
76+
77+
#if D3D11_IS_SUPPORTED
78+
DirectX11Wrapper::DirectX11Wrapper()
79+
{
80+
ComPtr<IDXGIFactory> factory;
81+
HRESULT hr = CreateDXGIFactory(IID_PPV_ARGS(factory.GetAddressOf()));
82+
if (FAILED(hr))
83+
{
84+
throw std::runtime_error("Failed to create DXGI factory");
85+
}
86+
87+
UINT i = 0;
88+
ComPtr<IDXGIAdapter> adapter;
89+
while (factory->EnumAdapters(i, adapter.GetAddressOf())
90+
!= DXGI_ERROR_NOT_FOUND)
91+
{
92+
++i;
93+
94+
ComPtr<ID3D11Device> device;
95+
hr = D3D11CreateDevice(adapter.Get(), D3D_DRIVER_TYPE_HARDWARE, nullptr,
96+
0, nullptr, 0, D3D11_SDK_VERSION,
97+
device.GetAddressOf(), nullptr, nullptr);
98+
if (FAILED(hr))
99+
{
100+
throw std::runtime_error("Failed to create DirectX 10 device");
101+
}
102+
103+
devices.push_back({ adapter, device });
104+
}
105+
}
106+
#endif
107+
108+
#if D3D10_IS_SUPPORTED
109+
DirectX10Wrapper::DirectX10Wrapper()
110+
{
111+
ComPtr<IDXGIFactory> factory;
112+
HRESULT hr = CreateDXGIFactory(IID_PPV_ARGS(factory.GetAddressOf()));
113+
if (FAILED(hr))
114+
{
115+
throw std::runtime_error("Failed to create DXGI factory");
116+
}
117+
118+
UINT i = 0;
119+
ComPtr<IDXGIAdapter> adapter;
120+
while (factory->EnumAdapters(i, adapter.GetAddressOf())
121+
!= DXGI_ERROR_NOT_FOUND)
122+
{
123+
++i;
124+
125+
ComPtr<ID3D10Device> device;
126+
hr = D3D10CreateDevice(adapter.Get(), D3D10_DRIVER_TYPE_HARDWARE,
127+
nullptr, 0, D3D10_SDK_VERSION,
128+
device.GetAddressOf());
129+
if (FAILED(hr))
130+
{
131+
throw std::runtime_error("Failed to create DirectX 10 device");
132+
}
133+
134+
devices.push_back({ adapter, device });
135+
}
136+
}
137+
#endif

test_conformance/common/directx_wrapper/directx_wrapper.hpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
#if D3D12_IS_SUPPORTED
2020
#include <d3d12.h>
2121
#endif
22+
#if D3D11_IS_SUPPORTED
23+
#include <cl/cl_d3d11.h>
24+
#endif
25+
#if D3D10_IS_SUPPORTED
26+
#include <cl/cl_d3d10.h>
27+
#endif
28+
29+
#include <vector>
2230
#include <wrl/client.h>
2331

2432
using namespace Microsoft::WRL;
@@ -47,4 +55,34 @@ class DirectX12FenceWrapper {
4755
ComPtr<ID3D12Fence> dx_fence = nullptr;
4856
ComPtr<ID3D12Device> dx_device = nullptr;
4957
};
50-
#endif
58+
#endif
59+
60+
#if D3D11_IS_SUPPORTED
61+
struct DirectX11Wrapper
62+
{
63+
struct DeviceEntry
64+
{
65+
ComPtr<IDXGIAdapter> dx_adapter;
66+
ComPtr<ID3D11Device> dx_device;
67+
};
68+
69+
DirectX11Wrapper();
70+
71+
std::vector<DeviceEntry> devices;
72+
};
73+
#endif
74+
75+
#if D3D10_IS_SUPPORTED
76+
struct DirectX10Wrapper
77+
{
78+
struct DeviceEntry
79+
{
80+
ComPtr<IDXGIAdapter> dx_adapter;
81+
ComPtr<ID3D10Device> dx_device;
82+
};
83+
84+
DirectX10Wrapper();
85+
86+
std::vector<DeviceEntry> devices;
87+
};
88+
#endif

0 commit comments

Comments
 (0)