Repository navigation
startup: implement command-list slots 41/43/45/46 root constants and views (Part of #870) #2017
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9990228
startup: record root views on command-list slots 41, 43, 45 and 46
tedin7 46f4751
startup: record compute root SRVs without a prefix copy; document roo…
tedin7 480c6fb
startup: bind compute root UAV/SRV addresses in live placed buffers
tedin7 cc65714
Merge origin/main into x2w-frontier-slots41-46
tedin7 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #pragma once | ||
|
|
||
| // Root descriptor views (CBV, SRV, UAV) a title sets on a command list, for the slots that carry them: | ||
| // compute CBV 41, compute SRV 43, compute UAV 45 and graphics UAV 46 (desktop 37, 39, 41, 42 plus four). | ||
| // Plain header with no Windows types so the host-only test can build it. | ||
| // | ||
| // A view is accepted only when a root signature of the matching kind is set, the parameter is below | ||
| // root_view_parameters and the root signature declares that parameter with the same view type. Anything | ||
| // else is refused and the store is left as it was. Setting a new root signature clears the store. | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| namespace x2w_startup { | ||
|
|
||
| constexpr unsigned root_view_parameters = 16; | ||
|
|
||
| // D3D12_ROOT_PARAMETER_TYPE values. | ||
| constexpr unsigned root_type_cbv = 2; | ||
| constexpr unsigned root_type_srv = 3; | ||
| constexpr unsigned root_type_uav = 4; | ||
|
|
||
| enum class RootViewResult { stored, no_root, parameter_out_of_range, wrong_type }; | ||
|
|
||
| inline const char* root_view_reason(RootViewResult result) | ||
| { | ||
| switch (result) { | ||
| case RootViewResult::stored: return "stored"; | ||
| case RootViewResult::no_root: return "no root signature set"; | ||
| case RootViewResult::parameter_out_of_range: return "parameter out of range"; | ||
| case RootViewResult::wrong_type: return "parameter declared as another type"; | ||
| } | ||
| return "unknown"; | ||
| } | ||
|
|
||
| struct RootViewStore { | ||
| std::uint64_t address[root_view_parameters] = {}; // title address, 0 when never set or the address was unreadable | ||
| std::uint32_t bound = 0; // bit per parameter that holds a view | ||
|
|
||
| void clear() { *this = RootViewStore{}; } | ||
|
|
||
| // True when every parameter in required (one bit each) holds a view. A Dispatch that needs these roots | ||
| // must be recorded only when this holds. | ||
| bool covers(std::uint32_t required) const { return (bound & required) == required; } | ||
|
|
||
| // declared: the type the root signature gives parameter, or ~0u when it has no such parameter. | ||
| RootViewResult set(bool root_set, unsigned declared, unsigned wanted, unsigned parameter, std::uint64_t value) | ||
| { | ||
| if (!root_set) return RootViewResult::no_root; | ||
| if (parameter >= root_view_parameters || declared == ~0u) return RootViewResult::parameter_out_of_range; | ||
| if (declared != wanted) return RootViewResult::wrong_type; | ||
| address[parameter] = value; | ||
| if (value) bound |= 1u << parameter; | ||
| else bound &= ~(1u << parameter); | ||
| return RootViewResult::stored; | ||
| } | ||
| }; | ||
|
|
||
| } // namespace x2w_startup |
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,49 @@ | ||
| // Host-only check of src/startup_stubs/root_view_store.h: which root view calls a list accepts and what the | ||
| // store holds afterwards. | ||
| #include "startup_stubs/root_view_store.h" | ||
|
|
||
| #include <cstdio> | ||
|
|
||
| using namespace x2w_startup; | ||
|
|
||
| namespace { | ||
| int failures; | ||
| void expect(bool ok, const char* what) | ||
| { | ||
| if (ok) return; | ||
| ++failures; | ||
| std::printf("FAIL %s\n", what); | ||
| } | ||
| } // namespace | ||
|
|
||
| int main() | ||
| { | ||
| RootViewStore store; | ||
| expect(store.set(false, root_type_cbv, root_type_cbv, 0, 0x1000) == RootViewResult::no_root, "no root refused"); | ||
| expect(store.bound == 0 && store.address[0] == 0, "no root leaves the store empty"); | ||
|
|
||
| expect(store.set(true, root_type_cbv, root_type_cbv, 3, 0x2000) == RootViewResult::stored, "cbv stored"); | ||
| expect(store.address[3] == 0x2000 && store.bound == (1u << 3), "cbv address and bit"); | ||
|
|
||
| expect(store.set(true, root_type_srv, root_type_uav, 3, 0x3000) == RootViewResult::wrong_type, "uav on srv parameter refused"); | ||
| expect(store.address[3] == 0x2000, "refused call keeps the old address"); | ||
|
|
||
| expect(store.set(true, ~0u, root_type_srv, 5, 0x4000) == RootViewResult::parameter_out_of_range, "undeclared parameter refused"); | ||
| expect(store.set(true, root_type_srv, root_type_srv, root_view_parameters, 0x4000) == RootViewResult::parameter_out_of_range, | ||
| "parameter 16 refused"); | ||
| expect(store.set(true, root_type_srv, root_type_srv, 15, 0x5000) == RootViewResult::stored, "last parameter stored"); | ||
| expect(store.bound == ((1u << 3) | (1u << 15)), "two bits set"); | ||
|
|
||
| expect(store.set(true, root_type_cbv, root_type_cbv, 3, 0) == RootViewResult::stored, "zero address stored"); | ||
| expect(store.bound == (1u << 15) && store.address[3] == 0, "zero address clears the bit"); | ||
|
|
||
| expect(store.covers(1u << 15) && store.covers(0), "bound parameter covered"); | ||
| expect(!store.covers((1u << 15) | (1u << 4)), "a missing root is not covered"); | ||
|
|
||
| store.clear(); | ||
| expect(store.bound == 0 && store.address[15] == 0, "clear empties the store"); | ||
|
|
||
| if (failures) return 1; | ||
| std::printf("root view store ok\n"); | ||
| return 0; | ||
| } |
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.