The SPIR-V optimiser spirv-opt includes the option --trim-capabilities, which should do the following.
Remove unnecessary capabilities and extensions declared within the module.
However, if the StorageBuffer16BitAccess capability is declared and used in a SPIR-V module, this optimisation removes it regardless. Here's the assembly of a module test.spvasm.
The StorageBuffer16BitAccess capability has been removed, despite the module declaring the 16-bit integer type, converting a 32-bit integer value to 16-bit, and storing a 16-bit integer value into a storage buffer. This is also recognised by the SPIR-V validator, which when run on this module,
spirv-val --target-env spv1.6 test2.spv
gives the following output.
error: line 9: Using a 16-bit integer type requires the Int16 capability, or an extension that explicitly enables 16-bit integers.
%ushort = OpTypeInt 16 0
All SPIRV-Tools used (spirv-as, spirv-dis, spirv-opt, and spirv-val) give the following --version.
The SPIR-V optimiser
spirv-opt
includes the option--trim-capabilities
, which should do the following.However, if the
StorageBuffer16BitAccess
capability is declared and used in a SPIR-V module, this optimisation removes it regardless. Here's the assembly of a moduletest.spvasm
.This module converts a 32-bit unsigned value to 16-bit, and writes the result into a storage buffer. If you assemble this into SPIR-V 1.6,
then apply the
--trim-capabilities
optimisation,and then disassemble the optimised SPIR-V,
you get the following assembly of the module
test2.spvasm
(minus some tidying up).The
StorageBuffer16BitAccess
capability has been removed, despite the module declaring the 16-bit integer type, converting a 32-bit integer value to 16-bit, and storing a 16-bit integer value into a storage buffer. This is also recognised by the SPIR-V validator, which when run on this module,gives the following output.
All SPIRV-Tools used (
spirv-as
,spirv-dis
,spirv-opt
, andspirv-val
) give the following--version
.