KhronosGroup / SPIRV-Tools

Apache License 2.0
1.09k stars 559 forks source link

VariablePointer Capability Not Removed by `--trim-capabilities` #5854

Open cwfitzgerald opened 1 month ago

cwfitzgerald commented 1 month ago

The following spirv, generated by slang, doesn't appear to use the VariablePointer cap or extension at all. Manually removing it passes spirv-val, but calling spirv-opt with --trim-capabilities doesn't actually remove it.

; SPIR-V
; Version: 1.5
; Generator: Khronos; 40
; Bound: 18
; Schema: 0
OpCapability VariablePointers
OpCapability PhysicalStorageBufferAddresses
OpCapability Shader
OpExtension "SPV_KHR_variable_pointers"
OpExtension "SPV_KHR_physical_storage_buffer"
OpMemoryModel PhysicalStorageBuffer64 GLSL450
OpEntryPoint GLCompute %computeMain "main" %globalParams
OpExecutionMode %computeMain LocalSize 4 1 1

; Debug Information
OpSource Slang 1
OpName %GlobalParams_std140 "GlobalParams_std140"   ; id %5
OpMemberName %GlobalParams_std140 0 "value"
OpName %globalParams "globalParams"                 ; id %9
OpName %computeMain "computeMain"                   ; id %2

; Annotations
OpDecorate %_ptr_PhysicalStorageBuffer_uint ArrayStride 4
OpDecorate %GlobalParams_std140 Block
OpMemberDecorate %GlobalParams_std140 0 Offset 0
OpDecorate %globalParams Binding 0
OpDecorate %globalParams DescriptorSet 0

; Types, variables and constants
%void = OpTypeVoid
%3 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%_ptr_PhysicalStorageBuffer_uint = OpTypePointer PhysicalStorageBuffer %uint    ; ArrayStride 4
%GlobalParams_std140 = OpTypeStruct %_ptr_PhysicalStorageBuffer_uint            ; Block
%_ptr_Uniform_GlobalParams_std140 = OpTypePointer Uniform %GlobalParams_std140
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%_ptr_Uniform__ptr_PhysicalStorageBuffer_uint = OpTypePointer Uniform %_ptr_PhysicalStorageBuffer_uint
%uint_2 = OpConstant %uint 2
%globalParams = OpVariable %_ptr_Uniform_GlobalParams_std140 Uniform    ; Binding 0, DescriptorSet 0

; Function computeMain
%computeMain = OpFunction %void None %3
%4 = OpLabel
%13 = OpAccessChain %_ptr_Uniform__ptr_PhysicalStorageBuffer_uint %globalParams %int_0
%14 = OpLoad %_ptr_PhysicalStorageBuffer_uint %13
OpStore %14 %uint_2 Aligned 4
OpReturn
OpFunctionEnd