Skip to content

Commit 26fb244

Browse files
committed
Show adapter info in slang-test
When -show-adapter-info is provided to slang-test, there is a subsequent pass over all available APIs to ask render-api to show which adapter will be used. > .\slang-test.exe -show-adapter-info Supported backends: fxc dxc glslang spirv-dis clang visualstudio genericcpp nvrtc llvm spirv-opt tint Check vk,vulkan: Supported Check dx12,d3d12: Supported Check dx11,d3d11: Supported Check cuda: Supported Check wgpu,webgpu: Supported Adapter Information for Available APIs: vk,vulkan: Using graphics adapter: NVIDIA RTX A3000 Laptop GPU dx12,d3d12: Using graphics adapter: NVIDIA RTX A3000 Laptop GPU dx11,d3d11: Using graphics adapter: Intel(R) UHD Graphics cpu: cuda: wgpu,webgpu: Using graphics adapter: default passed test: 'tests/autodiff/arithmetic-jvp.slang (dx11)' ... closes shader-slang#5600
1 parent a70113c commit 26fb244

File tree

6 files changed

+62
-0
lines changed

6 files changed

+62
-0
lines changed

tools/render-test/options.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ static rhi::DeviceType _toRenderType(Slang::RenderApiType apiType)
257257
{
258258
outOptions.dx12Experimental = true;
259259
}
260+
else if (argValue == "-show-adapter-info")
261+
{
262+
outOptions.showAdapterInfo = true;
263+
}
260264
else
261265
{
262266
// Lookup

tools/render-test/options.h

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ struct Options
9191

9292
bool dx12Experimental = false;
9393

94+
bool showAdapterInfo = false;
95+
9496
Options() { downstreamArgs.addName("slang"); }
9597

9698
static SlangResult parse(

tools/render-test/render-test-main.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,14 @@ static SlangResult _innerMain(
14651465
}
14661466
}
14671467

1468+
// Print adapter info after device creation but before any other operations
1469+
if (options.showAdapterInfo)
1470+
{
1471+
auto info = device->getDeviceInfo();
1472+
auto& out = stdWriters->getOut();
1473+
out.print("Using graphics adapter: %s\n", info.adapterName);
1474+
}
1475+
14681476
// If the only test is we can startup, then we are done
14691477
if (options.onlyStartup)
14701478
{

tools/slang-test/options.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ static bool _isSubCommand(const char* arg)
336336
}
337337
optionsOut->testDir = *argCursor++;
338338
}
339+
else if (strcmp(arg, "-show-adapter-info") == 0)
340+
{
341+
optionsOut->showAdapterInfo = true;
342+
}
339343
else
340344
{
341345
stdError.print("unknown option '%s'\n", arg);

tools/slang-test/options.h

+3
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ struct Options
115115
// The adapter to use. If empty will match first found adapter.
116116
Slang::String adapter;
117117

118+
// If true, print detailed adapter information
119+
bool showAdapterInfo = false;
120+
118121
// Maximum number of test servers to run.
119122
int serverCount = 1;
120123

tools/slang-test/slang-test-main.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,47 @@ static RenderApiFlags _getAvailableRenderApiFlags(TestContext* context)
13911391
}
13921392
}
13931393

1394+
// After determining available APIs, print adapter info for each one
1395+
if (context->options.showAdapterInfo && availableRenderApiFlags)
1396+
{
1397+
StdWriters::getOut().print("\nAdapter Information for Available APIs:\n");
1398+
for (int i = 0; i < int(RenderApiType::CountOf); ++i)
1399+
{
1400+
const RenderApiType apiType = RenderApiType(i);
1401+
const RenderApiFlags apiFlag = RenderApiFlags(1) << int(apiType);
1402+
1403+
if (availableRenderApiFlags & apiFlag)
1404+
{
1405+
// Create command line to query adapter info
1406+
CommandLine cmdLine;
1407+
cmdLine.setExecutableLocation(
1408+
ExecutableLocation(context->options.binDir, "render-test"));
1409+
1410+
// Add the API type
1411+
StringBuilder builder;
1412+
builder << "-" << RenderApiUtil::getApiName(apiType);
1413+
cmdLine.addArg(builder);
1414+
1415+
// Add flags to show adapter info and only startup
1416+
cmdLine.addArg("-show-adapter-info");
1417+
cmdLine.addArg("-only-startup");
1418+
1419+
// Run render-test to get adapter info
1420+
ExecuteResult exeRes;
1421+
if (SLANG_SUCCEEDED(
1422+
spawnAndWaitSharedLibrary(context, "adapter-info", cmdLine, exeRes)))
1423+
{
1424+
// Output the adapter info
1425+
StdWriters::getOut().print(
1426+
"\n%s:\n%s",
1427+
RenderApiUtil::getApiName(apiType).begin(),
1428+
exeRes.standardOutput.getBuffer());
1429+
}
1430+
}
1431+
}
1432+
StdWriters::getOut().print("\n");
1433+
}
1434+
13941435
context->availableRenderApiFlags = availableRenderApiFlags;
13951436
context->isAvailableRenderApiFlagsValid = true;
13961437
}

0 commit comments

Comments
 (0)