Skip to content

[spiv-val] Miscompiled SPIR-V is crashing the validator #2463

@godlikepanos

Description

@godlikepanos

Hi,

The GL_KHR_vulkan_glsl extension requires that combining a sampled image and a sampler happens at the point of the texture call. At the moment glslang doesn't check that and produces invalid SPIR-V. The validator is crashing when fed that SPIR-V.

Google probably requires a robust and crash-free validator that can be used for WebGPU. So you might want to fix this.

This is the GLSL shader (incorrect according to GL_KHR_vulkan_glsl):

#version 450 core

layout(local_size_x = 8, local_size_y = 8, local_size_z = 8) in;

layout(set = 0, binding = 1) uniform texture3D u_noiseTex;
layout(set = 0, binding = 2) uniform sampler u_linearAnyRepeatSampler;

sampler3D combineImageSampler(texture3D tex, sampler sampl)
{
	return sampler3D(tex, sampl);
}

void main()
{
	vec3 uv = vec3(0);
	vec4 col = textureLod(combineImageSampler(u_noiseTex, u_linearAnyRepeatSampler), uv, 0.0);
}

And this is the generated SPIR-V that is crashing the validator:

; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 7
; Bound: 39
; Schema: 0
               OpCapability Shader
          %1 = OpExtInstImport "GLSL.std.450"
               OpMemoryModel Logical GLSL450
               OpEntryPoint GLCompute %main "main"
               OpExecutionMode %main LocalSize 8 8 8
               OpSource GLSL 450
               OpName %main "main"
               OpName %combineImageSampler_t31_p1_ "combineImageSampler(t31;p1;"
               OpName %tex "tex"
               OpName %sampl "sampl"
               OpName %uv "uv"
               OpName %col "col"
               OpName %u_noiseTex "u_noiseTex"
               OpName %u_linearAnyRepeatSampler "u_linearAnyRepeatSampler"
               OpDecorate %u_noiseTex DescriptorSet 0
               OpDecorate %u_noiseTex Binding 1
               OpDecorate %u_linearAnyRepeatSampler DescriptorSet 0
               OpDecorate %u_linearAnyRepeatSampler Binding 2
               OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize
       %void = OpTypeVoid
          %3 = OpTypeFunction %void
      %float = OpTypeFloat 32
          %7 = OpTypeImage %float 3D 0 0 0 1 Unknown
%_ptr_UniformConstant_7 = OpTypePointer UniformConstant %7
          %9 = OpTypeSampler
%_ptr_UniformConstant_9 = OpTypePointer UniformConstant %9
         %11 = OpTypeSampledImage %7
         %12 = OpTypeFunction %11 %_ptr_UniformConstant_7 %_ptr_UniformConstant_9
    %v3float = OpTypeVector %float 3
%_ptr_Function_v3float = OpTypePointer Function %v3float
    %float_0 = OpConstant %float 0
         %26 = OpConstantComposite %v3float %float_0 %float_0 %float_0
    %v4float = OpTypeVector %float 4
%_ptr_Function_v4float = OpTypePointer Function %v4float
 %u_noiseTex = OpVariable %_ptr_UniformConstant_7 UniformConstant
%u_linearAnyRepeatSampler = OpVariable %_ptr_UniformConstant_9 UniformConstant
       %uint = OpTypeInt 32 0
     %v3uint = OpTypeVector %uint 3
     %uint_8 = OpConstant %uint 8
%gl_WorkGroupSize = OpConstantComposite %v3uint %uint_8 %uint_8 %uint_8
       %main = OpFunction %void None %3
          %5 = OpLabel
         %uv = OpVariable %_ptr_Function_v3float Function
        %col = OpVariable %_ptr_Function_v4float Function
               OpStore %uv %26
         %32 = OpFunctionCall %11 %combineImageSampler_t31_p1_ %u_noiseTex %u_linearAnyRepeatSampler
         %33 = OpLoad %v3float %uv
         %34 = OpImageSampleExplicitLod %v4float %32 %33 Lod %float_0
               OpStore %col %34
               OpReturn
               OpFunctionEnd
%combineImageSampler_t31_p1_ = OpFunction %11 None %12
        %tex = OpFunctionParameter %_ptr_UniformConstant_7
      %sampl = OpFunctionParameter %_ptr_UniformConstant_9
         %16 = OpLabel
         %17 = OpLoad %7 %tex
         %18 = OpLoad %9 %sampl
         %19 = OpSampledImage %11 %17 %18
               OpReturnValue %19
               OpFunctionEnd

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions