-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[DirectX][NFC] Refactoring DirectX backend to not use llvm::to_underlying
in switch cases.
#151032
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 3 commits
ea35c41
3c1fc51
591d12a
0d55d28
7841a83
98be089
25ee6d7
94fef90
3924438
5f26016
c975cc2
1d080aa
3b5f497
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 |
---|---|---|
|
@@ -424,22 +424,28 @@ void MappingContextTraits<DXContainerYAML::RootParameterLocationYaml, | |
IO.mapRequired("ParameterType", L.Header.Type); | ||
IO.mapRequired("ShaderVisibility", L.Header.Visibility); | ||
|
||
switch (L.Header.Type) { | ||
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit): { | ||
if (!dxbc::isValidParameterType(L.Header.Type)) | ||
return; | ||
dxbc::RootParameterType PT = | ||
static_cast<dxbc::RootParameterType>(L.Header.Type); | ||
|
||
// We allow ParameterType to be invalid here. | ||
|
||
switch (PT) { | ||
case dxbc::RootParameterType::Constants32Bit: { | ||
DXContainerYAML::RootConstantsYaml &Constants = | ||
S.Parameters.getOrInsertConstants(L); | ||
IO.mapRequired("Constants", Constants); | ||
break; | ||
} | ||
case llvm::to_underlying(dxbc::RootParameterType::CBV): | ||
case llvm::to_underlying(dxbc::RootParameterType::SRV): | ||
case llvm::to_underlying(dxbc::RootParameterType::UAV): { | ||
case dxbc::RootParameterType::CBV: | ||
case dxbc::RootParameterType::SRV: | ||
case dxbc::RootParameterType::UAV: { | ||
DXContainerYAML::RootDescriptorYaml &Descriptor = | ||
S.Parameters.getOrInsertDescriptor(L); | ||
IO.mapRequired("Descriptor", Descriptor); | ||
break; | ||
} | ||
case llvm::to_underlying(dxbc::RootParameterType::DescriptorTable): { | ||
case dxbc::RootParameterType::DescriptorTable: { | ||
DXContainerYAML::DescriptorTableYaml &Table = | ||
S.Parameters.getOrInsertTable(L); | ||
IO.mapRequired("Table", Table); | ||
|
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 is not updating to not use
to_underlying
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 specific case is necessary, to keep using llvm::to_underlying, since that is checking if an uint_32t is valid value for RootParametersType. However, I updated to use the tablegen definition, that way we will always have it covering all possible values.
Or we can change how the check is being done, if folks prefer.
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.
Seems to me like we get the same end result by doing the int->enum cast once before the switch and having the switch statement operate on the actual enumerations. I have a strong preference for not using
to_underlying
since it impairs the frontend's ability to generate warnings.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.
In this point, we are not sure
Type
is a validDescriptorRangeType
so the casting here int->enum would cause undefined behaviour.