blob: 42eb6442ec16428e59ae5d5b9f1d42203d7cd293 [file] [log] [blame]
Lei Zhangf18e1f22016-09-12 14:11:46 -04001// Copyright (c) 2016 Google Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
dan sinclair58a68762018-08-03 08:05:33 -040015#ifndef INCLUDE_SPIRV_TOOLS_OPTIMIZER_HPP_
16#define INCLUDE_SPIRV_TOOLS_OPTIMIZER_HPP_
Lei Zhangf18e1f22016-09-12 14:11:46 -040017
18#include <memory>
David Netoc32e79e2018-01-04 12:59:50 -050019#include <ostream>
Lei Zhangf18e1f22016-09-12 14:11:46 -040020#include <string>
21#include <unordered_map>
Jaebaek Seo57e1d8e2021-08-18 08:30:48 -040022#include <utility>
Lei Zhangf18e1f22016-09-12 14:11:46 -040023#include <vector>
24
25#include "libspirv.hpp"
Lei Zhangf18e1f22016-09-12 14:11:46 -040026
27namespace spvtools {
28
Arseny Kapoulkinef765d162018-05-22 14:31:26 -070029namespace opt {
30class Pass;
Jaebaek Seo57e1d8e2021-08-18 08:30:48 -040031struct DescriptorSetAndBinding;
Greg Fischer4ac8e5e2021-09-15 12:38:34 -060032} // namespace opt
Arseny Kapoulkinef765d162018-05-22 14:31:26 -070033
Lei Zhangf18e1f22016-09-12 14:11:46 -040034// C++ interface for SPIR-V optimization functionalities. It wraps the context
35// (including target environment and the corresponding SPIR-V grammar) and
36// provides methods for registering optimization passes and optimizing.
37//
38// Instances of this class provides basic thread-safety guarantee.
39class Optimizer {
40 public:
41 // The token for an optimization pass. It is returned via one of the
42 // Create*Pass() standalone functions at the end of this header file and
43 // consumed by the RegisterPass() method. Tokens are one-time objects that
44 // only support move; copying is not allowed.
45 struct PassToken {
46 struct Impl; // Opaque struct for holding inernal data.
47
48 PassToken(std::unique_ptr<Impl>);
49
Arseny Kapoulkinef765d162018-05-22 14:31:26 -070050 // Tokens for built-in passes should be created using Create*Pass functions
51 // below; for out-of-tree passes, use this constructor instead.
52 // Note that this API isn't guaranteed to be stable and may change without
53 // preserving source or binary compatibility in the future.
54 PassToken(std::unique_ptr<opt::Pass>&& pass);
55
Lei Zhangf18e1f22016-09-12 14:11:46 -040056 // Tokens can only be moved. Copying is disabled.
57 PassToken(const PassToken&) = delete;
58 PassToken(PassToken&&);
59 PassToken& operator=(const PassToken&) = delete;
60 PassToken& operator=(PassToken&&);
61
62 ~PassToken();
63
64 std::unique_ptr<Impl> impl_; // Unique pointer to internal data.
65 };
66
67 // Constructs an instance with the given target |env|, which is used to decode
68 // the binaries to be optimized later.
69 //
David Neto5d786f62020-01-24 16:26:07 -050070 // The instance will have an empty message consumer, which ignores all
71 // messages from the library. Use SetMessageConsumer() to supply a consumer
72 // if messages are of concern.
Lei Zhangf18e1f22016-09-12 14:11:46 -040073 explicit Optimizer(spv_target_env env);
74
75 // Disables copy/move constructor/assignment operations.
76 Optimizer(const Optimizer&) = delete;
77 Optimizer(Optimizer&&) = delete;
78 Optimizer& operator=(const Optimizer&) = delete;
79 Optimizer& operator=(Optimizer&&) = delete;
80
81 // Destructs this instance.
82 ~Optimizer();
83
84 // Sets the message consumer to the given |consumer|. The |consumer| will be
85 // invoked once for each message communicated from the library.
86 void SetMessageConsumer(MessageConsumer consumer);
87
Diego Novillo99fe61e2018-07-25 15:21:44 -040088 // Returns a reference to the registered message consumer.
89 const MessageConsumer& consumer() const;
90
Lei Zhangf18e1f22016-09-12 14:11:46 -040091 // Registers the given |pass| to this optimizer. Passes will be run in the
92 // exact order of registration. The token passed in will be consumed by this
93 // method.
94 Optimizer& RegisterPass(PassToken&& pass);
95
Diego Novilloc90d7302017-08-30 14:19:22 -040096 // Registers passes that attempt to improve performance of generated code.
97 // This sequence of passes is subject to constant review and will change
98 // from time to time.
99 Optimizer& RegisterPerformancePasses();
100
101 // Registers passes that attempt to improve the size of generated code.
102 // This sequence of passes is subject to constant review and will change
103 // from time to time.
104 Optimizer& RegisterSizePasses();
105
Lei Zhangaec60b82017-11-17 16:50:43 -0500106 // Registers passes that attempt to legalize the generated code.
107 //
Diego Novillo99fe61e2018-07-25 15:21:44 -0400108 // Note: this recipe is specially designed for legalizing SPIR-V. It should be
109 // used by compilers after translating HLSL source code literally. It should
Lei Zhangaec60b82017-11-17 16:50:43 -0500110 // *not* be used by general workloads for performance or size improvement.
111 //
112 // This sequence of passes is subject to constant review and will change
113 // from time to time.
114 Optimizer& RegisterLegalizationPasses();
115
Diego Novillo99fe61e2018-07-25 15:21:44 -0400116 // Register passes specified in the list of |flags|. Each flag must be a
117 // string of a form accepted by Optimizer::FlagHasValidForm().
118 //
119 // If the list of flags contains an invalid entry, it returns false and an
120 // error message is emitted to the MessageConsumer object (use
121 // Optimizer::SetMessageConsumer to define a message consumer, if needed).
122 //
123 // If all the passes are registered successfully, it returns true.
124 bool RegisterPassesFromFlags(const std::vector<std::string>& flags);
125
126 // Registers the optimization pass associated with |flag|. This only accepts
127 // |flag| values of the form "--pass_name[=pass_args]". If no such pass
128 // exists, it returns false. Otherwise, the pass is registered and it returns
129 // true.
130 //
131 // The following flags have special meaning:
132 //
133 // -O: Registers all performance optimization passes
134 // (Optimizer::RegisterPerformancePasses)
135 //
136 // -Os: Registers all size optimization passes
137 // (Optimizer::RegisterSizePasses).
138 //
139 // --legalize-hlsl: Registers all passes that legalize SPIR-V generated by an
140 // HLSL front-end.
141 bool RegisterPassFromFlag(const std::string& flag);
142
143 // Validates that |flag| has a valid format. Strings accepted:
144 //
145 // --pass_name[=pass_args]
146 // -O
147 // -Os
148 //
149 // If |flag| takes one of the forms above, it returns true. Otherwise, it
150 // returns false.
151 bool FlagHasValidForm(const std::string& flag) const;
152
Ryan Harrisone0292c22018-12-17 16:54:23 -0500153 // Allows changing, after creation time, the target environment to be
David Neto5d786f62020-01-24 16:26:07 -0500154 // optimized for and validated. Should be called before calling Run().
Ryan Harrisone0292c22018-12-17 16:54:23 -0500155 void SetTargetEnv(const spv_target_env env);
156
Lei Zhangf18e1f22016-09-12 14:11:46 -0400157 // Optimizes the given SPIR-V module |original_binary| and writes the
David Neto5d786f62020-01-24 16:26:07 -0500158 // optimized binary into |optimized_binary|. The optimized binary uses
159 // the same SPIR-V version as the original binary.
160 //
Lei Zhangf18e1f22016-09-12 14:11:46 -0400161 // Returns true on successful optimization, whether or not the module is
Steven Perronbcb0b692018-08-13 13:18:46 -0400162 // modified. Returns false if |original_binary| fails to validate or if errors
163 // occur when processing |original_binary| using any of the registered passes.
164 // In that case, no further passes are executed and the contents in
165 // |optimized_binary| may be invalid.
Lei Zhangf18e1f22016-09-12 14:11:46 -0400166 //
David Neto5d786f62020-01-24 16:26:07 -0500167 // By default, the binary is validated before any transforms are performed,
168 // and optionally after each transform. Validation uses SPIR-V spec rules
169 // for the SPIR-V version named in the binary's header (at word offset 1).
170 // Additionally, if the target environment is a client API (such as
171 // Vulkan 1.1), then validate for that client API version, to the extent
172 // that it is verifiable from data in the binary itself.
173 //
Lei Zhangf18e1f22016-09-12 14:11:46 -0400174 // It's allowed to alias |original_binary| to the start of |optimized_binary|.
175 bool Run(const uint32_t* original_binary, size_t original_binary_size,
176 std::vector<uint32_t>* optimized_binary) const;
Steven Perronbcb0b692018-08-13 13:18:46 -0400177
Steven Perron75c1bf22018-09-10 11:49:41 -0400178 // DEPRECATED: Same as above, except passes |options| to the validator when
179 // trying to validate the binary. If |skip_validation| is true, then the
180 // caller is guaranteeing that |original_binary| is valid, and the validator
181 // will not be run. The |max_id_bound| is the limit on the max id in the
182 // module.
Steven Perronbcb0b692018-08-13 13:18:46 -0400183 bool Run(const uint32_t* original_binary, const size_t original_binary_size,
Steven Perron5c8b4f52018-08-08 11:16:19 -0400184 std::vector<uint32_t>* optimized_binary,
Steven Perron75c1bf22018-09-10 11:49:41 -0400185 const ValidatorOptions& options, bool skip_validation) const;
186
187 // Same as above, except it takes an options object. See the documentation
188 // for |OptimizerOptions| to see which options can be set.
David Neto5d786f62020-01-24 16:26:07 -0500189 //
190 // By default, the binary is validated before any transforms are performed,
191 // and optionally after each transform. Validation uses SPIR-V spec rules
192 // for the SPIR-V version named in the binary's header (at word offset 1).
193 // Additionally, if the target environment is a client API (such as
194 // Vulkan 1.1), then validate for that client API version, to the extent
195 // that it is verifiable from data in the binary itself, or from the
196 // validator options set on the optimizer options.
Steven Perron75c1bf22018-09-10 11:49:41 -0400197 bool Run(const uint32_t* original_binary, const size_t original_binary_size,
198 std::vector<uint32_t>* optimized_binary,
199 const spv_optimizer_options opt_options) const;
Lei Zhangf18e1f22016-09-12 14:11:46 -0400200
Diego Novilloc90d7302017-08-30 14:19:22 -0400201 // Returns a vector of strings with all the pass names added to this
202 // optimizer's pass manager. These strings are valid until the associated
203 // pass manager is destroyed.
Steven Perron58347192017-10-20 12:17:41 -0400204 std::vector<const char*> GetPassNames() const;
Diego Novilloc90d7302017-08-30 14:19:22 -0400205
David Netoc32e79e2018-01-04 12:59:50 -0500206 // Sets the option to print the disassembly before each pass and after the
207 // last pass. If |out| is null, then no output is generated. Otherwise,
208 // output is sent to the |out| output stream.
209 Optimizer& SetPrintAll(std::ostream* out);
210
Jaebaek Seo3b594e12018-03-07 09:25:51 -0500211 // Sets the option to print the resource utilization of each pass. If |out|
212 // is null, then no output is generated. Otherwise, output is sent to the
213 // |out| output stream.
214 Optimizer& SetTimeReport(std::ostream* out);
215
alan-baker42e6f1a2019-03-26 14:38:59 -0400216 // Sets the option to validate the module after each pass.
217 Optimizer& SetValidateAfterAll(bool validate);
218
Lei Zhangf18e1f22016-09-12 14:11:46 -0400219 private:
220 struct Impl; // Opaque struct for holding internal data.
221 std::unique_ptr<Impl> impl_; // Unique pointer to internal data.
222};
223
224// Creates a null pass.
225// A null pass does nothing to the SPIR-V module to be optimized.
226Optimizer::PassToken CreateNullPass();
227
228// Creates a strip-debug-info pass.
229// A strip-debug-info pass removes all debug instructions (as documented in
230// Section 3.32.2 of the SPIR-V spec) of the SPIR-V module to be optimized.
231Optimizer::PassToken CreateStripDebugInfoPass();
232
David Neto844e1862018-03-09 16:08:57 -0500233// Creates a strip-reflect-info pass.
234// A strip-reflect-info pass removes all reflections instructions.
235// For now, this is limited to removing decorations defined in
236// SPV_GOOGLE_hlsl_functionality1. The coverage may expand in
237// the future.
238Optimizer::PassToken CreateStripReflectInfoPass();
239
Steven Perrone43c9102017-09-19 10:12:13 -0400240// Creates an eliminate-dead-functions pass.
Steven Perron58347192017-10-20 12:17:41 -0400241// An eliminate-dead-functions pass will remove all functions that are not in
242// the call trees rooted at entry points and exported functions. These
243// functions are not needed because they will never be called.
Steven Perrone43c9102017-09-19 10:12:13 -0400244Optimizer::PassToken CreateEliminateDeadFunctionsPass();
245
Steven Perron1b0047f2019-02-14 13:42:35 -0500246// Creates an eliminate-dead-members pass.
247// An eliminate-dead-members pass will remove all unused members of structures.
248// This will not affect the data layout of the remaining members.
249Optimizer::PassToken CreateEliminateDeadMembersPass();
250
qining144f59e2017-04-19 18:10:59 -0400251// Creates a set-spec-constant-default-value pass from a mapping from spec-ids
252// to the default values in the form of string.
Lei Zhangf18e1f22016-09-12 14:11:46 -0400253// A set-spec-constant-default-value pass sets the default values for the
254// spec constants that have SpecId decorations (i.e., those defined by
255// OpSpecConstant{|True|False} instructions).
256Optimizer::PassToken CreateSetSpecConstantDefaultValuePass(
257 const std::unordered_map<uint32_t, std::string>& id_value_map);
258
qining144f59e2017-04-19 18:10:59 -0400259// Creates a set-spec-constant-default-value pass from a mapping from spec-ids
260// to the default values in the form of bit pattern.
261// A set-spec-constant-default-value pass sets the default values for the
262// spec constants that have SpecId decorations (i.e., those defined by
263// OpSpecConstant{|True|False} instructions).
264Optimizer::PassToken CreateSetSpecConstantDefaultValuePass(
265 const std::unordered_map<uint32_t, std::vector<uint32_t>>& id_value_map);
266
David Neto11a867f2017-04-01 16:10:16 -0400267// Creates a flatten-decoration pass.
268// A flatten-decoration pass replaces grouped decorations with equivalent
269// ungrouped decorations. That is, it replaces each OpDecorationGroup
270// instruction and associated OpGroupDecorate and OpGroupMemberDecorate
271// instructions with equivalent OpDecorate and OpMemberDecorate instructions.
272// The pass does not attempt to preserve debug information for instructions
273// it removes.
274Optimizer::PassToken CreateFlattenDecorationPass();
275
Lei Zhangf18e1f22016-09-12 14:11:46 -0400276// Creates a freeze-spec-constant-value pass.
277// A freeze-spec-constant pass specializes the value of spec constants to
278// their default values. This pass only processes the spec constants that have
279// SpecId decorations (defined by OpSpecConstant, OpSpecConstantTrue, or
280// OpSpecConstantFalse instructions) and replaces them with their normal
281// counterparts (OpConstant, OpConstantTrue, or OpConstantFalse). The
282// corresponding SpecId annotation instructions will also be removed. This
283// pass does not fold the newly added normal constants and does not process
284// other spec constants defined by OpSpecConstantComposite or
285// OpSpecConstantOp.
286Optimizer::PassToken CreateFreezeSpecConstantValuePass();
287
288// Creates a fold-spec-constant-op-and-composite pass.
289// A fold-spec-constant-op-and-composite pass folds spec constants defined by
290// OpSpecConstantOp or OpSpecConstantComposite instruction, to normal Constants
291// defined by OpConstantTrue, OpConstantFalse, OpConstant, OpConstantNull, or
292// OpConstantComposite instructions. Note that spec constants defined with
293// OpSpecConstant, OpSpecConstantTrue, or OpSpecConstantFalse instructions are
294// not handled, as these instructions indicate their value are not determined
295// and can be changed in future. A spec constant is foldable if all of its
296// value(s) can be determined from the module. E.g., an integer spec constant
297// defined with OpSpecConstantOp instruction can be folded if its value won't
298// change later. This pass will replace the original OpSpecContantOp instruction
299// with an OpConstant instruction. When folding composite spec constants,
300// new instructions may be inserted to define the components of the composite
301// constant first, then the original spec constants will be replaced by
302// OpConstantComposite instructions.
303//
304// There are some operations not supported yet:
305// OpSConvert, OpFConvert, OpQuantizeToF16 and
306// all the operations under Kernel capability.
307// TODO(qining): Add support for the operations listed above.
308Optimizer::PassToken CreateFoldSpecConstantOpAndCompositePass();
309
310// Creates a unify-constant pass.
311// A unify-constant pass de-duplicates the constants. Constants with the exact
312// same value and identical form will be unified and only one constant will
313// be kept for each unique pair of type and value.
314// There are several cases not handled by this pass:
315// 1) Constants defined by OpConstantNull instructions (null constants) and
316// constants defined by OpConstantFalse, OpConstant or OpConstantComposite
317// with value 0 (zero-valued normal constants) are not considered equivalent.
318// So null constants won't be used to replace zero-valued normal constants,
319// vice versa.
320// 2) Whenever there are decorations to the constant's result id id, the
321// constant won't be handled, which means, it won't be used to replace any
322// other constants, neither can other constants replace it.
323// 3) NaN in float point format with different bit patterns are not unified.
324Optimizer::PassToken CreateUnifyConstantPass();
325
326// Creates a eliminate-dead-constant pass.
327// A eliminate-dead-constant pass removes dead constants, including normal
328// contants defined by OpConstant, OpConstantComposite, OpConstantTrue, or
329// OpConstantFalse and spec constants defined by OpSpecConstant,
330// OpSpecConstantComposite, OpSpecConstantTrue, OpSpecConstantFalse or
331// OpSpecConstantOp.
332Optimizer::PassToken CreateEliminateDeadConstantPass();
333
Steven Perrone4c7d8e2017-09-08 12:08:03 -0400334// Creates a strength-reduction pass.
335// A strength-reduction pass will look for opportunities to replace an
336// instruction with an equivalent and less expensive one. For example,
337// multiplying by a power of 2 can be replaced by a bit shift.
338Optimizer::PassToken CreateStrengthReductionPass();
339
GregFad1d0352017-06-07 15:28:53 -0600340// Creates a block merge pass.
341// This pass searches for blocks with a single Branch to a block with no
342// other predecessors and merges the blocks into a single block. Continue
343// blocks and Merge blocks are not candidates for the second block.
344//
345// The pass is most useful after Dead Branch Elimination, which can leave
346// such sequences of blocks. Merging them makes subsequent passes more
347// effective, such as single block local store-load elimination.
348//
349// While this pass reduces the number of occurrences of this sequence, at
350// this time it does not guarantee all such sequences are eliminated.
351//
352// Presence of phi instructions can inhibit this optimization. Handling
Steven Perrone43c9102017-09-19 10:12:13 -0400353// these is left for future improvements.
GregFad1d0352017-06-07 15:28:53 -0600354Optimizer::PassToken CreateBlockMergePass();
355
GregF429ca052017-08-15 17:58:28 -0600356// Creates an exhaustive inline pass.
357// An exhaustive inline pass attempts to exhaustively inline all function
358// calls in all functions in an entry point call tree. The intent is to enable,
359// albeit through brute force, analysis and optimization across function
360// calls by subsequent optimization passes. As the inlining is exhaustive,
361// there is no attempt to optimize for size or runtime performance. Functions
362// that are not in the call tree of an entry point are not changed.
GregFe28bd392017-08-01 17:20:13 -0600363Optimizer::PassToken CreateInlineExhaustivePass();
Steven Perrone43c9102017-09-19 10:12:13 -0400364
GregF429ca052017-08-15 17:58:28 -0600365// Creates an opaque inline pass.
366// An opaque inline pass inlines all function calls in all functions in all
367// entry point call trees where the called function contains an opaque type
368// in either its parameter types or return type. An opaque type is currently
369// defined as Image, Sampler or SampledImage. The intent is to enable, albeit
370// through brute force, analysis and optimization across these function calls
371// by subsequent passes in order to remove the storing of opaque types which is
372// not legal in Vulkan. Functions that are not in the call tree of an entry
373// point are not changed.
374Optimizer::PassToken CreateInlineOpaquePass();
Steven Perrone43c9102017-09-19 10:12:13 -0400375
GregF7c8da662017-05-18 14:51:55 -0600376// Creates a single-block local variable load/store elimination pass.
Steven Perrone43c9102017-09-19 10:12:13 -0400377// For every entry point function, do single block memory optimization of
GregF7c8da662017-05-18 14:51:55 -0600378// function variables referenced only with non-access-chain loads and stores.
379// For each targeted variable load, if previous store to that variable in the
380// block, replace the load's result id with the value id of the store.
381// If previous load within the block, replace the current load's result id
382// with the previous load's result id. In either case, delete the current
383// load. Finally, check if any remaining stores are useless, and delete store
384// and variable if possible.
385//
386// The presence of access chain references and function calls can inhibit
387// the above optimization.
388//
Steven Perron79a00642017-12-11 13:10:24 -0500389// Only modules with relaxed logical addressing (see opt/instruction.h) are
390// currently processed.
GregF7c8da662017-05-18 14:51:55 -0600391//
Steven Perrone43c9102017-09-19 10:12:13 -0400392// This pass is most effective if preceeded by Inlining and
GregF7c8da662017-05-18 14:51:55 -0600393// LocalAccessChainConvert. This pass will reduce the work needed to be done
GregFcc8bad32017-06-16 15:37:31 -0600394// by LocalSingleStoreElim and LocalMultiStoreElim.
GregF429ca052017-08-15 17:58:28 -0600395//
396// Only functions in the call tree of an entry point are processed.
GregF7c8da662017-05-18 14:51:55 -0600397Optimizer::PassToken CreateLocalSingleBlockLoadStoreElimPass();
Greg Fischer04fcc662016-11-10 10:11:50 -0700398
GregF52e247f2017-06-02 13:23:20 -0600399// Create dead branch elimination pass.
400// For each entry point function, this pass will look for SelectionMerge
401// BranchConditionals with constant condition and convert to a Branch to
402// the indicated label. It will delete resulting dead blocks.
403//
Andrey Tuganov4b1577a2017-10-05 16:26:09 -0400404// For all phi functions in merge block, replace all uses with the id
405// corresponding to the living predecessor.
406//
Alan Baker1b6cfd32018-01-04 17:04:03 -0500407// Note that some branches and blocks may be left to avoid creating invalid
408// control flow. Improving this is left to future work.
GregF52e247f2017-06-02 13:23:20 -0600409//
410// This pass is most effective when preceeded by passes which eliminate
411// local loads and stores, effectively propagating constant values where
412// possible.
413Optimizer::PassToken CreateDeadBranchElimPass();
414
GregFcc8bad32017-06-16 15:37:31 -0600415// Creates an SSA local variable load/store elimination pass.
416// For every entry point function, eliminate all loads and stores of function
417// scope variables only referenced with non-access-chain loads and stores.
Steven Perrone43c9102017-09-19 10:12:13 -0400418// Eliminate the variables as well.
GregFcc8bad32017-06-16 15:37:31 -0600419//
420// The presence of access chain references and function calls can inhibit
421// the above optimization.
422//
Steven Perron79a00642017-12-11 13:10:24 -0500423// Only shader modules with relaxed logical addressing (see opt/instruction.h)
424// are currently processed. Currently modules with any extensions enabled are
425// not processed. This is left for future work.
GregFcc8bad32017-06-16 15:37:31 -0600426//
Steven Perrone43c9102017-09-19 10:12:13 -0400427// This pass is most effective if preceeded by Inlining and
GregFcc8bad32017-06-16 15:37:31 -0600428// LocalAccessChainConvert. LocalSingleStoreElim and LocalSingleBlockElim
429// will reduce the work that this pass has to do.
430Optimizer::PassToken CreateLocalMultiStoreElimPass();
431
GregFaa7e6872017-05-12 17:27:21 -0600432// Creates a local access chain conversion pass.
433// A local access chain conversion pass identifies all function scope
434// variables which are accessed only with loads, stores and access chains
435// with constant indices. It then converts all loads and stores of such
436// variables into equivalent sequences of loads, stores, extracts and inserts.
437//
438// This pass only processes entry point functions. It currently only converts
439// non-nested, non-ptr access chains. It does not process modules with
440// non-32-bit integer types present. Optional memory access options on loads
441// and stores are ignored as we are only processing function scope variables.
442//
443// This pass unifies access to these variables to a single mode and simplifies
444// subsequent analysis and elimination of these variables along with their
445// loads and stores allowing values to propagate to their points of use where
446// possible.
447Optimizer::PassToken CreateLocalAccessChainConvertPass();
448
GregF0c5722f2017-05-19 17:31:28 -0600449// Creates a local single store elimination pass.
Steven Perrone43c9102017-09-19 10:12:13 -0400450// For each entry point function, this pass eliminates loads and stores for
GregF0c5722f2017-05-19 17:31:28 -0600451// function scope variable that are stored to only once, where possible. Only
452// whole variable loads and stores are eliminated; access-chain references are
453// not optimized. Replace all loads of such variables with the value that is
454// stored and eliminate any resulting dead code.
455//
456// Currently, the presence of access chains and function calls can inhibit this
457// pass, however the Inlining and LocalAccessChainConvert passes can make it
458// more effective. In additional, many non-load/store memory operations are
459// not supported and will prohibit optimization of a function. Support of
460// these operations are future work.
461//
Steven Perron79a00642017-12-11 13:10:24 -0500462// Only shader modules with relaxed logical addressing (see opt/instruction.h)
463// are currently processed.
464//
GregF0c5722f2017-05-19 17:31:28 -0600465// This pass will reduce the work needed to be done by LocalSingleBlockElim
GregFcc8bad32017-06-16 15:37:31 -0600466// and LocalMultiStoreElim and can improve the effectiveness of other passes
467// such as DeadBranchElimination which depend on values for their analysis.
GregF0c5722f2017-05-19 17:31:28 -0600468Optimizer::PassToken CreateLocalSingleStoreElimPass();
469
GregF6136bf92017-05-26 10:33:11 -0600470// Creates an insert/extract elimination pass.
471// This pass processes each entry point function in the module, searching for
472// extracts on a sequence of inserts. It further searches the sequence for an
473// insert with indices identical to the extract. If such an insert can be
474// found before hitting a conflicting insert, the extract's result id is
475// replaced with the id of the values from the insert.
476//
477// Besides removing extracts this pass enables subsequent dead code elimination
478// passes to delete the inserts. This pass performs best after access chains are
479// converted to inserts and extracts and local loads and stores are eliminated.
480Optimizer::PassToken CreateInsertExtractElimPass();
481
GregFf28b1062018-01-26 17:05:33 -0700482// Creates a dead insert elimination pass.
483// This pass processes each entry point function in the module, searching for
484// unreferenced inserts into composite types. These are most often unused
485// stores to vector components. They are unused because they are never
486// referenced, or because there is another insert to the same component between
487// the insert and the reference. After removing the inserts, dead code
488// elimination is attempted on the inserted values.
489//
490// This pass performs best after access chains are converted to inserts and
491// extracts and local loads and stores are eliminated. While executing this
492// pass can be advantageous on its own, it is also advantageous to execute
493// this pass after CreateInsertExtractPass() as it will remove any unused
494// inserts created by that pass.
495Optimizer::PassToken CreateDeadInsertElimPass();
496
GregF9de4e692017-06-08 10:37:21 -0600497// Create aggressive dead code elimination pass
Alan Baker3a054e12017-12-18 12:13:10 -0500498// This pass eliminates unused code from the module. In addition,
GregF9de4e692017-06-08 10:37:21 -0600499// it detects and eliminates code which may have spurious uses but which do
500// not contribute to the output of the function. The most common cause of
501// such code sequences is summations in loops whose result is no longer used
502// due to dead code elimination. This optimization has additional compile
503// time cost over standard dead code elimination.
504//
505// This pass only processes entry point functions. It also only processes
Alan Baker3a054e12017-12-18 12:13:10 -0500506// shaders with relaxed logical addressing (see opt/instruction.h). It
507// currently will not process functions with function calls. Unreachable
508// functions are deleted.
GregF9de4e692017-06-08 10:37:21 -0600509//
510// This pass will be made more effective by first running passes that remove
511// dead control flow and inlines function calls.
512//
513// This pass can be especially useful after running Local Access Chain
514// Conversion, which tends to cause cycles of dead code to be left after
515// Store/Load elimination passes are completed. These cycles cannot be
516// eliminated with standard dead code elimination.
Greg Fischer4ac8e5e2021-09-15 12:38:34 -0600517//
518// If |preserve_interface| is true, all non-io variables in the entry point
519// interface are considered live and are not eliminated. This mode is needed
520// by GPU-Assisted validation instrumentation, where a change in the interface
521// is not allowed.
522Optimizer::PassToken CreateAggressiveDCEPass(bool preserve_interface = false);
GregF9de4e692017-06-08 10:37:21 -0600523
ZHOU Hef9893c42021-06-29 23:33:58 +0800524// Creates a remove-unused-interface-variables pass.
525// Removes variables referenced on the |OpEntryPoint| instruction that are not
526// referenced in the entry point function or any function in its call tree. Note
527// that this could cause the shader interface to no longer match other shader
528// stages.
529Optimizer::PassToken CreateRemoveUnusedInterfaceVariablesPass();
530
Jaebaek Seof7da5272020-10-30 18:03:56 -0400531// Creates an empty pass.
532// This is deprecated and will be removed.
533// TODO(jaebaek): remove this pass after handling glslang's broken unit tests.
534// https://github.com/KhronosGroup/glslang/pull/2440
535Optimizer::PassToken CreatePropagateLineInfoPass();
536
537// Creates an empty pass.
538// This is deprecated and will be removed.
539// TODO(jaebaek): remove this pass after handling glslang's broken unit tests.
540// https://github.com/KhronosGroup/glslang/pull/2440
541Optimizer::PassToken CreateRedundantLineInfoElimPass();
542
Andrey Tuganov1e309af2017-04-11 15:11:04 -0400543// Creates a compact ids pass.
544// The pass remaps result ids to a compact and gapless range starting from %1.
545Optimizer::PassToken CreateCompactIdsPass();
546
Pierre Moreau7183ad52018-01-03 01:54:55 +0100547// Creates a remove duplicate pass.
548// This pass removes various duplicates:
549// * duplicate capabilities;
550// * duplicate extended instruction imports;
551// * duplicate types;
552// * duplicate decorations.
Pierre Moreau86627f72017-07-13 02:16:51 +0200553Optimizer::PassToken CreateRemoveDuplicatesPass();
554
Diego Novilloc75704e2017-09-06 08:56:41 -0400555// Creates a CFG cleanup pass.
556// This pass removes cruft from the control flow graph of functions that are
557// reachable from entry points and exported functions. It currently includes the
558// following functionality:
559//
560// - Removal of unreachable basic blocks.
561Optimizer::PassToken CreateCFGCleanupPass();
562
Steven Perron58347192017-10-20 12:17:41 -0400563// Create dead variable elimination pass.
564// This pass will delete module scope variables, along with their decorations,
565// that are not referenced.
566Optimizer::PassToken CreateDeadVariableEliminationPass();
567
Steven Perronb3daa932018-03-06 11:20:28 -0500568// create merge return pass.
569// changes functions that have multiple return statements so they have a single
570// return statement.
Alan Bakera92d69b2017-11-08 16:22:10 -0500571//
Steven Perronb3daa932018-03-06 11:20:28 -0500572// for structured control flow it is assumed that the only unreachable blocks in
573// the function are trivial merge and continue blocks.
Alan Bakera92d69b2017-11-08 16:22:10 -0500574//
Steven Perronb3daa932018-03-06 11:20:28 -0500575// a trivial merge block contains the label and an opunreachable instructions,
576// nothing else. a trivial continue block contain a label and an opbranch to
577// the header, nothing else.
578//
579// these conditions are guaranteed to be met after running dead-branch
580// elimination.
Alan Bakera92d69b2017-11-08 16:22:10 -0500581Optimizer::PassToken CreateMergeReturnPass();
582
Steven Perron28c41552017-11-10 20:26:55 -0500583// Create value numbering pass.
584// This pass will look for instructions in the same basic block that compute the
585// same value, and remove the redundant ones.
586Optimizer::PassToken CreateLocalRedundancyEliminationPass();
Steven Perron5d602ab2017-12-04 12:29:51 -0500587
Alexander Johnston84ccd0b2018-01-29 10:39:55 +0000588// Create LICM pass.
589// This pass will look for invariant instructions inside loops and hoist them to
590// the loops preheader.
591Optimizer::PassToken CreateLoopInvariantCodeMotionPass();
592
Stephen McGroarty9a5dd6f2018-04-23 21:01:12 +0100593// Creates a loop fission pass.
594// This pass will split all top level loops whose register pressure exceedes the
595// given |threshold|.
596Optimizer::PassToken CreateLoopFissionPass(size_t threshold);
597
Toomas Remmelg1dc24582018-04-20 15:14:45 +0100598// Creates a loop fusion pass.
599// This pass will look for adjacent loops that are compatible and legal to be
600// fused. The fuse all such loops as long as the register usage for the fused
601// loop stays under the threshold defined by |max_registers_per_loop|.
602Optimizer::PassToken CreateLoopFusionPass(size_t max_registers_per_loop);
603
Victor Lomuller10e5d7c2018-03-29 12:22:42 +0100604// Creates a loop peeling pass.
605// This pass will look for conditions inside a loop that are true or false only
606// for the N first or last iteration. For loop with such condition, those N
607// iterations of the loop will be executed outside of the main loop.
608// To limit code size explosion, the loop peeling can only happen if the code
609// size growth for each loop is under |code_growth_threshold|.
610Optimizer::PassToken CreateLoopPeelingPass();
611
Victor Lomuller3497a942018-02-12 21:42:15 +0000612// Creates a loop unswitch pass.
613// This pass will look for loop independent branch conditions and move the
614// condition out of the loop and version the loop based on the taken branch.
615// Works best after LICM and local multi store elimination pass.
616Optimizer::PassToken CreateLoopUnswitchPass();
617
Steven Perron5d602ab2017-12-04 12:29:51 -0500618// Create global value numbering pass.
619// This pass will look for instructions where the same value is computed on all
620// paths leading to the instruction. Those instructions are deleted.
621Optimizer::PassToken CreateRedundancyEliminationPass();
Alan Baker867451f2017-11-30 17:03:06 -0500622
623// Create scalar replacement pass.
624// This pass replaces composite function scope variables with variables for each
Steven Perrona579e722018-04-16 09:58:00 -0400625// element if those elements are accessed individually. The parameter is a
626// limit on the number of members in the composite variable that the pass will
627// consider replacing.
628Optimizer::PassToken CreateScalarReplacementPass(uint32_t size_limit = 100);
Steven Perronb86eb682017-12-11 13:10:24 -0500629
630// Create a private to local pass.
631// This pass looks for variables delcared in the private storage class that are
632// used in only one function. Those variables are moved to the function storage
633// class in the function that they are used.
634Optimizer::PassToken CreatePrivateToLocalPass();
Diego Novillo4ba9dcc2017-12-05 11:39:25 -0500635
636// Creates a conditional constant propagation (CCP) pass.
637// This pass implements the SSA-CCP algorithm in
638//
639// Constant propagation with conditional branches,
640// Wegman and Zadeck, ACM TOPLAS 13(2):181-210.
641//
642// Constant values in expressions and conditional jumps are folded and
643// simplified. This may reduce code size by removing never executed jump targets
644// and computations with constant operands.
645Optimizer::PassToken CreateCCPPass();
646
Steven Perron34d42942018-01-17 14:57:37 -0500647// Creates a workaround driver bugs pass. This pass attempts to work around
648// a known driver bug (issue #1209) by identifying the bad code sequences and
649// rewriting them.
650//
651// Current workaround: Avoid OpUnreachable instructions in loops.
652Optimizer::PassToken CreateWorkaround1209Pass();
653
Alan Baker2e93e802018-01-16 11:15:06 -0500654// Creates a pass that converts if-then-else like assignments into OpSelect.
655Optimizer::PassToken CreateIfConversionPass();
656
Steven Perron61d8c032018-01-30 11:24:03 -0500657// Creates a pass that will replace instructions that are not valid for the
658// current shader stage by constants. Has no effect on non-shader modules.
659Optimizer::PassToken CreateReplaceInvalidOpcodePass();
660
Steven Perron06cdb962018-02-02 11:55:05 -0500661// Creates a pass that simplifies instructions using the instruction folder.
662Optimizer::PassToken CreateSimplificationPass();
663
Stephen McGroartydd8400e2018-02-14 17:03:12 +0000664// Create loop unroller pass.
Stephen McGroartye3549842018-02-27 11:50:08 +0000665// Creates a pass to unroll loops which have the "Unroll" loop control
Stephen McGroartydd8400e2018-02-14 17:03:12 +0000666// mask set. The loops must meet a specific criteria in order to be unrolled
667// safely this criteria is checked before doing the unroll by the
668// LoopUtils::CanPerformUnroll method. Any loop that does not meet the criteria
669// won't be unrolled. See CanPerformUnroll LoopUtils.h for more information.
Stephen McGroartye3549842018-02-27 11:50:08 +0000670Optimizer::PassToken CreateLoopUnrollPass(bool fully_unroll, int factor = 0);
Stephen McGroartydd8400e2018-02-14 17:03:12 +0000671
Diego Novillo735d8a52018-02-22 16:18:29 -0500672// Create the SSA rewrite pass.
673// This pass converts load/store operations on function local variables into
674// operations on SSA IDs. This allows SSA optimizers to act on these variables.
675// Only variables that are local to the function and of supported types are
676// processed (see IsSSATargetVar for details).
677Optimizer::PassToken CreateSSARewritePass();
678
greg-lunargd11725b2019-09-03 11:22:13 -0600679// Create pass to convert relaxed precision instructions to half precision.
680// This pass converts as many relaxed float32 arithmetic operations to half as
681// possible. It converts any float32 operands to half if needed. It converts
682// any resulting half precision values back to float32 as needed. No variables
683// are changed. No image operations are changed.
684//
greg-lunarg9215c1b2019-12-20 19:08:12 -0700685// Best if run after function scope store/load and composite operation
686// eliminations are run. Also best if followed by instruction simplification,
687// redundancy elimination and DCE.
greg-lunargd11725b2019-09-03 11:22:13 -0600688Optimizer::PassToken CreateConvertRelaxedToHalfPass();
689
690// Create relax float ops pass.
691// This pass decorates all float32 result instructions with RelaxedPrecision
692// if not already so decorated.
693Optimizer::PassToken CreateRelaxFloatOpsPass();
694
Steven Perronc4dc0462018-03-20 23:33:24 -0400695// Create copy propagate arrays pass.
696// This pass looks to copy propagate memory references for arrays. It looks
697// for specific code patterns to recognize array copies.
698Optimizer::PassToken CreateCopyPropagateArraysPass();
Steven Perron2c0ce872018-04-23 11:13:07 -0400699
700// Create a vector dce pass.
701// This pass looks for components of vectors that are unused, and removes them
702// from the vector. Note this would still leave around lots of dead code that
703// a pass of ADCE will be able to remove.
704Optimizer::PassToken CreateVectorDCEPass();
705
Steven Perronaf430ec2018-05-07 12:31:03 -0400706// Create a pass to reduce the size of loads.
707// This pass looks for loads of structures where only a few of its members are
708// used. It replaces the loads feeding an OpExtract with an OpAccessChain and
Jaebaek Seo0c092582021-09-02 10:45:51 -0400709// a load of the specific elements. The parameter is a threshold to determine
710// whether we have to replace the load or not. If the ratio of the used
711// components of the load is less than the threshold, we replace the load.
712Optimizer::PassToken CreateReduceLoadSizePass(
713 double load_replacement_threshold = 0.9);
Steven Perronaf430ec2018-05-07 12:31:03 -0400714
Alan Baker755e5c92018-07-23 11:23:11 -0400715// Create a pass to combine chained access chains.
716// This pass looks for access chains fed by other access chains and combines
717// them into a single instruction where possible.
718Optimizer::PassToken CreateCombineAccessChainsPass();
719
greg-lunarg1e9fc1a2018-11-08 11:54:54 -0700720// Create a pass to instrument bindless descriptor checking
721// This pass instruments all bindless references to check that descriptor
greg-lunarge1a76262019-03-19 06:53:43 -0700722// array indices are inbounds, and if the descriptor indexing extension is
723// enabled, that the descriptor has been initialized. If the reference is
724// invalid, a record is written to the debug output buffer (if space allows)
725// and a null value is returned. This pass is designed to support bindless
726// validation in the Vulkan validation layers.
727//
728// TODO(greg-lunarg): Add support for buffer references. Currently only does
729// checking for image references.
greg-lunarg1e9fc1a2018-11-08 11:54:54 -0700730//
731// Dead code elimination should be run after this pass as the original,
732// potentially invalid code is not removed and could cause undefined behavior,
733// including crashes. It may also be beneficial to run Simplification
734// (ie Constant Propagation), DeadBranchElim and BlockMerge after this pass to
735// optimize instrument code involving the testing of compile-time constants.
736// It is also generally recommended that this pass (and all
737// instrumentation passes) be run after any legalization and optimization
738// passes. This will give better analysis for the instrumentation and avoid
739// potentially de-optimizing the instrument code, for example, inlining
740// the debug record output function throughout the module.
741//
742// The instrumentation will read and write buffers in debug
743// descriptor set |desc_set|. It will write |shader_id| in each output record
744// to identify the shader module which generated the record.
greg-lunarg7046c052020-12-01 09:28:16 -0700745// |desc_length_enable| controls instrumentation of runtime descriptor array
746// references, |desc_init_enable| controls instrumentation of descriptor
747// initialization checking, and |buff_oob_enable| controls instrumentation
748// of storage and uniform buffer bounds checking, all of which require input
749// buffer support. |texbuff_oob_enable| controls instrumentation of texel
750// buffers, which does not require input buffer support.
greg-lunargcf211462019-02-07 12:00:36 -0700751Optimizer::PassToken CreateInstBindlessCheckPass(
greg-lunarg7046c052020-12-01 09:28:16 -0700752 uint32_t desc_set, uint32_t shader_id, bool desc_length_enable = false,
753 bool desc_init_enable = false, bool buff_oob_enable = false,
754 bool texbuff_oob_enable = false);
greg-lunarg1e9fc1a2018-11-08 11:54:54 -0700755
greg-lunarg06407252019-08-16 07:18:34 -0600756// Create a pass to instrument physical buffer address checking
757// This pass instruments all physical buffer address references to check that
758// all referenced bytes fall in a valid buffer. If the reference is
759// invalid, a record is written to the debug output buffer (if space allows)
760// and a null value is returned. This pass is designed to support buffer
761// address validation in the Vulkan validation layers.
762//
763// Dead code elimination should be run after this pass as the original,
764// potentially invalid code is not removed and could cause undefined behavior,
765// including crashes. Instruction simplification would likely also be
766// beneficial. It is also generally recommended that this pass (and all
767// instrumentation passes) be run after any legalization and optimization
768// passes. This will give better analysis for the instrumentation and avoid
769// potentially de-optimizing the instrument code, for example, inlining
770// the debug record output function throughout the module.
771//
772// The instrumentation will read and write buffers in debug
773// descriptor set |desc_set|. It will write |shader_id| in each output record
774// to identify the shader module which generated the record.
greg-lunarg06407252019-08-16 07:18:34 -0600775Optimizer::PassToken CreateInstBuffAddrCheckPass(uint32_t desc_set,
greg-lunarg44102722020-05-21 11:10:42 -0600776 uint32_t shader_id);
greg-lunarg06407252019-08-16 07:18:34 -0600777
greg-lunarg1fe9bcc2020-03-12 07:19:52 -0600778// Create a pass to instrument OpDebugPrintf instructions.
779// This pass replaces all OpDebugPrintf instructions with instructions to write
780// a record containing the string id and the all specified values into a special
781// printf output buffer (if space allows). This pass is designed to support
782// the printf validation in the Vulkan validation layers.
783//
784// The instrumentation will write buffers in debug descriptor set |desc_set|.
785// It will write |shader_id| in each output record to identify the shader
786// module which generated the record.
787Optimizer::PassToken CreateInstDebugPrintfPass(uint32_t desc_set,
788 uint32_t shader_id);
789
alan-bakere510b1b2018-11-30 14:15:51 -0500790// Create a pass to upgrade to the VulkanKHR memory model.
791// This pass upgrades the Logical GLSL450 memory model to Logical VulkanKHR.
792// Additionally, it modifies memory, image, atomic and barrier operations to
793// conform to that model's requirements.
794Optimizer::PassToken CreateUpgradeMemoryModelPass();
795
Steven Perrondd4157d2019-01-17 15:56:36 -0500796// Create a pass to do code sinking. Code sinking is a transformation
797// where an instruction is moved into a more deeply nested construct.
798Optimizer::PassToken CreateCodeSinkingPass();
799
Steven Perron3a0bc9e2019-04-05 13:12:08 -0400800// Create a pass to fix incorrect storage classes. In order to make code
801// generation simpler, DXC may generate code where the storage classes do not
802// match up correctly. This pass will fix the errors that it can.
803Optimizer::PassToken CreateFixStorageClassPass();
804
David Neto31590102019-07-30 19:52:46 -0400805// Creates a graphics robust access pass.
806//
807// This pass injects code to clamp indexed accesses to buffers and internal
808// arrays, providing guarantees satisfying Vulkan's robustBufferAccess rules.
809//
810// TODO(dneto): Clamps coordinates and sample index for pointer calculations
811// into storage images (OpImageTexelPointer). For an cube array image, it
812// assumes the maximum layer count times 6 is at most 0xffffffff.
813//
814// NOTE: This pass will fail with a message if:
815// - The module is not a Shader module.
816// - The module declares VariablePointers, VariablePointersStorageBuffer, or
817// RuntimeDescriptorArrayEXT capabilities.
818// - The module uses an addressing model other than Logical
819// - Access chain indices are wider than 64 bits.
820// - Access chain index for a struct is not an OpConstant integer or is out
821// of range. (The module is already invalid if that is the case.)
822// - TODO(dneto): The OpImageTexelPointer coordinate component is not 32-bits
823// wide.
David Netoaf741052019-12-03 11:18:56 -0500824//
825// NOTE: Access chain indices are always treated as signed integers. So
826// if an array has a fixed size of more than 2^31 elements, then elements
827// from 2^31 and above are never accessible with a 32-bit index,
828// signed or unsigned. For this case, this pass will clamp the index
829// between 0 and at 2^31-1, inclusive.
830// Similarly, if an array has more then 2^15 element and is accessed with
831// a 16-bit index, then elements from 2^15 and above are not accessible.
832// In this case, the pass will clamp the index between 0 and 2^15-1
833// inclusive.
David Neto31590102019-07-30 19:52:46 -0400834Optimizer::PassToken CreateGraphicsRobustAccessPass();
835
Steven Perron4b64beb2019-08-08 10:53:19 -0400836// Create descriptor scalar replacement pass.
837// This pass replaces every array variable |desc| that has a DescriptorSet and
838// Binding decorations with a new variable for each element of the array.
839// Suppose |desc| was bound at binding |b|. Then the variable corresponding to
840// |desc[i]| will have binding |b+i|. The descriptor set will be the same. It
841// is assumed that no other variable already has a binding that will used by one
842// of the new variables. If not, the pass will generate invalid Spir-V. All
843// accesses to |desc| must be OpAccessChain instructions with a literal index
844// for the first index.
845Optimizer::PassToken CreateDescriptorScalarReplacementPass();
846
alan-bakerf3cec932020-07-22 11:45:02 -0400847// Create a pass to replace each OpKill instruction with a function call to a
848// function that has a single OpKill. Also replace each OpTerminateInvocation
849// instruction with a function call to a function that has a single
850// OpTerminateInvocation. This allows more code to be inlined.
Steven Perron60043ed2019-08-14 09:27:12 -0400851Optimizer::PassToken CreateWrapOpKillPass();
852
Steven Perron35d98be2019-08-29 12:48:17 -0400853// Replaces the extensions VK_AMD_shader_ballot,VK_AMD_gcn_shader, and
854// VK_AMD_shader_trinary_minmax with equivalent code using core instructions and
855// capabilities.
856Optimizer::PassToken CreateAmdExtToKhrPass();
857
Greg Fischer48007a52021-03-31 12:26:36 -0600858// Replaces the internal version of GLSLstd450 InterpolateAt* extended
859// instructions with the externally valid version. The internal version allows
860// an OpLoad of the interpolant for the first argument. This pass removes the
861// OpLoad and replaces it with its pointer. glslang and possibly other
862// frontends will create the internal version for HLSL. This pass will be part
863// of HLSL legalization and should be called after interpolants have been
864// propagated into their final positions.
865Optimizer::PassToken CreateInterpolateFixupPass();
866
Jaebaek Seo57e1d8e2021-08-18 08:30:48 -0400867// Creates a convert-to-sampled-image pass to convert images and/or
868// samplers with given pairs of descriptor set and binding to sampled image.
869// If a pair of an image and a sampler have the same pair of descriptor set and
870// binding that is one of the given pairs, they will be converted to a sampled
871// image. In addition, if only an image has the descriptor set and binding that
872// is one of the given pairs, it will be converted to a sampled image as well.
873Optimizer::PassToken CreateConvertToSampledImagePass(
874 const std::vector<opt::DescriptorSetAndBinding>&
875 descriptor_set_binding_pairs);
876
Lei Zhangf18e1f22016-09-12 14:11:46 -0400877} // namespace spvtools
878
dan sinclair58a68762018-08-03 08:05:33 -0400879#endif // INCLUDE_SPIRV_TOOLS_OPTIMIZER_HPP_