Skip to content

[SM6.10][Exec][Bugfix] Add matrix layout conversion helpers, add post-dispatch callback, and re-enable OuterProduct test#8606

Open
Icohedron wants to merge 7 commits into
microsoft:mainfrom
Icohedron:matrix-layout-conversion
Open

[SM6.10][Exec][Bugfix] Add matrix layout conversion helpers, add post-dispatch callback, and re-enable OuterProduct test#8606
Icohedron wants to merge 7 commits into
microsoft:mainfrom
Icohedron:matrix-layout-conversion

Conversation

@Icohedron

@Icohedron Icohedron commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Addresses the matrix layout conversion requirement of issue #8386

This PR re-enables the OuterProduct smoke test and adds support for matrix layout conversions via new dedicated helper functions in HLSLExecTestUtils.h/.cpp and a new post-dispatch command list callback in ShaderOpTest.h/.cpp.

  • New helper functions getLinAlgMatrixByteSize, recordLinAlgMatrixConversion, and toLinAlgDataType for querying matrix byte sizes, recording a matrix layout conversion operation to a command list, and converting DXIL component type enums into D3D12 LinAlg datatype enums
  • A new post-dispatch callback is introduced for allowing tests to record commands that run after a dispatch. This is used to record a ConvertLinearAlgebraMatrix to the command list immediately after the dispatch
  • Re-enable the OuterProduct smoke test with changes made to use the outer-product-optimal layout and uses the new helpers and callback to convert the output back into row-major order for validation

Assisted by: Claude Opus 4.8

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

✅ With the latest revision this PR passed the C/C++ code formatter.

Comment thread tools/clang/unittests/HLSLExec/HlslExecTestUtils.h Outdated
Args.c_str());
addUAVBuffer(Op.get(), "Input", InBuffSize, false, "byname");
addUAVBuffer(Op.get(), "Output", OutBufferSize, true);
addUAVBuffer(Op.get(), "Output", OutBufferSize, /*ReadBack=*/false);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm wrong, but I see you using GetResource on the "Output" buffer, in the code below. Doesn't that mean that this ReadBack bool should remain true?

@Icohedron Icohedron Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Output" buffer is not being read by the CPU, so the ReadBack bool is false. The "Output" buffer is also in the opaque outer-product-optimal layout, so we shouldn't even try to interpret it without first converting it to a layout we do know how to read.

The GetResource just obtains a handle to be able to refer to the "Output" buffer so that we can record a ConvertLinearAlgebraMatrix command into the command list to tell the GPU to convert it into row-major order and store it into "OutputRowMajor", which the CPU does read back.

@Icohedron

Icohedron commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

Discussed offline with @damyanp.

I removed the dedicated post-execute command list+queue and replaced it with a post-dispatch callback for recording commands immediately after the dispatch command in compute command lists.

I will need to clarify with @jenatali if it is intentional for ConvertLinearAlgebraMatrix to not be able to be recorded into compute command lists due to a runtime error. Currently, recording an ID3D12GraphicsCommandListPreview::ConvertLinearAlgebraMatrix into a compute command list (D3D12_COMMAND_LIST_TYPE_COMPUTE) causes the command list's Close() to fail with E_FAIL (0x80004005).

So as of this PR's current state, the test will fail with:

StartGroup: LinAlg::DxilConf_SM610_LinAlg::OuterProduct_Thread_16x16_F16
Compiling with flags: -T cs_6_10 -E main -HV 202x -DCOMP_TYPE=8 -DM_DIM=16 -DN_DIM=16 -DUSE=0 -DSCOPE=0 -DSTRIDE=0 -DLAYOUT=4 -DELEM_SIZE=2 -DNUMTHREADS=1 -DELEM_TYPE=half -enable-16bit-types
Compiling shader:
        Target profile: cs_6_10
        Arguments: -HV 202x -DCOMP_TYPE=8 -DM_DIM=16 -DN_DIM=16 -DUSE=0 -DSCOPE=0 -DSTRIDE=0 -DLAYOUT=4 -DELEM_SIZE=2 -DNUMTHREADS=1 -DELEM_TYPE=half -enable-16bit-types
Error: Verify: SUCCEEDED(pList->Close()) - Value (0x80004005) [File: C:\workspace\hlsl-win-dev\DirectXShaderCompiler\tools\clang\unittests\HLSLExec\ShaderOpTest.cpp, Function: st::ShaderOpTest::RunCommandList, Line: 1070]
EndGroup: LinAlg::DxilConf_SM610_LinAlg::OuterProduct_Thread_16x16_F16 [Failed]

A workaround is changing the compute list and queue into a direct list and queue, but I will leave it as compute for now.

@jenatali

jenatali commented Jul 8, 2026

Copy link
Copy Markdown
Member

Definitely not intentional, that traces back to the cooperative vector prototype 1.5 years ago. I'll get that fixed.

@Icohedron

Copy link
Copy Markdown
Collaborator Author

Definitely not intentional, that traces back to the cooperative vector prototype 1.5 years ago. I'll get that fixed.

Thanks!

@Icohedron Icohedron changed the title [SM6.10][Exec][Bugfix] Add matrix layout conversion helpers, post-execute command list callback, and re-enable OuterProduct test [SM6.10][Exec][Bugfix] Add matrix layout conversion helpers, add post-dispatch callback, and re-enable OuterProduct test Jul 8, 2026
Params.Enable16Bit = true;
runOuterProduct(D3DDevice, DxcSupport, Params, VerboseLogging);
#else
WEX::Logging::Log::Comment(

@V-FEXrt V-FEXrt Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it sometimes required to compile out this test?

@Icohedron Icohedron Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test requires compiling against the preview Agility SDK whose headers provide the linear algebra matrix conversion APIs. Without it, the matrix can not be converted and therefore the output can not be validated.

L"without the linear-algebra matrix-conversion API "
L"(DIRECT3D_LINEAR_ALGEBRA undefined); the host-side conversion helpers "
L"are compiled out.");
WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void ShaderOpTest::GetResource(LPCSTR pResourceName,
ID3D12Resource **ppResource) {
pResourceName = m_pShaderOp->Strings.insert(pResourceName); // Unique
auto It = m_ResourceData.find(pResourceName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should swap to use .at like GetReadBack data so the test throws instead of crashing for a name that doesn't exist (programmer error).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

[SM6.10] LinAlg Exec Tests need to support Matrix Layout Conversion

5 participants