Skip to content
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

[Error Handling] Fix DxcContainerBuilder error handling #7056

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

bob80905
Copy link
Collaborator

Some error handling changes were incorrectly made to the container assembler, as described in the issue below.
This is bad because the API protocol for error handling must remain consistent across all functions. This PR
aims to restore the correct semantic meaning of returning bad HR values.
Fixes #7051

@bob80905 bob80905 requested a review from a team as a code owner January 11, 2025 00:51
Copy link
Contributor

@tex3d tex3d left a comment

Choose a reason for hiding this comment

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

If this succeeded testing without the suggested change to check valHR before hashing, we are missing a test that makes sure it doesn't hash the shader even when validation fails.

lib/DxilContainer/DxcContainerBuilder.cpp Outdated Show resolved Hide resolved
lib/DxilContainer/DxcContainerBuilder.cpp Outdated Show resolved Hide resolved
@bob80905 bob80905 self-assigned this Jan 16, 2025
Copy link
Contributor

github-actions bot commented Jan 17, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 070d0d5a2beacef9eeb51037a9b04665716fd6f3 9194c5300d03c3163779108d8d27c86dce6afd4b -- lib/DxilContainer/DxcContainerBuilder.cpp tools/clang/tools/dxclib/dxc.cpp tools/clang/unittests/HLSL/ValidationTest.cpp
View the diff from clang-format here.
diff --git a/tools/clang/unittests/HLSL/ValidationTest.cpp b/tools/clang/unittests/HLSL/ValidationTest.cpp
index cb2a5ce28..e7d3bfaeb 100644
--- a/tools/clang/unittests/HLSL/ValidationTest.cpp
+++ b/tools/clang/unittests/HLSL/ValidationTest.cpp
@@ -1228,7 +1228,7 @@ TEST_F(ValidationTest, ValidationFailNoHash) {
   VERIFY_IS_NOT_NULL(pHeader);
 
   BYTE ZeroHash[DxilContainerHashSize] = {0, 0, 0, 0, 0, 0, 0, 0,
-                                        0, 0, 0, 0, 0, 0, 0, 0};
+                                          0, 0, 0, 0, 0, 0, 0, 0};
 
   // Should be equal, this proves the hash isn't written when validation fails
   VERIFY_ARE_EQUAL(memcmp(ZeroHash, pHeader->Hash.Digest, sizeof(ZeroHash)), 0);
  • Check this box to apply formatting changes to this branch.

return;
CComPtr<IDxcBlob> pProgram;

// we need any shader that will pass compilation but fail validation
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: the comment could say why the shader is expected to fail validation, otherwise it might not be obvious. That was the initial issue that tripped me up when reading the test code.

I still would have preferred we assembled IR instead of compiled HLSL, since that's what we should be using in validation tests.

Suggested change
// we need any shader that will pass compilation but fail validation
// We need any shader that will pass compilation but fail validation.
// This shader reads from uninitialized 'float a', which works for now.

pProgram->GetBufferPointer(), pProgram->GetBufferSize());
VERIFY_IS_NOT_NULL(pHeader);

BYTE Result[DxilContainerHashSize] = {0, 0, 0, 0, 0, 0, 0, 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think Result should be renamed to be clear that it's zeros, like ZeroHash. That way if you had a failure in the VERIFY macro, you would see that it's comparing with ZeroHash and understand what was expected without having to read this source code.

BYTE Result[DxilContainerHashSize] = {0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0};
// ComputeHashRetail(DataToHash, AmountToHash, Result);
// Should be unequal, this proves the hash isn't written when validation fails
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Comment out of date.

Suggested change
// Should be unequal, this proves the hash isn't written when validation fails
// Should be equal, this proves the hash isn't written when validation fails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

Regression in ContainerBuilder error handling code introduced by #6853
2 participants