-
Notifications
You must be signed in to change notification settings - Fork 849
[HLSL] Add GroupWaveIndex/Count execution test #8277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JoeCitizen
merged 1 commit into
microsoft:main
from
JoeCitizen:user/jackell/GroupWaveIndex_HLK
Mar 25, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| #include <array> | ||
| #include <string> | ||
| #include <map> | ||
| #include <set> | ||
| #include <unordered_set> | ||
| #include <sstream> | ||
| #include <iomanip> | ||
|
|
@@ -212,6 +213,7 @@ class ExecutionTest { | |
| TEST_METHOD(GroupSharedLimitTest); | ||
| TEST_METHOD(GroupSharedLimitASTest); | ||
| TEST_METHOD(GroupSharedLimitMSTest); | ||
| TEST_METHOD(GroupWaveIndexTest); | ||
| TEST_METHOD(PartialDerivTest); | ||
| TEST_METHOD(DerivativesTest); | ||
| TEST_METHOD(ComputeSampleTest); | ||
|
|
@@ -10931,6 +10933,210 @@ void ExecutionTest::GroupSharedLimitMSTest() { | |
| } | ||
| } | ||
|
|
||
| void ExecutionTest::GroupWaveIndexTest() { | ||
| WEX::TestExecution::SetVerifyOutput VerifySettings( | ||
| WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures); | ||
|
|
||
| BEGIN_TEST_METHOD_PROPERTIES() | ||
| TEST_METHOD_PROPERTY(L"Kits.TestId", L"c3f60f00-8e91-4acb-b4be-9f483fbe836b") | ||
| TEST_METHOD_PROPERTY( | ||
| L"Kits.Specification", | ||
| L"Device.Graphics.D3D12.DXILCore.ShaderModel610.CoreRequirement") | ||
| END_TEST_METHOD_PROPERTIES() | ||
|
|
||
| bool FailIfRequirementsNotMet = false; | ||
| #ifdef _HLK_CONF | ||
| FailIfRequirementsNotMet = true; | ||
| #endif | ||
| WEX::TestExecution::RuntimeParameters::TryGetValue( | ||
| L"FailIfRequirementsNotMet", FailIfRequirementsNotMet); | ||
|
|
||
| CComPtr<ID3D12Device> Device; | ||
| const bool SkipUnsupported = !FailIfRequirementsNotMet; | ||
| if (!createDevice(&Device, D3D_SHADER_MODEL_6_10, SkipUnsupported)) { | ||
| if (FailIfRequirementsNotMet) | ||
| LogErrorFmt(L"Device creation failed, resulting in test failure, since " | ||
| L"FailIfRequirementsNotMet is set."); | ||
| return; | ||
| } | ||
|
|
||
| // Get supported wave sizes for WaveSize attribute tests. | ||
| D3D12_FEATURE_DATA_D3D12_OPTIONS1 WaveOpts = {}; | ||
| VERIFY_SUCCEEDED( | ||
| Device->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, | ||
| &WaveOpts, sizeof(WaveOpts))); | ||
| const UINT MinWaveSize = WaveOpts.WaveLaneCountMin; | ||
| const UINT MaxWaveSize = WaveOpts.WaveLaneCountMax; | ||
|
|
||
| struct GroupWaveData { | ||
| uint32_t GroupIndex; | ||
| uint32_t WaveIndex; | ||
| uint32_t WaveCount; | ||
| uint32_t LaneIndex; | ||
| uint32_t LaneCount; | ||
| uint32_t FirstLaneGroupIndex; | ||
| }; | ||
|
|
||
| // Shader source uses defines for thread group dimensions and optional | ||
| // WaveSize attribute, injected via compiler -D options. | ||
| const char Shader[] = | ||
| R"(struct GroupWaveData { | ||
| uint GroupIndex; | ||
| uint WaveIndex; | ||
| uint WaveCount; | ||
| uint LaneIndex; | ||
| uint LaneCount; | ||
| uint FirstLaneGroupIndex; | ||
| }; | ||
| RWStructuredBuffer<GroupWaveData> Data : register(u0); | ||
|
|
||
| WAVE_SIZE_ATTR | ||
| [numthreads(NUMTHREADS_X, NUMTHREADS_Y, NUMTHREADS_Z)] | ||
| void main(uint GI : SV_GroupIndex) { | ||
| GroupWaveData D; | ||
| D.GroupIndex = GI; | ||
| D.WaveIndex = GetGroupWaveIndex(); | ||
| D.WaveCount = GetGroupWaveCount(); | ||
| D.LaneIndex = WaveGetLaneIndex(); | ||
| D.LaneCount = WaveGetLaneCount(); | ||
| D.FirstLaneGroupIndex = WaveReadLaneFirst(GI); | ||
| Data[GI] = D; | ||
| })"; | ||
|
|
||
| CComPtr<IStream> Stream; | ||
| std::shared_ptr<st::ShaderOpSet> ShaderOpSet = | ||
| std::make_shared<st::ShaderOpSet>(); | ||
| readHlslDataIntoNewStream(L"ShaderOpArith.xml", &Stream, m_support); | ||
| st::ParseShaderOpSetFromStream(Stream, ShaderOpSet.get()); | ||
|
|
||
| // Test configurations: {numthreadsX, numthreadsY, numthreadsZ, WaveSize} | ||
| // WaveSize 0 means no [WaveSize] attribute. | ||
| struct TestConfig { | ||
| UINT X, Y, Z; | ||
| UINT WaveSize; | ||
| }; | ||
|
|
||
| std::vector<TestConfig> Configs = { | ||
| {8, 1, 1, 0}, // 1D small (8 threads) | ||
| {8, 8, 1, 0}, // 2D medium (64 threads) | ||
| {16, 16, 1, 0}, // 2D large (256 threads) | ||
| {32, 32, 1, 0}, // 2D max (1024 threads) | ||
| {4, 4, 4, 0}, // 3D (64 threads) | ||
| {10, 1, 1, 0}, // 1D non-power-of-2 | ||
| }; | ||
|
|
||
| // Add WaveSize-attributed variants for each supported wave size. | ||
| for (UINT WS = MinWaveSize; WS <= MaxWaveSize; WS *= 2) { | ||
| Configs.push_back({8, 8, 1, WS}); | ||
| // Single wave case: numthreads <= WaveSize. | ||
| if (WS >= 8) | ||
| Configs.push_back({8, 1, 1, WS}); | ||
| } | ||
|
|
||
| for (const auto &Cfg : Configs) { | ||
| const UINT NumThreads = Cfg.X * Cfg.Y * Cfg.Z; | ||
| if (Cfg.WaveSize > 0) { | ||
| LogCommentFmt(L"Testing [numthreads(%u,%u,%u)] [WaveSize(%u)] " | ||
| L"(%u threads)", | ||
| Cfg.X, Cfg.Y, Cfg.Z, Cfg.WaveSize, NumThreads); | ||
| } else { | ||
| LogCommentFmt(L"Testing [numthreads(%u,%u,%u)] (%u threads)", Cfg.X, | ||
| Cfg.Y, Cfg.Z, NumThreads); | ||
| } | ||
|
|
||
| // Build compiler options with thread group defines. | ||
| char CompilerOptions[256]; | ||
| if (Cfg.WaveSize > 0) { | ||
| VERIFY_IS_TRUE( | ||
| sprintf_s(CompilerOptions, sizeof(CompilerOptions), | ||
| "-D NUMTHREADS_X=%u -D NUMTHREADS_Y=%u " | ||
| "-D NUMTHREADS_Z=%u -D WAVE_SIZE_ATTR=[wavesize(%u)]", | ||
| Cfg.X, Cfg.Y, Cfg.Z, Cfg.WaveSize) != -1); | ||
| } else { | ||
| VERIFY_IS_TRUE(sprintf_s(CompilerOptions, sizeof(CompilerOptions), | ||
| "-D NUMTHREADS_X=%u -D NUMTHREADS_Y=%u " | ||
| "-D NUMTHREADS_Z=%u -D WAVE_SIZE_ATTR=", | ||
| Cfg.X, Cfg.Y, Cfg.Z) != -1); | ||
| } | ||
|
|
||
| std::shared_ptr<st::ShaderOpTestResult> Test = | ||
| st::RunShaderOpTestAfterParse( | ||
| Device, m_support, "GroupWaveIndexTest", | ||
| [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *ShaderOp) { | ||
| VERIFY_IS_TRUE(0 == strcmp(Name, "UAVBuffer0")); | ||
| ShaderOp->Shaders.at(0).Text = Shader; | ||
| ShaderOp->Shaders.at(0).Arguments = CompilerOptions; | ||
|
|
||
| VERIFY_IS_TRUE(sizeof(GroupWaveData) * NumThreads <= Data.size()); | ||
| GroupWaveData *InData = (GroupWaveData *)Data.data(); | ||
| memset(InData, 0, sizeof(GroupWaveData) * NumThreads); | ||
|
Comment on lines
+11071
to
+11072
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is this even true? I think you decided not to do anything in response to this? |
||
| }, | ||
| ShaderOpSet); | ||
|
|
||
| MappedData DataUav; | ||
| Test->Test->GetReadBackData("UAVBuffer0", &DataUav); | ||
| VERIFY_IS_TRUE(sizeof(GroupWaveData) * NumThreads <= DataUav.size()); | ||
| const GroupWaveData *Results = (const GroupWaveData *)DataUav.data(); | ||
|
|
||
|
|
||
| // Verify WaveCount is uniform across all threads and >= 1. | ||
| const uint32_t GroupWaveCount = Results[0].WaveCount; | ||
| VERIFY_IS_GREATER_THAN_OR_EQUAL(GroupWaveCount, 1u); | ||
| for (UINT I = 0; I < NumThreads; ++I) { | ||
| VERIFY_ARE_EQUAL(Results[I].WaveCount, GroupWaveCount); | ||
| } | ||
|
|
||
| // Verify WaveCount >= ceil(threadGroupSize / LaneCount) per spec. | ||
| const uint32_t GroupLaneCount = Results[0].LaneCount; | ||
| const uint32_t MinWaves = | ||
| (NumThreads + GroupLaneCount - 1) / GroupLaneCount; | ||
| LogCommentFmt(L" waveCount=%u, laneCount=%u, minWaves=%u", GroupWaveCount, | ||
| GroupLaneCount, MinWaves); | ||
| VERIFY_IS_GREATER_THAN_OR_EQUAL(GroupWaveCount, MinWaves); | ||
|
|
||
| // If a specific WaveSize was requested, verify LaneCount matches. | ||
| if (Cfg.WaveSize > 0) { | ||
| VERIFY_ARE_EQUAL(GroupLaneCount, Cfg.WaveSize); | ||
| } | ||
|
|
||
| // Verify WaveIndex is in range [0, WaveCount). | ||
| for (UINT I = 0; I < NumThreads; ++I) { | ||
| VERIFY_IS_LESS_THAN(Results[I].WaveIndex, GroupWaveCount); | ||
| } | ||
|
|
||
| // Group threads by wave using FirstLaneGroupIndex. | ||
| std::map<uint32_t, std::vector<const GroupWaveData *>> Waves; | ||
| for (UINT I = 0; I < NumThreads; ++I) { | ||
| Waves[Results[I].FirstLaneGroupIndex].push_back(&Results[I]); | ||
| } | ||
|
|
||
| // Verify number of distinct waves matches WaveCount. | ||
| VERIFY_ARE_EQUAL(Waves.size(), static_cast<size_t>(GroupWaveCount)); | ||
|
|
||
| // Verify WaveIndex is uniform within each wave and unique across waves. | ||
| std::set<uint32_t> SeenWaveIndices; | ||
| for (auto &WavePair : Waves) { | ||
| const std::vector<const GroupWaveData *> &Lanes = WavePair.second; | ||
| VERIFY_IS_GREATER_THAN_OR_EQUAL(Lanes.size(), 1u); | ||
|
|
||
| uint32_t ExpectedWaveIndex = Lanes[0]->WaveIndex; | ||
| for (size_t J = 1; J < Lanes.size(); ++J) { | ||
| VERIFY_ARE_EQUAL(Lanes[J]->WaveIndex, ExpectedWaveIndex); | ||
| } | ||
|
|
||
| VERIFY_IS_TRUE(SeenWaveIndices.find(ExpectedWaveIndex) == | ||
| SeenWaveIndices.end()); | ||
| SeenWaveIndices.insert(ExpectedWaveIndex); | ||
| } | ||
|
|
||
| // Verify all wave indices from 0 to WaveCount-1 are present. | ||
| VERIFY_ARE_EQUAL(SeenWaveIndices.size(), | ||
| static_cast<size_t>(GroupWaveCount)); | ||
| for (uint32_t I = 0; I < GroupWaveCount; ++I) { | ||
| VERIFY_IS_TRUE(SeenWaveIndices.count(I) == 1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Atomic operation testing | ||
|
|
||
| // Atomic tests take a single integer index as input and contort it into some | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're going to need to decorate the new 6.10 test methods with an HLK requirement (Kits.Specification) and a GUID (Kits.TestId) to make these actually show up in the HLK. I alluded to that on the last PR but it would be good to make sure we at least track that.
Also, we still need to add a requirements xml to the OS for the HLK requirement to actually exist.
Heres an example of a decorated test method in the LongVector tests.
DirectXShaderCompiler/tools/clang/unittests/HLSLExec/LongVectors.cpp
Line 1820 in 21f060b
Test can have requirement and ID at the class level if all the tests in the class should map to that requirement. If we're going to add these 6.10 tests to ExecutionTests.cpp then we'll either want to do the per test method option or add in a sub test class for them.
The GUID is the thing that the HLK infra will use for 'registering' the test and executing it. So, if a GUID were to say map to a test class then those tests would be deployed on a sing machine to run in the HLK environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming we want these in the HLK :)