Skip to content

Commit f1b110f

Browse files
Change setup of virtual device support (o3de#17640)
Signed-off-by: Martin Winter <[email protected]>
1 parent 432e544 commit f1b110f

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

Gems/Atom/RHI/Code/Include/Atom/RHI/RHISystem.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ namespace AZ::RHI
3838
, public RHIMemoryStatisticsInterface
3939
{
4040
public:
41-
//! This function just initializes the native device and RHI::Device as a result.
42-
//! We can use this device to then query for device capabilities.
43-
ResultCode InitDevices(InitDevicesFlags initializationVariant = InitDevicesFlags::SingleDevice);
41+
//! This function just initializes the native devices and RHI::Device as a result.
42+
//! We can use these devices to then query for device capabilities.
43+
ResultCode InitDevices(int deviceCount = 1);
4444

4545
//! This function initializes the rest of the RHI/RHI backend.
4646
//! bindlessSrgLayout in this case is layout associated with the bindless srg (Bindless.azsli).
@@ -97,7 +97,7 @@ namespace AZ::RHI
9797
private:
9898

9999
//! Enumerates the Physical devices and picks one (or multiple) to be used to initialize the RHI::Device(s) with
100-
ResultCode InitInternalDevices(InitDevicesFlags initializationVariant);
100+
ResultCode InitInternalDevices(int deviceCount);
101101

102102
AZStd::vector<DrawListTag> m_drawListTagsDisabledByDefault;
103103
AZStd::vector<RHI::Ptr<RHI::Device>> m_devices;

Gems/Atom/RHI/Code/Source/RHI/RHISystem.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ namespace AZ::RHI
3535
return Interface<RHIMemoryStatisticsInterface>::Get();
3636
}
3737

38-
ResultCode RHISystem::InitDevices(InitDevicesFlags initializationVariant)
38+
ResultCode RHISystem::InitDevices(int deviceCount)
3939
{
4040
Interface<RHISystemInterface>::Register(this);
4141
Interface<RHIMemoryStatisticsInterface>::Register(this);
42-
return InitInternalDevices(initializationVariant);
42+
return InitInternalDevices(deviceCount);
4343
}
4444

4545
void RHISystem::Init(RHI::Ptr<RHI::ShaderResourceGroupLayout> bindlessSrgLayout)
@@ -100,7 +100,7 @@ namespace AZ::RHI
100100
RHISystemNotificationBus::Broadcast(&RHISystemNotificationBus::Events::OnRHISystemInitialized);
101101
}
102102

103-
ResultCode RHISystem::InitInternalDevices(InitDevicesFlags initializationVariant)
103+
ResultCode RHISystem::InitInternalDevices(int deviceCount)
104104
{
105105
RHI::PhysicalDeviceList physicalDevices = RHI::Factory::Get().EnumeratePhysicalDevices();
106106

@@ -114,7 +114,7 @@ namespace AZ::RHI
114114

115115
RHI::PhysicalDeviceList usePhysicalDevices;
116116

117-
if (initializationVariant == InitDevicesFlags::MultiDevice)
117+
if (deviceCount > 1)
118118
{
119119
AZ_Printf("RHISystem", "\tUsing multiple devices\n");
120120

@@ -197,6 +197,14 @@ namespace AZ::RHI
197197
}
198198
}
199199

200+
for (auto index{ 0 }; m_devices.size() < deviceCount; index++)
201+
{
202+
// We do not have enough physical devices for the requested device count
203+
// Virtualize the existing devices up to the required number
204+
auto deviceIndex{ AddVirtualDevice(m_devices[index]->GetDeviceIndex()) };
205+
AZ_Printf("RHISystem", "\tVirtualized device %d from device %d\n", deviceIndex.value(), m_devices[index]->GetDeviceIndex());
206+
}
207+
200208
if (m_devices.empty())
201209
{
202210
AZ_Error("RHISystem", false, "Failed to initialize RHI device.");

Gems/Atom/RHI/Code/Tests/DrawPacketTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ namespace UnitTest
178178
m_drawListTagRegistry = RHI::DrawListTagRegistry::Create();
179179

180180
m_rhiSystem.reset(aznew AZ::RHI::RHISystem);
181-
m_rhiSystem->InitDevices(AZ::RHI::InitDevicesFlags::SingleDevice);
181+
m_rhiSystem->InitDevices();
182182
m_rhiSystem->Init();
183183
}
184184

Gems/Atom/RHI/Code/Tests/RHITestFixture.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <Atom/RHI.Reflect/Base.h>
2424
#include <Atom/RHI/RHISystem.h>
25+
#include <Tests/Device.h>
2526
#include <Tests/Factory.h>
2627

2728
namespace UnitTest
@@ -71,7 +72,7 @@ namespace UnitTest
7172

7273
m_rhiSystem.reset(aznew AZ::RHI::RHISystem);
7374

74-
m_rhiSystem->InitDevices(AZ::RHI::InitDevicesFlags::MultiDevice);
75+
m_rhiSystem->InitDevices(DeviceCount);
7576
m_rhiSystem->Init();
7677
}
7778

Gems/Atom/RPI/Code/Source/RPI.Public/RPISystem.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ namespace AZ
8181
void RPISystem::Initialize(const RPISystemDescriptor& rpiSystemDescriptor)
8282
{
8383
// Init RHI device(s)
84-
m_rhiSystem.InitDevices(AzFramework::StringFunc::Equal(RHI::GetCommandLineValue("enableMultipleDevices").c_str(), "enable") ? RHI::InitDevicesFlags::MultiDevice : RHI::InitDevicesFlags::SingleDevice);
84+
auto commandLineMultipleDevicesValue{ RHI::GetCommandLineValue("device-count") };
85+
m_rhiSystem.InitDevices((commandLineMultipleDevicesValue != "") ? AZStd::stoi(commandLineMultipleDevicesValue) : 1);
8586

8687
// Gather asset handlers from sub-systems.
8788
ImageSystem::GetAssetHandlers(m_assetHandlers);

0 commit comments

Comments
 (0)