-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[DirectX] Add extract-section
to llvm-objcopy
and implement it for DXContainer
#154804
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
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
350d36a
add common option `extract-section`
inbelic 86160db
add support for `extract-section` for `dxcontainer`
inbelic c4810e6
add basic test cases
inbelic 8b733cc
comment touch up
inbelic 2129aed
add failure testcase
inbelic fcf5316
actually enable option for DXContainer
inbelic a6bf6cc
self-review: no need to alloc
inbelic 7baf785
clang-format
inbelic 40d7e57
review: alphabetical order
inbelic 6d92ea4
review: add ELF block to denote unhandled option
inbelic a795ac7
review: add option docs
inbelic 2792bd0
review: rename tests
inbelic bb336c9
self-review: misc
inbelic 9197d82
review: fix up comments
inbelic 2bc1450
review: improve testing readability and strictness
inbelic be61cae
review: hande extract before any removal
inbelic b9f6e08
review: add test for invalid format err
inbelic f3ce155
review: improve test readability and flexibility
inbelic 00627a4
review: clean up test cases
inbelic b689569
Merge branch 'main' into inbelic/dx-objcopy-extract
inbelic 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
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
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
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
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
111 changes: 111 additions & 0 deletions
111
llvm/test/tools/llvm-objcopy/DXContainer/extract-section-basic.test
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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
## Tests that a separate DXContainer is created for the RTS0 (root signature) | ||
## part, when--extract-section is specified. | ||
|
||
# RUN: yaml2obj %s -o %t | ||
# RUN: llvm-objcopy %t --extract-section=RTS0=%t.rts0.out | ||
# RUN: obj2yaml %t.rts0.out | FileCheck %s --implicit-check-not=Name: | ||
|
||
## The DXContainer described below was generated with: | ||
|
||
## `clang-dxc -T cs_6_7 test.hlsl /Fo temp.dxo` | ||
## `obj2yaml temp.dxo` | ||
|
||
## and has the DXIL section trimmed for readability. | ||
|
||
## ``` test.hlsl | ||
## [RootSignature("")] | ||
## [numthreads(1,1,1)] | ||
## void main() {} | ||
## ``` | ||
|
||
# CHECK: Header: | ||
# CHECK-NEXT: Hash: | ||
# CHECK: Version: | ||
# CHECK-NEXT: Major: 1 | ||
# CHECK-NEXT: Minor: 0 | ||
# CHECK-NEXT: FileSize: 68 | ||
# CHECK-NEXT: PartCount: 1 | ||
# CHECK-NEXT: PartOffsets: [ 36 ] | ||
# CHECK-NEXT: Parts: | ||
# CHECK-NEXT: Name: RTS0 | ||
# CHECK-NEXT Size: 24 | ||
# CHECK-NEXT RootSignature: | ||
# CHECK-NEXT Version: 2 | ||
# CHECK-NEXT NumRootParameters: 0 | ||
# CHECK-NEXT RootParametersOffset: 24 | ||
# CHECK-NEXT NumStaticSamplers: 0 | ||
# CHECK-NEXT StaticSamplersOffset: 24 | ||
# CHECK-NEXT Parameters: [] | ||
|
||
--- !dxcontainer | ||
Header: | ||
Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | ||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ] | ||
Version: | ||
Major: 1 | ||
Minor: 0 | ||
FileSize: 1984 | ||
PartCount: 7 | ||
PartOffsets: [ 60, 1792, 1808, 1836, 1852, 1868, 1900 ] | ||
Parts: | ||
- Name: DXIL | ||
Size: 1724 | ||
Program: | ||
MajorVersion: 6 | ||
MinorVersion: 7 | ||
ShaderKind: 5 | ||
Size: 28 | ||
DXILMajorVersion: 1 | ||
DXILMinorVersion: 7 | ||
DXILSize: 4 | ||
DXIL: [ 0x42, 0x43, 0xC0, 0xDE, ] | ||
- Name: SFI0 | ||
Size: 8 | ||
- Name: HASH | ||
Size: 20 | ||
Hash: | ||
IncludesSource: false | ||
Digest: [ 0x9F, 0xD1, 0xD9, 0xE2, 0x49, 0xFB, 0x3A, 0x6C, | ||
0x8C, 0x14, 0x8A, 0x96, 0x1C, 0x7D, 0x85, 0xA9 ] | ||
- Name: ISG1 | ||
Size: 8 | ||
Signature: | ||
Parameters: [] | ||
- Name: OSG1 | ||
Size: 8 | ||
Signature: | ||
Parameters: [] | ||
- Name: RTS0 | ||
Size: 24 | ||
RootSignature: | ||
Version: 2 | ||
NumRootParameters: 0 | ||
RootParametersOffset: 24 | ||
NumStaticSamplers: 0 | ||
StaticSamplersOffset: 24 | ||
Parameters: [] | ||
- Name: PSV0 | ||
Size: 76 | ||
PSVInfo: | ||
Version: 3 | ||
ShaderStage: 5 | ||
MinimumWaveLaneCount: 0 | ||
MaximumWaveLaneCount: 4294967295 | ||
UsesViewID: 0 | ||
SigInputVectors: 0 | ||
SigOutputVectors: [ 0, 0, 0, 0 ] | ||
NumThreadsX: 1 | ||
NumThreadsY: 1 | ||
NumThreadsZ: 1 | ||
EntryName: main | ||
ResourceStride: 24 | ||
Resources: [] | ||
SigInputElements: [] | ||
SigOutputElements: [] | ||
SigPatchOrPrimElements: [] | ||
InputOutputMap: | ||
- [ ] | ||
- [ ] | ||
- [ ] | ||
- [ ] | ||
... |
40 changes: 40 additions & 0 deletions
40
llvm/test/tools/llvm-objcopy/DXContainer/extract-section-errs.test
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
## Check that llvm-objcopy reports a suitable error when it can't find the | ||
## section to extract. | ||
|
||
## We can't extract a part that doesn't exist. | ||
# RUN: yaml2obj %s --docnum=1 -o %t1 | ||
# RUN: not llvm-objcopy %t1 --extract-section=UNKNOWN=%t.unknown.out 2>&1 | FileCheck %s -DFILE=%t1 --check-prefix=ERROR1 | ||
|
||
# ERROR1: error: '[[FILE]]': part 'UNKNOWN' not found | ||
|
||
--- !dxcontainer | ||
Header: | ||
Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | ||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ] | ||
Version: | ||
Major: 1 | ||
Minor: 0 | ||
PartCount: 1 | ||
Parts: | ||
- Name: FKE0 | ||
Size: 8 | ||
... | ||
|
||
## We can't extract a part that is specified incorrectly. | ||
# RUN: yaml2obj %s --docnum=2 -o %t2 | ||
# RUN: not llvm-objcopy %t2 --extract-section=FKE0,%t.fke0.out 2>&1 | FileCheck %s -DFILE=%t2 --check-prefix=ERROR2 | ||
|
||
# ERROR2: error: bad format for --extract-section, expected section=file | ||
|
||
--- !dxcontainer | ||
Header: | ||
Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | ||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ] | ||
Version: | ||
Major: 1 | ||
Minor: 0 | ||
PartCount: 1 | ||
Parts: | ||
- Name: FKE0 | ||
Size: 8 | ||
... |
53 changes: 53 additions & 0 deletions
53
llvm/test/tools/llvm-objcopy/DXContainer/extract-section-headers.test
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
## Tests that a separate DXContainer is created with only the specified section | ||
## for each --extract-section specified. | ||
|
||
# RUN: yaml2obj %s -o %t | ||
# RUN: llvm-objcopy %t --extract-section=FKE1=%t.fke1.out --extract-section=FKE4=%t.fke4.out | ||
# RUN: obj2yaml %t.fke1.out | FileCheck %s --check-prefixes=CHECK,FKE1 --implicit-check-not=Name: | ||
# RUN: obj2yaml %t.fke4.out | FileCheck %s --check-prefixes=CHECK,FKE4 --implicit-check-not=Name: | ||
|
||
# FKE1: FileSize: 52 | ||
# FKE4: FileSize: 1732 | ||
# CHECK-NEXT: PartCount: 1 | ||
# CHECK-NEXT: PartOffsets: [ 36 ] | ||
# CHECK-NEXT: Parts: | ||
# FKE1-NEXT: Name: FKE1 | ||
# FKE1-NEXT: Size: 8 | ||
# FKE4-NEXT: Name: FKE4 | ||
# FKE4-NEXT: Size: 1688 | ||
|
||
--- !dxcontainer | ||
Header: | ||
Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | ||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ] | ||
Version: | ||
Major: 1 | ||
Minor: 0 | ||
FileSize: 1996 | ||
PartCount: 7 | ||
PartOffsets: [ 60, 76, 92, 108, 236, 1932, 1960 ] | ||
Parts: | ||
- Name: FKE0 | ||
Size: 8 | ||
- Name: FKE1 | ||
Size: 8 | ||
- Name: FKE2 | ||
Size: 8 | ||
- Name: FKE3 | ||
Size: 120 | ||
- Name: FKE4 | ||
Size: 1688 | ||
- Name: FKE5 | ||
Size: 20 | ||
- Name: DXIL | ||
Size: 28 | ||
Program: | ||
MajorVersion: 6 | ||
MinorVersion: 5 | ||
ShaderKind: 5 | ||
Size: 8 | ||
DXILMajorVersion: 1 | ||
DXILMinorVersion: 5 | ||
DXILSize: 4 | ||
DXIL: [ 0x42, 0x43, 0xC0, 0xDE, ] | ||
... |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.