Skip to content

Commit a6f198f

Browse files
committed
add device info reporting
1 parent 2da60ee commit a6f198f

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

tests/testing.cpp

+39-15
Original file line numberDiff line numberDiff line change
@@ -432,20 +432,6 @@ ComPtr<IDevice> createTestingDevice(
432432

433433
REQUIRE_CALL(getRHI()->createDevice(deviceDesc, device.writeRef()));
434434

435-
#if SLANG_RHI_DEBUG
436-
const char* features[128];
437-
uint32_t featureCount;
438-
REQUIRE_CALL(device->getFeatures(features, SLANG_COUNT_OF(features), &featureCount));
439-
std::string featureStr;
440-
for (uint32_t i = 0; i < featureCount; i++)
441-
{
442-
featureStr += features[i];
443-
if (i < featureCount - 1)
444-
featureStr += " ";
445-
}
446-
INFO("Device features: ", featureStr);
447-
#endif
448-
449435
if (useCachedDevice)
450436
{
451437
gCachedDevices[deviceType] = device;
@@ -554,9 +540,47 @@ inline bool checkDeviceTypeAvailable(DeviceType deviceType, bool verbose = true)
554540
desc.debugCallback = &sDebugCallback;
555541
#endif
556542

543+
#if SLANG_RHI_DEBUG
544+
557545
if (!SLANG_SUCCEEDED(rhi::getRHI()->createDevice(desc, device.writeRef())))
558546
RETURN_NOT_AVAILABLE("failed to create device");
559547

548+
std::string deviceInfo;
549+
deviceInfo += "Device type: ";
550+
deviceInfo += deviceTypeToString(deviceType);
551+
deviceInfo += "\n";
552+
deviceInfo += "Adapter name: ";
553+
deviceInfo += device->getInfo().adapterName;
554+
deviceInfo += "\n";
555+
{
556+
uint32_t featureCount;
557+
SLANG_RETURN_ON_FAIL(device->getFeatures(&featureCount, nullptr));
558+
std::vector<Feature> features(featureCount);
559+
SLANG_RETURN_ON_FAIL(device->getFeatures(&featureCount, features.data()));
560+
deviceInfo += "Device features:";
561+
for (uint32_t i = 0; i < featureCount; i++)
562+
{
563+
deviceInfo += " ";
564+
deviceInfo += rhi::getRHI()->getFeatureName(features[i]);
565+
}
566+
deviceInfo += "\n";
567+
}
568+
{
569+
uint32_t capabilityCount;
570+
SLANG_RETURN_ON_FAIL(device->getCapabilities(&capabilityCount, nullptr));
571+
std::vector<Capability> capabilities(capabilityCount);
572+
SLANG_RETURN_ON_FAIL(device->getCapabilities(&capabilityCount, capabilities.data()));
573+
deviceInfo += "Device capabilities:";
574+
for (uint32_t i = 0; i < capabilityCount; i++)
575+
{
576+
deviceInfo += " ";
577+
deviceInfo += rhi::getRHI()->getCapabilityName(capabilities[i]);
578+
}
579+
deviceInfo += "\n";
580+
}
581+
MESSAGE("Device info:\n", doctest::String(deviceInfo.c_str()));
582+
#endif
583+
560584
// Try compiling a trivial shader.
561585
ComPtr<slang::ISession> session = device->getSlangSession();
562586
if (!session)
@@ -660,7 +684,7 @@ bool isSwiftShaderDevice(IDevice* device)
660684
return adapterName.find("swiftshader") != std::string::npos;
661685
}
662686

663-
static slang::IGlobalSession* getSlangGlobalSession()
687+
slang::IGlobalSession* getSlangGlobalSession()
664688
{
665689
static slang::IGlobalSession* slangGlobalSession = []()
666690
{

tests/testing.h

+2
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ bool isDeviceTypeAvailable(DeviceType deviceType);
180180

181181
bool isSwiftShaderDevice(IDevice* device);
182182

183+
slang::IGlobalSession* getSlangGlobalSession();
184+
183185
const char* getTestsDir();
184186

185187
std::vector<const char*> getSlangSearchPaths();

0 commit comments

Comments
 (0)