Repository navigation
fix(shader): replicate a lane-invariant descriptor dword into both web arms #21763
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
base: main
Are you sure you want to change the base?
Changes from all commits
8900a30
badbe8c
46b222d
efc21d3
4bb0c53
2098734
9adafaf
2c23338
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 |
|---|---|---|
|
|
@@ -1549,6 +1549,7 @@ class Tracker { | |
| } | ||
|
|
||
| static constexpr std::uint32_t phiSearchDepth = 8u; | ||
| static constexpr std::uint32_t descriptorDwordDepth = 16u; | ||
| static constexpr std::uint32_t firstLaneMultipleDepth = 32u; | ||
|
|
||
| static bool SplittableImageRead(const IrValue& inst) { | ||
|
|
@@ -1738,7 +1739,7 @@ class Tracker { | |
| } | ||
| if (value->IsPhi()) { | ||
| IrValue* incoming = PhiIncoming(*value, predecessor); | ||
| return incoming == nullptr ? nullptr : Rematerialize(incoming, position, emit, phiSearchDepth); | ||
| return incoming == nullptr ? nullptr : Rematerialize(incoming, position, emit, descriptorDwordDepth); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bound the cost of rebuilding shared descriptor expressions.
Make the rebuild cost follow the size of the shared graph, not its tree expansion. Reuse the emitted result for a shared value within one rebuild, or enforce an explicit emitted-node budget for the rebuild. Either change must still rebuild every descriptor dword that the validator accepts.
|
||
| } | ||
| std::vector<IrValue*> arguments; | ||
| for (std::size_t index = 0; index < value->ArgumentCount(); index++) { | ||
|
|
@@ -1842,7 +1843,7 @@ class Tracker { | |
| for (const IrBlock* arm : arms) { | ||
| for (std::uint32_t slot = 0; slot < handleCount; slot++) { | ||
| for (std::size_t dword = 0; split[slot] && dword < handles[slot]->ArgumentCount(); dword++) { | ||
| if (SubstituteEdge(handles[slot]->Argument(dword), arm, inst, false, phiSearchDepth) == nullptr) { | ||
| if (SubstituteEdge(handles[slot]->Argument(dword), arm, inst, false, descriptorDwordDepth) == nullptr) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Group predecessors on every Phi that arm substitution rewrites. Edge grouping collects Phis with For example, with three predecessors, a visible Phi with values Require the predecessor grouping to compare every Phi that the arm substitution rewrites. A group must share the values of all such Phis. Alternatively, require substitution to rewrite only the Phis that the grouping compares. Either change must give each predecessor its own incoming value. The depth-16 rematerialization of incoming values at line 1715 can remain unchanged.
|
||
| return false; | ||
| } | ||
| } | ||
|
|
@@ -1858,7 +1859,7 @@ class Tracker { | |
| conditions.push_back(&EdgeSelector(*block, edges)); | ||
| } | ||
| ReplaceWithArmCopies(inst, handles, split, handleCount, conditions, false, [&](std::uint32_t arm, std::uint32_t slot, std::size_t dword) { | ||
| return SubstituteEdge(handles[slot]->Argument(dword), arms[arm], inst, true, phiSearchDepth); | ||
| return SubstituteEdge(handles[slot]->Argument(dword), arms[arm], inst, true, descriptorDwordDepth); | ||
| }); | ||
| return true; | ||
| } | ||
|
|
@@ -2047,7 +2048,7 @@ class Tracker { | |
| return &m_builder.Constant(DescriptorWeb::foldedArm); | ||
| } | ||
| for (IrValue* value : tuple) { | ||
| if (Rematerialize(value, position, false, phiSearchDepth) == nullptr) { | ||
| if (Rematerialize(value, position, false, descriptorDwordDepth) == nullptr) { | ||
| if (StrictDescriptorWebs()) { | ||
| return GiveUp(web, "a descriptor dword is not rebuilt from user data, the SRT and uniform operations before the read (" + RebuildBlocker(value, phiSearchDepth) + ")"); | ||
| } | ||
|
|
@@ -2118,6 +2119,14 @@ class Tracker { | |
| return &selector; | ||
| } | ||
|
|
||
| bool LaneInvariantDword(const IrValue& value) const { | ||
| if (value.Type() != IrType::U32) { | ||
| return false; | ||
| } | ||
| constexpr SrtWalker walker; | ||
| return walker.ValidateRuntimeValue(m_program.Resources(), &value); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lane-invariant
The rebuild and the predicate must agree. A dword that
|
||
| } | ||
|
|
||
| static bool EarlierPhi(const IrValue& value, const IrBlock* block, const DescriptorWeb& web) { | ||
| if (!value.IsPhi()) { | ||
| return false; | ||
|
|
@@ -2146,7 +2155,7 @@ class Tracker { | |
| if (select) { | ||
| right.push_back(value->Argument(2u)); | ||
| } | ||
| } else if (value->HasImmediate() || (select && !value->IsPhi() && value->Opcode() != IrOpcode::ReadFirstLane) || EarlierPhi(*value, block, web)) { | ||
| } else if (value->HasImmediate() || LaneInvariantDword(*value) || (select && !value->IsPhi() && value->Opcode() != IrOpcode::ReadFirstLane) || EarlierPhi(*value, block, web)) { | ||
| left.push_back(value); | ||
| if (select) { | ||
| right.push_back(value); | ||
|
|
@@ -2253,7 +2262,7 @@ class Tracker { | |
| conditions.push_back(EmitBefore(inst, IrOpcode::IEqual32, IrType::Bool, compare)); | ||
| } | ||
| ReplaceWithArmCopies(inst, handles, split, handleCount, conditions, true, [&](std::uint32_t arm, std::uint32_t slot, std::size_t dword) { | ||
| return Rematerialize(web.arms[arm][offsets[slot] + dword], inst, true, phiSearchDepth); | ||
| return Rematerialize(web.arms[arm][offsets[slot] + dword], inst, true, descriptorDwordDepth); | ||
| }); | ||
| } | ||
|
|
||
|
|
||
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.
Assert the replicated invariant dword in both descriptor arms.
CompileDescriptorWebchecks only fault-buffer state, image and optional-descriptor counts, and whether compilation succeeds. It does not check any descriptor word or source dword. A regression that gives one arm a wrong invariant dword can still compile with the same counts, soverifyDescriptorWebLaneInvariantDwordwould still pass.Add assertions that check the invariant SRT dword in both arms of the lane-invariant case. Also check that the selected per-lane dword keeps its two expected alternatives. This tests the replication that the PR changes, not only that compilation succeeds.