slang
slang copied to clipboard
[CTS] SPIR-V Validation failure, "Expected Image Operand ConstOffset to be a const object"
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