代码之家  ›  专栏  ›  技术社区  ›  Maik Klein

SPIR-V中的哪些类型不允许为类型别名?

  •  1
  • Maik Klein  · 技术社区  · 8 年前

    操作数参数化不能是类型别名。对于非结构, 两种类型 <id>

    #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

    这条规则在哪里适用?

    1 回复  |  直到 8 年前
        1
  •  1
  •   krOoze    8 年前

    我的猜测是,验证规则的措辞很不幸,并引用了这一点( 2.8. Types and Variables of SPIR-V specification

    <id> 根据定义,s形式有两种不同的类型。声明多个是有效的 总数的 类型 < 装饰 不同地(不需要不同的装饰;两种不同的骨料类型 < 允许具有相同的声明和修饰,并且仍然是两种不同的类型。)非聚合类型不同:声明多个类型无效 <id> s表示相同的标量、向量或矩阵类型。也就是说,非聚合类型声明都必须具有不同的操作码或操作数。(请注意,非聚合类型不能以影响其类型的方式进行修饰。)

    但也有不同之处。E、 例如,“非聚集”(即非结构+非数组)与“非结构”。

    OpTypeInt id=1 bits=32 sign=0 // OK OpTypeInt id=1 bits=32 sign=1 // ERROR -- redefined result id OpTypeInt id=2 bits=32 sign=0 // ERROR -- uint32 already defined as id 1 OpTypeInt id=3 bits=32 sign=1 // OK

    我在您的人类可读SPIR-V示例中没有发现违反此规则的情况。

    推荐文章