-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[HLSL][RootSignature] Implement ResourceRange
as an IntervalMap
#140957
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
Open
inbelic
wants to merge
5
commits into
llvm:main
Choose a base branch
from
inbelic:inbelic/rs-resource-range-intervals
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a222856
[HLSL][RootSignature] Implement resource register validation
inbelic f5226ad
review: small clarifications
inbelic ee63c2e
self-review: touch up comment
inbelic 042c3a0
self-review: fix missed typos
inbelic 87241ac
Merge branch 'main' into inbelic/rs-resource-range-intervals
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
177 changes: 177 additions & 0 deletions
177
llvm/unittests/Frontend/HLSLRootSignatureRangesTest.cpp
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,177 @@ | ||
//===------ HLSLRootSignatureRangeTest.cpp - RootSignature Range tests ----===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/Frontend/HLSL/HLSLRootSignature.h" | ||
#include "gtest/gtest.h" | ||
|
||
using namespace llvm::hlsl::rootsig; | ||
|
||
namespace { | ||
|
||
TEST(HLSLRootSignatureTest, NoOverlappingInsertTests) { | ||
// Ensures that there is never a reported overlap | ||
ResourceRange::MapT::Allocator Allocator; | ||
ResourceRange Range(Allocator); | ||
|
||
RangeInfo A; | ||
A.LowerBound = 0; | ||
A.UpperBound = 3; | ||
EXPECT_EQ(Range.insert(A), std::nullopt); | ||
|
||
RangeInfo B; | ||
B.LowerBound = 4; | ||
B.UpperBound = 7; | ||
EXPECT_EQ(Range.insert(B), std::nullopt); | ||
|
||
RangeInfo C; | ||
C.LowerBound = 10; | ||
C.UpperBound = RangeInfo::Unbounded; | ||
EXPECT_EQ(Range.insert(C), std::nullopt); | ||
|
||
// A = [0;3] | ||
EXPECT_EQ(Range.lookup(0), &A); | ||
EXPECT_EQ(Range.lookup(2), &A); | ||
EXPECT_EQ(Range.lookup(3), &A); | ||
|
||
// B = [4;7] | ||
EXPECT_EQ(Range.lookup(4), &B); | ||
EXPECT_EQ(Range.lookup(5), &B); | ||
EXPECT_EQ(Range.lookup(7), &B); | ||
|
||
EXPECT_EQ(Range.lookup(8), nullptr); | ||
EXPECT_EQ(Range.lookup(9), nullptr); | ||
|
||
// C = [10;unbounded] | ||
EXPECT_EQ(Range.lookup(10), &C); | ||
EXPECT_EQ(Range.lookup(42), &C); | ||
EXPECT_EQ(Range.lookup(98237423), &C); | ||
EXPECT_EQ(Range.lookup(RangeInfo::Unbounded), &C); | ||
} | ||
|
||
TEST(HLSLRootSignatureTest, SingleOverlappingInsertTests) { | ||
// Ensures that we correctly report an overlap when we insert a range that | ||
// overlaps with one other range but does not cover (replace) it | ||
ResourceRange::MapT::Allocator Allocator; | ||
ResourceRange Range(Allocator); | ||
|
||
RangeInfo A; | ||
A.LowerBound = 1; | ||
A.UpperBound = 5; | ||
EXPECT_EQ(Range.insert(A), std::nullopt); | ||
|
||
RangeInfo B; | ||
B.LowerBound = 0; | ||
B.UpperBound = 2; | ||
EXPECT_EQ(Range.insert(B).value(), &A); | ||
|
||
RangeInfo C; | ||
C.LowerBound = 4; | ||
C.UpperBound = RangeInfo::Unbounded; | ||
EXPECT_EQ(Range.insert(C).value(), &A); | ||
|
||
// A = [1;5] | ||
EXPECT_EQ(Range.lookup(1), &A); | ||
EXPECT_EQ(Range.lookup(2), &A); | ||
EXPECT_EQ(Range.lookup(3), &A); | ||
EXPECT_EQ(Range.lookup(4), &A); | ||
EXPECT_EQ(Range.lookup(5), &A); | ||
|
||
// B = [0;0] | ||
EXPECT_EQ(Range.lookup(0), &B); | ||
|
||
// C = [6; unbounded] | ||
inbelic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
EXPECT_EQ(Range.lookup(6), &C); | ||
EXPECT_EQ(Range.lookup(RangeInfo::Unbounded), &C); | ||
} | ||
|
||
TEST(HLSLRootSignatureTest, MultipleOverlappingInsertTests) { | ||
// Ensures that we correctly report an overlap when inserted range | ||
// overlaps more than one range and it does not cover (replace) either | ||
// range. In this case it will just fill in the interval between the two | ||
ResourceRange::MapT::Allocator Allocator; | ||
ResourceRange Range(Allocator); | ||
|
||
RangeInfo A; | ||
A.LowerBound = 0; | ||
A.UpperBound = 2; | ||
EXPECT_EQ(Range.insert(A), std::nullopt); | ||
|
||
RangeInfo B; | ||
B.LowerBound = 4; | ||
B.UpperBound = 6; | ||
EXPECT_EQ(Range.insert(B), std::nullopt); | ||
|
||
RangeInfo C; | ||
C.LowerBound = 1; | ||
C.UpperBound = 5; | ||
EXPECT_EQ(Range.insert(C).value(), &A); | ||
|
||
// A = [0;2] | ||
EXPECT_EQ(Range.lookup(0), &A); | ||
EXPECT_EQ(Range.lookup(1), &A); | ||
EXPECT_EQ(Range.lookup(2), &A); | ||
|
||
// B = [4;6] | ||
EXPECT_EQ(Range.lookup(4), &B); | ||
EXPECT_EQ(Range.lookup(5), &B); | ||
EXPECT_EQ(Range.lookup(6), &B); | ||
|
||
// C = [3;3] | ||
EXPECT_EQ(Range.lookup(3), &C); | ||
} | ||
|
||
TEST(HLSLRootSignatureTest, CoverInsertTests) { | ||
// Ensures that we correctly report an overlap when inserted range | ||
// covers one or more ranges | ||
ResourceRange::MapT::Allocator Allocator; | ||
ResourceRange Range(Allocator); | ||
|
||
RangeInfo A; | ||
A.LowerBound = 0; | ||
A.UpperBound = 2; | ||
EXPECT_EQ(Range.insert(A), std::nullopt); | ||
|
||
RangeInfo B; | ||
B.LowerBound = 4; | ||
B.UpperBound = 5; | ||
EXPECT_EQ(Range.insert(B), std::nullopt); | ||
|
||
// Covers B | ||
RangeInfo C; | ||
C.LowerBound = 4; | ||
C.UpperBound = 6; | ||
EXPECT_EQ(Range.insert(C).value(), &B); | ||
|
||
// A = [0;2] | ||
// C = [4;6] <- covers reference to B | ||
EXPECT_EQ(Range.lookup(0), &A); | ||
EXPECT_EQ(Range.lookup(1), &A); | ||
EXPECT_EQ(Range.lookup(2), &A); | ||
EXPECT_EQ(Range.lookup(3), nullptr); | ||
EXPECT_EQ(Range.lookup(4), &C); | ||
EXPECT_EQ(Range.lookup(5), &C); | ||
EXPECT_EQ(Range.lookup(6), &C); | ||
|
||
// Covers all other ranges | ||
RangeInfo D; | ||
D.LowerBound = 0; | ||
D.UpperBound = 7; | ||
EXPECT_EQ(Range.insert(D).value(), &A); | ||
|
||
// D = [0;7] <- Covers reference to A and C | ||
EXPECT_EQ(Range.lookup(0), &D); | ||
EXPECT_EQ(Range.lookup(1), &D); | ||
EXPECT_EQ(Range.lookup(2), &D); | ||
EXPECT_EQ(Range.lookup(3), &D); | ||
EXPECT_EQ(Range.lookup(4), &D); | ||
EXPECT_EQ(Range.lookup(5), &D); | ||
EXPECT_EQ(Range.lookup(6), &D); | ||
EXPECT_EQ(Range.lookup(7), &D); | ||
} | ||
|
||
} // namespace |
Oops, something went wrong.
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.