Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CTS] SPIR-V Validation failure, "Expected Image Operand ConstOffset to be a const object" #5339

Closed
jkwak-work opened this issue Oct 17, 2024 · 5 comments · Fixed by #5426
Closed
Assignees
Labels
goal:forward looking Feature needed at a later date, not connected to a specific use case. kind:bug something doesn't work like it should

Comments

@jkwak-work
Copy link
Collaborator

Three CTS tests are occasionally causing the crash of deqp-vk.exe.

dEQP-VK.glsl.texture_gather.offset.implementation_offset.2d.rgba8.size_pot.clamp_to_edge_repeat
dEQP-VK.glsl.texture_gather.offset.implementation_offset.2d.rgba8.size_pot.mirrored_repeat_clamp_to_edge
dEQP-VK.glsl.texture_gather.offset.implementation_offset.2d.rgba8.size_pot.repeat_mirrored_repeat

When the validation is enabled, those tests fail with the following message,

Expected Image Operand ConstOffset to be a const objec

A simple repro is following,

#extension GL_EXT_gpu_shader5 : require

layout (location = 0) out mediump vec4 o_color;

layout (location = 0) in highp vec2 v_texCoord;

layout (binding = 0) uniform highp sampler2D u_sampler;
layout (binding = 1) uniform offset { highp ivec2 u_offset; };

void main(void)
{
                o_color = textureGatherOffset(u_sampler, v_texCoord, u_offset);
}

When the shader above is stored as test.slang, observe the validation error with the following command,

$ slangc.exe -target spirv -entry main -stage fragment -allow-glsl test.slang

error: line 53: Expected Image Operand ConstOffset to be a const object
  %29 = OpImageGather %v4float %24 %27 %int_0 ConstOffset %21

(0): internal error 99999: Validation of generated SPIR-V failed. SPIRV generated:
; SPIR-V
; Version: 1.5
; Generator: Khronos; 40
; Bound: 37
; Schema: 0
               OpCapability Shader
               OpMemoryModel Logical GLSL450
               OpEntryPoint Fragment %main "main" %11 %offset %u_sampler %31 %entryPointParam_main_o_color %v_texCoord
               OpExecutionMode %main OriginUpperLeft

               ; Debug Information
               OpSource Slang 1
               OpName %v_texCoord "v_texCoord"  ; id %9
               OpName %SLANG_ParameterGroup_offset_std140 "SLANG_ParameterGroup_offset_std140"  ; id %13
               OpMemberName %SLANG_ParameterGroup_offset_std140 0 "u_offset"
               OpName %offset "offset"  ; id %17
               OpName %u_sampler "u_sampler"  ; id %26
               OpName %entryPointParam_main_o_color "entryPointParam_main.o_color"  ; id %34
               OpName %main "main"  ; id %2

               ; Annotations
               OpDecorate %v_texCoord Location 0
               OpDecorate %SLANG_ParameterGroup_offset_std140 Block
               OpMemberDecorate %SLANG_ParameterGroup_offset_std140 0 Offset 0
               OpDecorate %offset Binding 1
               OpDecorate %offset DescriptorSet 0
               OpDecorate %u_sampler Binding 0
               OpDecorate %u_sampler DescriptorSet 0
               OpDecorate %entryPointParam_main_o_color Location 0

               ; Types, variables and constants
       %void = OpTypeVoid
          %3 = OpTypeFunction %void
      %float = OpTypeFloat 32
    %v2float = OpTypeVector %float 2
%_ptr_Input_v2float = OpTypePointer Input %v2float
%_ptr_Private_v2float = OpTypePointer Private %v2float
        %int = OpTypeInt 32 1
      %v2int = OpTypeVector %int 2
%SLANG_ParameterGroup_offset_std140 = OpTypeStruct %v2int
%_ptr_Uniform_SLANG_ParameterGroup_offset_std140 = OpTypePointer Uniform %SLANG_ParameterGroup_offset_std140
      %int_0 = OpConstant %int 0
%_ptr_Uniform_v2int = OpTypePointer Uniform %v2int
         %22 = OpTypeImage %float 2D 2 0 0 1 Unknown
         %23 = OpTypeSampledImage %22
%_ptr_UniformConstant_23 = OpTypePointer UniformConstant %23
    %v4float = OpTypeVector %float 4
%_ptr_Private_v4float = OpTypePointer Private %v4float
%_ptr_Output_v4float = OpTypePointer Output %v4float
 %v_texCoord = OpVariable %_ptr_Input_v2float Input
         %11 = OpVariable %_ptr_Private_v2float Private
     %offset = OpVariable %_ptr_Uniform_SLANG_ParameterGroup_offset_std140 Uniform
  %u_sampler = OpVariable %_ptr_UniformConstant_23 UniformConstant
         %31 = OpVariable %_ptr_Private_v4float Private
%entryPointParam_main_o_color = OpVariable %_ptr_Output_v4float Output

               ; Function main
       %main = OpFunction %void None %3
          %4 = OpLabel
          %7 = OpLoad %v2float %v_texCoord
               OpStore %11 %7
         %20 = OpAccessChain %_ptr_Uniform_v2int %offset %int_0
         %21 = OpLoad %v2int %20
         %24 = OpLoad %23 %u_sampler
         %27 = OpLoad %v2float %v_texCoord
         %29 = OpImageGather %v4float %24 %27 %int_0 ConstOffset %21
               OpStore %31 %29
               OpStore %entryPointParam_main_o_color %29
               OpReturn
               OpFunctionEnd
@jkwak-work jkwak-work added kind:bug something doesn't work like it should goal:forward looking Feature needed at a later date, not connected to a specific use case. labels Oct 17, 2024
@jkwak-work
Copy link
Collaborator Author

Due to this problem, the following tests are currently disabled for the nightly CTS test.

dEQP-VK.glsl.texture_gather.offset.implementation_offset.2d.rgba8.size_pot.clamp_to_edge_repeat
dEQP-VK.glsl.texture_gather.offset.implementation_offset.2d.rgba8.size_pot.mirrored_repeat_clamp_to_edge
dEQP-VK.glsl.texture_gather.offset.implementation_offset.2d.rgba8.size_pot.repeat_mirrored_repeat

Once the problem is resolved, we should re-enabled them back.

@jkwak-work
Copy link
Collaborator Author

I think the problem is on the fact that ConstOffset is used when it should be just Offset

@csyonghe
Copy link
Collaborator

seems like should be easy to fix.

@bmillsNV bmillsNV added this to the Q4 2024 (Fall) milestone Oct 18, 2024
@jkwak-work
Copy link
Collaborator Author

jkwak-work commented Oct 28, 2024

I found it interesting that all of the offset variants of GLSL textureXXX functions require the offset value to be a compile-time constant value except for textureGatherOffset().

The GLSL spec says,

(textureGatherOffset) Perform a texture gather operation as in
textureGather by offset as described in
textureOffset except that the offset can be
variable (non constant)

When textureGatherOffset is converted to SPIR-V code, it uses OpImageGather instruction with Offset option.
In this case, it has to use ImageGatherExtended capability.

Note that OpImageGather is also available with ConstOffset option if the offset value is known at the compile-time.
In this case, it doesn't need ImageGatherExtended capability.

@jkwak-work
Copy link
Collaborator Author

A note for myself here.
Once the fix is merged, I need to re-enable three tests on the nightly CTS test that was disabled by shader-slang/VK-GL-CTS#7

dEQP-VK.glsl.texture_gather.offset.implementation_offset.2d.rgba8.size_pot.clamp_to_edge_repeat
dEQP-VK.glsl.texture_gather.offset.implementation_offset.2d.rgba8.size_pot.mirrored_repeat_clamp_to_edge
dEQP-VK.glsl.texture_gather.offset.implementation_offset.2d.rgba8.size_pot.repeat_mirrored_repeat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:forward looking Feature needed at a later date, not connected to a specific use case. kind:bug something doesn't work like it should
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants