具有相同 操作数参数的非结构类型(标量,向量,数组等)不能是类型别名。对于非结构, 两种类型
<id>
只匹配 - 如果类型匹配。SPIR-V中的哪些类型不允许为别名?
这是什么意思?
#version 400
void main()
{
uint a = 4;
uint b = 5;
}
编译这个着色器glslang结果
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 1
; Bound: 12
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %main "main"
OpSource GLSL 400
OpName %main "main"
OpName %a "a"
OpName %b "b"
%void = OpTypeVoid
%3 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%_ptr_Function_uint = OpTypePointer Function %uint
%uint_4 = OpConstant %uint 4
%uint_5 = OpConstant %uint 5
%main = OpFunction %void None %3
%5 = OpLabel
%a = OpVariable %_ptr_Function_uint Function
%b = OpVariable %_ptr_Function_uint Function
OpStore %a %uint_4
OpStore %b %uint_5
OpReturn
OpFunctionEnd
这里%uint = OpTypeInt 32 0
多次使用和%_ptr_Function_uint
也使用两次。
这条规则甚至适用于哪里?
我的猜测:这意味着例如int和uint不能相同,即使它们可能具有相同的大小。对于float来说更是如此,你不能把float看作int,就像c,float f; int i = *((int *)&f)得到它的位。 – starmole