-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[DirectX] Adding missing descriptor table validations #153276
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
Changes from 164 commits
0e8828c
2edd215
242545e
3f8dec4
3b1ce3b
f5720af
ea54904
a49aa19
d90676f
a04eb9f
5994b8f
e8b14bf
8f40e83
28350b2
4fd2e0b
e25ee87
01a558b
881dd36
8779ee9
43eb04e
c16f15b
f67bec1
d7b4cf4
c7d5be7
cc5afae
571a0ef
974d4bc
403b546
aea75da
e0bc862
b5a0b32
00a74af
5ccb842
5423aba
a7637a7
da42c0c
5af9199
46294cb
91ff1bf
edb015d
5f8bbeb
9f3888e
8459d14
578a03b
34deb3a
b4a0e16
49f3bf2
ef14638
662c3a8
848501d
8d97116
9c34f3f
24040a0
2c30cd9
260633c
d42f156
9ee3a4b
6db6224
04658b8
adf3feb
c95ce68
af6aa53
29eb893
ed4c553
28fb609
fc338b5
f5b5b3e
03d571a
76048d4
7c9bd62
ef51048
21675e6
849ff86
7a1bc21
403972d
0f0435d
e841a98
ae6d67a
41f32bd
47662f0
6da5fb0
108a7d5
6f3d019
971ad57
db73d71
3b04c2d
1ddffc3
1c10acf
50e78d2
aee4c56
7d1c13e
85719af
cc304fd
3c28142
81261ff
db0008e
0c72dcf
b4e5fb4
e5e73fe
ad0e1f3
d97eb7c
8a4ee3c
4a655a5
cc94561
98f48d2
eb334b8
06c0da4
d58606f
74980c8
23537b5
d376abf
4abb40d
bb44eef
1cf2d1e
373d871
d2750d7
777d544
19e9baa
708c4dc
a163d1b
4f120cc
def929f
d3349ce
bf5714d
7cf513f
fe24637
6db8d93
e3a65b6
e902add
9a6d64c
15b7592
11b9fb2
0b8a997
34619da
84d4579
d2b4aea
e2ba167
b395a47
17b425d
f9c4b9c
c7cedb4
bf9b30c
18e4c3d
567bd15
42518b2
f6abbf7
2971f5f
f0ed242
a6a9fe9
3f83308
8daa97b
79f1f48
3d10d92
f596ad5
55c2b96
d1c31f1
75d74ed
fbf6776
5f429d2
5633433
ec10db8
b42630a
bce1ef9
cf84fcf
e5976ee
eb84e14
6a3c2ab
1327b74
c2d39ed
592dc62
f3253ed
d442625
f785d25
eefd22c
0c508d8
b188df1
dabb9cd
0e08cea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -27,6 +27,11 @@ namespace rootsig { | |||||
char GenericRSMetadataError::ID; | ||||||
char InvalidRSMetadataFormat::ID; | ||||||
char InvalidRSMetadataValue::ID; | ||||||
char TableSamplerMixinError::ID; | ||||||
char ShaderRegisterOverflowError::ID; | ||||||
char OffsetOverflowError::ID; | ||||||
char DescriptorRangeOverflowError::ID; | ||||||
|
||||||
template <typename T> char RootSignatureValidationError<T>::ID; | ||||||
|
||||||
static std::optional<uint32_t> extractMdIntValue(MDNode *Node, | ||||||
|
@@ -63,6 +68,14 @@ extractShaderVisibility(MDNode *Node, unsigned int OpId) { | |||||
return make_error<InvalidRSMetadataValue>("ShaderVisibility"); | ||||||
} | ||||||
|
||||||
static uint64_t updateOngoingOffset(uint64_t CurOfset, uint64_t NumDescriptors, | ||||||
|
static uint64_t updateOngoingOffset(uint64_t CurOfset, uint64_t NumDescriptors, | |
static uint64_t updateOngoingOffset(uint64_t CurOffset, uint64_t NumDescriptors, |
Is this function required? I think we could just use the OffsetBound
below in the same way as the front-end? Or we can make the function shared?
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 moved this function to a common place and updated the frontend to use it. I wasn't able to get the correct behaviour by copying frontend's update function. The test rootsignature-validation-fail-appending-overflow.ll
, was failing with it.
If you have something you would like me to try, please let me know.
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 a bit concerned that the change to the frontend to use this function doesn't also include a test change - the frontend's original logic was simple saturation, and this behaviour is not the same as that. Are we missing test coverage in the frontend that would show this fixing a bug?
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 think the frontend has all tests covered. I spent sometime checking for equivalent errors for the tests I've added, here are the mappings I've found:
llvm/test/CodeGen/DirectX/rootsignature-validation-fail-appending-overflow.ll
=RootSignature-resource-ranges-err.hlsl#append_to_unbound_signature
llvm/test/CodeGen/DirectX/rootsignature-validation-fail-offset-overflow.ll
=RootSignature-resource-ranges-err.hlsl#direct_offset_overflow_signature
llvm/test/CodeGen/DirectX/rootsignature-validation-fail-register-overflow.ll
=RootSignature-err.hlsl#basic_validation_0
llvm/test/CodeGen/DirectX/rootsignature-validation-fail-sampler-mix.ll
=RootSignature-resource-ranges-err.hlsl#mixed_resource_table
@inbelic, let me know if you think otherwise.
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 think we should do it more like this: #153276 (comment).
To Justin's point though, I think we are missing a test-case for something like:
DescriptorTable(
CBV(u0, offset = 2^32 - 3), numDescriptors = 4), // Overflows
CBV(u1) // Appending to overflow
)
which would only report the first overflow and not the second because the offset will be truncated to 1 when converted to a uint32_t
, when using updateOngoingOffset
. It should report both when using the original frontend method.
Outdated
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.
This cast does nothing - Range.RangeType
is a dxil::ResourceClass
.
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.
This check is being added here for 2 reasons: 1) The equivalent implementation of this function in the frontend makes this check, so I wanna make sure we have the same assumptions when running this logic; 2) There are tests that require Range.NumDescriptors
to be 0, those test check other parts of the code, since this code is accumulating multiple errors, this check needs to be here to avoid breaking such tests.
I am open to review it, if you have a better approach.
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.
The continue
is probably fine here for the reasons you describe, but why are we checking <= 0
? Since NumDescriptors
is unsigned, wouldn't checking == 0
make more sense?
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.
True, missed that. Thanks
Outdated
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.
Another no-op cast
inbelic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
joaosaffran marked this conversation as resolved.
Show resolved
Hide resolved
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,8 +11,9 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" } | |||||
|
||||||
!dx.rootsignatures = !{!2} ; list of function/root signature pairs | ||||||
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature | ||||||
!3 = !{ !5 } ; list of root signature elements | ||||||
!5 = !{ !"DescriptorTable", i32 0, !6, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20 } | ||||||
!3 = !{ !5, !21 } ; list of root signature elements | ||||||
!5 = !{ !"DescriptorTable", i32 0, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20 } | ||||||
!21 = !{ !"DescriptorTable", i32 0,!6, !8, !9 } | ||||||
|
!21 = !{ !"DescriptorTable", i32 0,!6, !8, !9 } | |
!21 = !{ !"DescriptorTable", i32 0, !6, !8, !9 } |
inbelic marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
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.
Those are all samplers, they are being moved to bellow
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||
; RUN: not opt -S -passes='dxil-post-optimization-validation' -mtriple=dxil-pc-shadermodel6.6-compute %s 2>&1 | FileCheck %s | ||||||
; This test check if a resource is implicitly overflowing. That means, it is appending a resource after an unbounded range. | ||||||
|
; This test check if a resource is implicitly overflowing. That means, it is appending a resource after an unbounded range. | |
; This test checks if a resource is implicitly overflowing. That means, it is appending a resource after an unbounded range. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; RUN: not opt -S -passes='dxil-post-optimization-validation' -mtriple=dxil-pc-shadermodel6.6-compute %s 2>&1 | FileCheck %s | ||
; CHECK: error: Overflow for descriptor range: UAV(register=0, space=0) | ||
|
||
define void @CSMain() "hlsl.shader"="compute" { | ||
entry: | ||
ret void | ||
} | ||
|
||
!dx.rootsignatures = !{!0} | ||
|
||
!0 = !{ptr @CSMain, !1, i32 2} | ||
!1 = !{!3} | ||
!3 = !{!"DescriptorTable", i32 0, !4, !5} | ||
!4 = !{!"UAV", i32 100, i32 0, i32 0, i32 4294967294, i32 0} | ||
!5 = !{!"UAV", i32 1, i32 101, i32 0, i32 10, i32 0} |
inbelic marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
; RUN: not opt -S -passes='dxil-post-optimization-validation' -mtriple=dxil-pc-shadermodel6.6-compute %s 2>&1 | FileCheck %s | ||
; CHECK: error: Overflow for shader register range: UAV(register=4294967295, space=0) | ||
define void @CSMain() "hlsl.shader"="compute" { | ||
entry: | ||
ret void | ||
} | ||
|
||
!dx.rootsignatures = !{!0} | ||
|
||
!0 = !{ptr @CSMain, !1, i32 2} | ||
!1 = !{!3} | ||
!3 = !{!"DescriptorTable", i32 0, !4} | ||
!4 = !{!"UAV", i32 100, i32 4294967295, i32 0, i32 -1, i32 0} |
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.
Nothing needed for this PR as you're just following the established pattern, but we should probably come back and take a look at this error heirarchy at some point - I'm not really convinced we need this many distinct errors given all we ever do with them is print the error message (as opposed to handling specific errors in some way). We might be able to simplify these to something only a bit more structured than a
StringError
without any real loss to functionality or readability.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've created an issue to check this in the future: #159429