KhronosGroup / KhronosGroup/glslang

SPIR-V: Converting ivec4 to u8vec4 triggers validation error

Open
#2,179 0 comments 0 reactions 1 assignee Claimed by @arcady-lunarg View on GitHub
bug GLSL/ESSL SPIR-V
Dominant language
C++
Stars
3.6k
Forks
989
Avg merge
1d 2h
Merged PRs (30d)
31

Description

```
#version 450
#extension GL_EXT_shader_8bit_storage : require
layout(local_size_x = 1) in;

struct Foo
{
ivec4 a;
};

struct FooMem
{
u8vec4 a;
};

layout(set = 0, binding = 0, std430) buffer SSBO
{
FooMem mem;
};

void main()
{
Foo foo;
foo.a = ivec4(10);
mem.a = u8vec4(foo.a);
}
```
generates
```
// Module Version 10000
// Generated by (magic number): 80008
// Id's are bound by 37

Capability Shader
Capability UniformAndStorageBuffer8BitAccess
Extension "SPV_KHR_8bit_storage"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint GLCompute 4 "main"
ExecutionMode 4 LocalSize 1 1 1
Source GLSL 450
SourceExtension "GL_EXT_shader_8bit_storage"
Name 4 "main"
Name 8 "Foo"
MemberName 8(Foo) 0 "a"
Name 10 "foo"
Name 18 "FooMem"
MemberName 18(FooMem) 0 "a"
Name 19 "SSBO"
MemberName 19(SSBO) 0 "mem"
Name 21 ""
MemberDecorate 18(FooMem) 0 Offset 0
MemberDecorate 19(SSBO) 0 Offset 0
Decorate 19(SSBO) BufferBlock
Decorate 21 DescriptorSet 0
Decorate 21 Binding 0
Decorate 36 BuiltIn WorkgroupSize
2: TypeVoid
3: TypeFunction 2
6: TypeInt 32 1
7: TypeVector 6(int) 4
8(Foo): TypeStruct 7(ivec4)
9: TypePointer Function 8(Foo)
11: 6(int) Constant 0
12: 6(int) Constant 10
13: 7(ivec4) ConstantComposite 12 12 12 12
14: TypePointer Function 7(ivec4)
16: TypeInt 8 0
17: TypeVector 16(int8_t) 4
18(FooMem): TypeStruct 17(i8vec4)
19(SSBO): TypeStruct 18(FooMem)
20: TypePointer Uniform 19(SSBO)
21: 20(ptr) Variable Uniform
24: TypeInt 32 0
25: TypeVector 24(int) 4
32: TypePointer Uniform 17(i8vec4)
34: TypeVector 24(int) 3
35: 24(int) Constant 1
36: 34(ivec3) ConstantComposite 35 35 35
4(main): 2 Function None 3
5: Label
10(foo): 9(ptr) Variable Function
15: 14(ptr) AccessChain 10(foo) 11
Store 15 13
22: 14(ptr) AccessChain 10(foo) 11
23: 7(ivec4) Load 22
26: 24(int) CompositeExtract 23 0
27: 24(int) CompositeExtract 23 1
28: 24(int) CompositeExtract 23 2
29: 24(int) CompositeExtract 23 3
30: 25(ivec4) CompositeConstruct 26 27 28 29
31: 17(i8vec4) UConvert 30
33: 32(ptr) AccessChain 21 11 11
Store 33 31
Return
FunctionEnd
```
which triggers validation error:
```
error: line 54: Result type (OpTypeInt) does not match the type that results from indexing into the composite (OpTypeInt).
%26 = OpCompositeExtract %uint %23 0
```
This happens because the composite extract extracts values as uint rather than int. Needs a bitcast here.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.