KhronosGroup / KhronosGroup/SPIRV-Tools

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

Open
#5,854 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.4k
Forks
709
Avg merge
1d 22h
Merged PRs (30d)
28

Description

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.

```spvasm
; 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
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided SPIR-V input with spirv-opt --trim-capabilities, then validate the result with spirv-val. Trace the trim-capabilities pass and its handling of VariablePointers and SPV_KHR_variable_pointers; done means the unused capability and extension are removed without validation failures.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.