Skip to content

Commit 108b19e

Browse files
Add --canonicalize-ids pass (KhronosGroup#6174)
This is a port of the spirv-remap utility in glslang. The canonicalize IDs pass is an optimization to improve compression of SPIR-V binary files via entropy reduction. It transforms SPIR-V to SPIR-V, remapping IDs. The resulting modules have an increased ID range (IDs are not as tightly packed around zero), but will compress better when multiple modules are compressed together, since the compressor's dictionary can find better cross module commonality. Remapping is accomplished via canonicalization. Thus, modules can be compressed one at a time with no loss of quality relative to operating on many modules at once. This pass should be run after most optimization passes except for --strip-debug because this pass will use OpName to canonicalize IDs. i.e. Run --strip-debug after this pass.
1 parent 8560756 commit 108b19e

File tree

11 files changed

+2677
-0
lines changed

11 files changed

+2677
-0
lines changed

Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ SPVTOOLS_OPT_SRC_FILES := \
169169
source/opt/redundancy_elimination.cpp \
170170
source/opt/register_pressure.cpp \
171171
source/opt/relax_float_ops_pass.cpp \
172+
source/opt/canonicalize_ids_pass.cpp \
172173
source/opt/remove_dontinline_pass.cpp \
173174
source/opt/remove_duplicates_pass.cpp \
174175
source/opt/remove_unused_interface_variables_pass.cpp \

BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,8 @@ static_library("spvtools_opt") {
581581
"source/opt/remove_duplicates_pass.h",
582582
"source/opt/remove_unused_interface_variables_pass.cpp",
583583
"source/opt/remove_unused_interface_variables_pass.h",
584+
"source/opt/canonicalize_ids_pass.h",
585+
"source/opt/canonicalize_ids_pass.cpp",
584586
"source/opt/replace_desc_array_access_using_var_index.cpp",
585587
"source/opt/replace_desc_array_access_using_var_index.h",
586588
"source/opt/replace_invalid_opc.cpp",

include/spirv-tools/optimizer.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,16 @@ Optimizer::PassToken CreateSplitCombinedImageSamplerPass();
10221022
// This pass assumes binding numbers are not applid via decoration groups
10231023
// (OpDecorationGroup).
10241024
Optimizer::PassToken CreateResolveBindingConflictsPass();
1025+
1026+
// Create a pass to canonicalize IDs to improve compression of SPIR-V binary
1027+
// files. The resulting modules have an increased ID range (IDs are not as
1028+
// tightly packed around zero), but will compress better when multiple modules
1029+
// are compressed together, since the compressor's dictionary can find better
1030+
// cross module commonality. This pass should be run after most optimization
1031+
// passes except for
1032+
// --strip-debug because this pass will use OpName to canonicalize IDs. i.e. Run
1033+
// --strip-debug after this pass.
1034+
Optimizer::PassToken CreateCanonicalizeIdsPass();
10251035
} // namespace spvtools
10261036

10271037
#endif // INCLUDE_SPIRV_TOOLS_OPTIMIZER_HPP_

source/opt/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ set(SPIRV_TOOLS_OPT_SOURCES
104104
reflect.h
105105
register_pressure.h
106106
relax_float_ops_pass.h
107+
canonicalize_ids_pass.h
107108
remove_dontinline_pass.h
108109
remove_duplicates_pass.h
109110
remove_unused_interface_variables_pass.h
@@ -222,6 +223,7 @@ set(SPIRV_TOOLS_OPT_SOURCES
222223
redundancy_elimination.cpp
223224
register_pressure.cpp
224225
relax_float_ops_pass.cpp
226+
canonicalize_ids_pass.cpp
225227
remove_dontinline_pass.cpp
226228
remove_duplicates_pass.cpp
227229
remove_unused_interface_variables_pass.cpp

0 commit comments

Comments
 (0)