具有相同 操作數參數的非結構類型(標量,向量,數組等)不能是類型別名。對於非結構, 兩種類型
<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