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

SPIR-V for matrix multiplication that produces an error when gl_ObjectToWorldEXT and gl_WorldToObject3x4EXT are used in the same shader #3680

Open
wuhuandi opened this issue Jul 30, 2024 · 0 comments

Comments

@wuhuandi
Copy link

Hello, we are using the version 14.3.0 glslang tool to convert to spv, when testing the following shader, we found that the shader semantics appeared in the 4x3 matrix multiplied by the 4x3 matrix spv semantics, this matrix multiplication is illegal, Is this a known issue with glslang?

%26 is obtained when the 4x3 * 4x3 matrix multiplication

#version 460
#extension GL_EXT_ray_tracing : enable
#extension GL_EXT_nonuniform_qualifier : enable
layout(location = 0) rayPayloadInEXT vec3 hitValue;
hitAttributeEXT vec3 attribs;
void main()
{
mat4 res1 = gl_WorldToObject3x4EXT * gl_ObjectToWorldEXT;
mat4 res2 = gl_ObjectToWorld3x4EXT * gl_WorldToObjectEXT;
const vec3 barycentricCoords = vec3(1.0f - attribs.x - attribs.y, attribs.x, attribs.y);
vec4 hitTemp = vec4(barycentricCoords, 1.0);
hitValue = vec3(res1 * res2 * hitTemp);
}

; SPIR-V
; Version: 1.5
; Generator: Khronos Glslang Reference Front End; 11
; Bound: 65
; Schema: 0
OpCapability RayTracingKHR
OpExtension "SPV_KHR_ray_tracing"
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint ClosestHitNV %main "main" %gl_WorldToObject3x4EXT %gl_ObjectToWorldEXT %attribs %hitValue
OpSource GLSL 460
OpSourceExtension "GL_EXT_nonuniform_qualifier"
OpSourceExtension "GL_EXT_ray_tracing"
OpName %main "main"
OpName %res1 "res1"
OpName %gl_WorldToObject3x4EXT "gl_WorldToObject3x4EXT"
OpName %gl_ObjectToWorldEXT "gl_ObjectToWorldEXT"
OpName %res2 "res2"
OpName %barycentricCoords "barycentricCoords"
OpName %attribs "attribs"
OpName %hitTemp "hitTemp"
OpName %hitValue "hitValue"
OpDecorate %gl_WorldToObject3x4EXT BuiltIn WorldToObjectNV
OpDecorate %gl_ObjectToWorldEXT BuiltIn ObjectToWorldNV
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%mat4v4float = OpTypeMatrix %v4float 4
%_ptr_Function_mat4v4float = OpTypePointer Function %mat4v4float
%v3float = OpTypeVector %float 3
%mat4v3float = OpTypeMatrix %v3float 4
%mat3v4float = OpTypeMatrix %v4float 3
%_ptr_Input_mat4v3float = OpTypePointer Input %mat4v3float
%gl_WorldToObject3x4EXT = OpVariable %_ptr_Input_mat4v3float Input
%gl_ObjectToWorldEXT = OpVariable %_ptr_Input_mat4v3float Input
%_ptr_Function_v3float = OpTypePointer Function %v3float
%float_1 = OpConstant %float 1
%_ptr_HitAttributeNV_v3float = OpTypePointer HitAttributeNV %v3float
%attribs = OpVariable %_ptr_HitAttributeNV_v3float HitAttributeNV
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_HitAttributeNV_float = OpTypePointer HitAttributeNV %float
%uint_1 = OpConstant %uint 1
%_ptr_Function_v4float = OpTypePointer Function %v4float
%_ptr_IncomingRayPayloadNV_v3float = OpTypePointer IncomingRayPayloadNV %v3float
%hitValue = OpVariable %_ptr_IncomingRayPayloadNV_v3float IncomingRayPayloadNV
%main = OpFunction %void None %3
%5 = OpLabel
%res1 = OpVariable %_ptr_Function_mat4v4float Function
%res2 = OpVariable %_ptr_Function_mat4v4float Function
%barycentricCoords = OpVariable %_ptr_Function_v3float Function
%hitTemp = OpVariable %_ptr_Function_v4float Function
%16 = OpLoad %mat4v3float %gl_WorldToObject3x4EXT
%17 = OpTranspose %mat3v4float %16
%19 = OpLoad %mat4v3float %gl_ObjectToWorldEXT
%20 = OpMatrixTimesMatrix %mat4v4float %17 %19
OpStore %res1 %20
%22 = OpLoad %mat4v3float %gl_ObjectToWorldEXT
%23 = OpTranspose %mat3v4float %22
%24 = OpLoad %mat4v3float %gl_WorldToObject3x4EXT
%25 = OpTranspose %mat3v4float %24

%26 = OpMatrixTimesMatrix %mat4v4float %23 %25
OpStore %res2 %26
%35 = OpAccessChain %_ptr_HitAttributeNV_float %attribs %uint_0
%36 = OpLoad %float %35
%37 = OpFSub %float %float_1 %36
%39 = OpAccessChain %_ptr_HitAttributeNV_float %attribs %uint_1
%40 = OpLoad %float %39
%41 = OpFSub %float %37 %40
%42 = OpAccessChain %_ptr_HitAttributeNV_float %attribs %uint_0
%43 = OpLoad %float %42
%44 = OpAccessChain %_ptr_HitAttributeNV_float %attribs %uint_1
%45 = OpLoad %float %44
%46 = OpCompositeConstruct %v3float %41 %43 %45
OpStore %barycentricCoords %46
%49 = OpLoad %v3float %barycentricCoords
%50 = OpCompositeExtract %float %49 0
%51 = OpCompositeExtract %float %49 1
%52 = OpCompositeExtract %float %49 2
%53 = OpCompositeConstruct %v4float %50 %51 %52 %float_1
OpStore %hitTemp %53
%56 = OpLoad %mat4v4float %res1
%57 = OpLoad %mat4v4float %res2
%58 = OpMatrixTimesMatrix %mat4v4float %56 %57
%59 = OpLoad %v4float %hitTemp
%60 = OpMatrixTimesVector %v4float %58 %59
%61 = OpCompositeExtract %float %60 0
%62 = OpCompositeExtract %float %60 1
%63 = OpCompositeExtract %float %60 2
%64 = OpCompositeConstruct %v3float %61 %62 %63
OpStore %hitValue %64
OpReturn
OpFunctionEnd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants