Skip to content

Commit d9b92cc

Browse files
Validate -render-features in render-test (#8940)
# Main Changes Add validation for `-render-feature` and `-render-features` flags against `SLANG_RHI_FEATURES`. Invalid feature names now fail immediately during option parsing with clear error messages. **Implementation:** * Add `isValidFeatureName()` helper function using `SLANG_RHI_FEATURES` macro * Add workaround (WAR) to accept `cooperative-matrix-*` patterns until RHI backend supports them * Emit warning when WAR is triggered * Add diagnostic error 1006 for invalid render features Fixes #8274 # Test Fixes **Fixed capability misuse:** * Changed `cuda_sm_7_0` from `-render-feature` to `-capability` in wave operation tests (5 files) # Cooperative-Matrix WAR Tests use cooperative-matrix-2 sub-features (e.g., `cooperative-matrix-reductions`, `cooperative-matrix-tensor-addressing`) not yet in `SLANG_RHI_FEATURES`. **Solution:** WAR accepts `cooperative-matrix-*` patterns, allowing: * Tests remain enabled and skip gracefully on unsupported hardware * No CI failures (Tesla T4 lacks cooperative-matrix-2) * Auto-enable when RHI backend implements `VK_NV_cooperative_matrix2` # Code Cleanup * Fixed include order and removed unused includes from `options.cpp` # Testing * Invalid features caught with clear errors * Cooperative-matrix tests skip gracefully on unsupported hardware
1 parent 0f4d0f6 commit d9b92cc

File tree

7 files changed

+58
-14
lines changed

7 files changed

+58
-14
lines changed

tests/hlsl-intrinsic/active-mask/switch-trivial-fallthrough.slang

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// target because we do not synthesize the active
2323
// mask value we want/expect to see.
2424
//
25-
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -render-features cuda_sm_7_0
25+
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -capability cuda_sm_7_0
2626

2727
//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name buffer
2828
RWStructuredBuffer<int> buffer;

tests/hlsl-intrinsic/active-mask/switch.slang

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
77
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile cs_6_0 -xslang -DHACK -shaderobj
88
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -xslang -DHACK -shaderobj
9-
//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -render-features cuda_sm_7_0
9+
//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -capability cuda_sm_7_0
1010

1111
//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name buffer
1212
RWStructuredBuffer<int> buffer;

tests/hlsl-intrinsic/wave-active-count-bits.slang

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//TEST:COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile cs_6_0 -shaderobj -render-feature hardware-device
55
//TEST:COMPARE_COMPUTE_EX:-slang -compute -cuda -profile cs_6_0 -shaderobj -render-feature hardware-device
66
//TEST(vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -render-feature hardware-device
7-
//TEST:COMPARE_COMPUTE_EX:-cuda -compute -render-features cuda_sm_7_0 -shaderobj
7+
//TEST:COMPARE_COMPUTE_EX:-cuda -compute -capability cuda_sm_7_0 -shaderobj
88
//TEST:COMPARE_COMPUTE_EX:-metal -compute -shaderobj
99

1010
//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer

tests/hlsl-intrinsic/wave-broadcast-lane-at.slang

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
TEST:COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile cs_6_0 -shaderobj
55
// Disabled on VK because glsl can't do WaveReadLaneAt on matrix.
66
//DISABLE_TEST(vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj
7-
TEST:COMPARE_COMPUTE_EX:-cuda -compute -render-features cuda_sm_7_0 -shaderobj
7+
TEST:COMPARE_COMPUTE_EX:-cuda -compute -capability cuda_sm_7_0 -shaderobj
88

99
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
1010
RWStructuredBuffer<int> outputBuffer;

tests/hlsl-intrinsic/wave-shuffle.slang

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//DISABLE_TEST:COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile cs_6_0
66
// Disabled because vk doesn't currently support matrix types. See wave-shuffle-vk.slang
77
//DISABLE_TEST(vulkan):COMPARE_COMPUTE_EX:-vk -compute
8-
TEST:COMPARE_COMPUTE_EX:-cuda -compute -render-features cuda_sm_7_0
8+
TEST:COMPARE_COMPUTE_EX:-cuda -compute -capability cuda_sm_7_0
99

1010
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
1111
RWStructuredBuffer<int> outputBuffer;

tools/render-test/diagnostic-defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ DIAGNOSTIC(1003, Error, unknownSourceLanguage, "unknown source language name")
3737
DIAGNOSTIC(1003, Error, unknown, "unknown source language name")
3838
DIAGNOSTIC(1004, Error, unknownCommandLineOption, "unknown command-line option '$0'")
3939
DIAGNOSTIC(1005, Error, unexpectedPositionalArg, "unexpected positional arg")
40+
DIAGNOSTIC(1006, Error, invalidRenderFeature, "invalid render feature name '$0'")
4041

4142
#undef DIAGNOSTIC

tools/render-test/options.cpp

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,58 @@
22

33
#include "options.h"
44

5+
#include "../../source/compiler-core/slang-command-line-args.h"
56
#include "../../source/core/slang-list.h"
67
#include "../../source/core/slang-render-api-util.h"
78
#include "../../source/core/slang-string-util.h"
9+
#include "../../source/core/slang-type-text-util.h"
810
#include "../../source/core/slang-writer.h"
11+
#include "diagnostics.h"
912

1013
#include <stdio.h>
1114
#include <stdlib.h>
12-
#include <string.h>
13-
// #include "../../source/core/slang-downstream-compiler.h"
14-
15-
#include "../../source/compiler-core/slang-command-line-args.h"
16-
#include "../../source/core/slang-type-text-util.h"
17-
#include "diagnostics.h"
1815

1916
namespace renderer_test
2017
{
2118
using namespace Slang;
2219

20+
// Helper function to check if a feature name is valid
21+
static bool isValidFeatureName(
22+
const UnownedStringSlice& featureName,
23+
DiagnosticSink* sink,
24+
SourceLoc loc)
25+
{
26+
// WAR: Accept cooperative-matrix-2 sub-features until RHI backend supports them
27+
// These features will be gracefully skipped at runtime if hardware doesn't support them
28+
if (featureName.startsWith("cooperative-matrix-"))
29+
{
30+
if (sink)
31+
{
32+
sink->diagnoseRaw(
33+
Severity::Warning,
34+
"Using cooperative-matrix-2 feature that is not yet fully supported "
35+
"in RHI backend. "
36+
"Test will be skipped if hardware doesn't support it.");
37+
}
38+
return true;
39+
}
40+
41+
#define SLANG_RHI_FEATURES_X(id, name) name,
42+
static const char* kValidFeatureNames[] = {SLANG_RHI_FEATURES(SLANG_RHI_FEATURES_X)};
43+
#undef SLANG_RHI_FEATURES_X
44+
45+
static const int kFeatureCount = sizeof(kValidFeatureNames) / sizeof(kValidFeatureNames[0]);
46+
47+
for (int i = 0; i < kFeatureCount; i++)
48+
{
49+
if (featureName == UnownedStringSlice(kValidFeatureNames[i]))
50+
{
51+
return true;
52+
}
53+
}
54+
return false;
55+
}
56+
2357
static rhi::DeviceType _toRenderType(Slang::RenderApiType apiType)
2458
{
2559
using namespace Slang;
@@ -111,14 +145,23 @@ static rhi::DeviceType _toRenderType(Slang::RenderApiType apiType)
111145
}
112146
else if (argValue == "-render-features" || argValue == "-render-feature")
113147
{
114-
String features;
115-
SLANG_RETURN_ON_FAIL(reader.expectArg(features));
148+
CommandLineArg featuresArg;
149+
SLANG_RETURN_ON_FAIL(reader.expectArg(featuresArg));
116150

117151
List<UnownedStringSlice> values;
118-
StringUtil::split(features.getUnownedSlice(), ',', values);
152+
StringUtil::split(featuresArg.value.getUnownedSlice(), ',', values);
119153

120154
for (const auto& value : values)
121155
{
156+
// Validate that the feature name is recognized
157+
if (!isValidFeatureName(value, &sink, featuresArg.loc))
158+
{
159+
sink.diagnose(
160+
featuresArg.loc,
161+
RenderTestDiagnostics::invalidRenderFeature,
162+
value);
163+
return SLANG_FAIL;
164+
}
122165
outOptions.renderFeatures.add(value);
123166
}
124167
}

0 commit comments

Comments
 (0)