diff options
author | Greg Fischer <greg@lunarg.com> | 2022-11-02 20:23:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-02 20:23:25 +0300 |
commit | c8e1588cfa3ff9e3b5d600ef04f4261c4e68af90 (patch) | |
tree | 05fd13d996634c2c11280b092a88b812dab3fdb9 /include | |
parent | a52de681dd17f8b545ecd9ea2138f72b39bf449a (diff) |
Add passes to eliminate dead output stores (#4970)
This adds two passes to accomplish this: one pass to analyze a shader
to determine the input slots that are live. The second pass is run on
the preceding shader to eliminate any stores to output slots that are
not consumed by the following shader.
These passes support vert, tesc, tese, geom, and frag shaders.
These passes are currently only available through the API.
These passes together with dead code elimination, and elimination of
dead input and output components and variables (WIP), will allow users
to do dead code elimination across shader boundaries.
Diffstat (limited to 'include')
-rw-r--r-- | include/spirv-tools/optimizer.hpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/include/spirv-tools/optimizer.hpp b/include/spirv-tools/optimizer.hpp index 949735608..bca12520f 100644 --- a/include/spirv-tools/optimizer.hpp +++ b/include/spirv-tools/optimizer.hpp @@ -19,6 +19,7 @@ #include <ostream> #include <string> #include <unordered_map> +#include <unordered_set> #include <utility> #include <vector> @@ -893,6 +894,26 @@ Optimizer::PassToken CreateInterpolateFixupPass(); // types. Optimizer::PassToken CreateEliminateDeadInputComponentsPass(); +// Analyzes shader and populates |live_locs| and |live_builtins|. Best results +// will be obtained if shader has all dead code eliminated first. |live_locs| +// and |live_builtins| are subsequently used when calling +// CreateEliminateDeadOutputStoresPass on the preceding shader. Currently only +// supports tesc, tese, geom, and frag shaders. +Optimizer::PassToken CreateAnalyzeLiveInputPass( + std::unordered_set<uint32_t>* live_locs, + std::unordered_set<uint32_t>* live_builtins); + +// Removes stores to output locations not listed in |live_locs| or +// |live_builtins|. Best results are obtained if constant propagation is +// performed first. A subsequent call to ADCE will eliminate any dead code +// created by the removal of the stores. A subsequent call to +// CreateEliminateDeadOutputComponentsPass will eliminate any dead output +// components created by the elimination of the stores. Currently only supports +// vert, tesc, tese, and geom shaders. +Optimizer::PassToken CreateEliminateDeadOutputStoresPass( + std::unordered_set<uint32_t>* live_locs, + std::unordered_set<uint32_t>* live_builtins); + // Creates a convert-to-sampled-image pass to convert images and/or // samplers with given pairs of descriptor set and binding to sampled image. // If a pair of an image and a sampler have the same pair of descriptor set and |