Skip to content

v0.22.3

Choose a tag to compare

@kolkov kolkov released this 16 Nov 10:40
· 26 commits to main since this release

The GLSL input frontend ships as a preview. glsl.Parse reads a large part of Vulkan GLSL 440/450/460
and of the GL 3.30 core / ES 3.00 dialects, and every form it accepts is verified end to end (see below),
but the frontend is not complete: a few subgroup forms the IR cannot express are refused with named
limitations (subgroupElect, subgroupAllEqual, the ballot bit helpers and the gl_Subgroup*Mask
variables, and the clustered forms); the Min/Max/And/Or/Xor scans stay refused until the text backends write
them; and the ParseInfo / ParseOptions shape may still change until the frontend is complete. The
refusals list the limits rather than lowering a source the IR cannot express.

Added

  • GLSL frontend: the subgroup built-in variables (NAGA-FEAT-002, card P2-GLSLIN-027). The four scalar
    variables of GL_KHR_shader_subgroup_basic — gl_SubgroupSize, gl_SubgroupInvocationID, gl_SubgroupID
    and gl_NumSubgroups (GLSL 4.60 §8.18) — lower onto the IR's BuiltinSubgroupSize,
    BuiltinSubgroupInvocationID, BuiltinSubgroupID and BuiltinNumSubgroups as private u32 globals bound as
    entry-point arguments, which is what glslang compiles (input variables decorated SubgroupSize,
    SubgroupLocalInvocationId, SubgroupId, NumSubgroups). Availability follows the subgroup builtins':
    the basic family's extension must be enabled (glslang: "'gl_SubgroupSize' : required extension not
    requested: GL_KHR_shader_subgroup_basic") and GLSL ES before 3.10 has no subgroup operations. The ballot
    family's mask variables (gl_SubgroupEqMask and siblings) stay refused with a message naming the missing
    IR value, and the remaining subgroup gaps (elect, all-equal, the ballot bit operations, the clustered forms)
    are recorded on the new card P2-IR-038 with glslang's SPIR-V shape for each and what every backend would
    need — they require an IR design before v1.0, not a frontend patch.

  • GLSL frontend: textureQueryLod (NAGA-FEAT-002, card P1-GLSLIN-012). The level-of-detail query of GLSL
    4.00 §8.9 is accepted where glslangValidator accepts it — the 1D, 2D, 3D, cube, 1D-array, 2D-array and
    cube-array sampled, depth (shadow) and integer sampler classes, with the spatial coordinate and without the
    array layer — through the combined-sampler split, in a fragment shader only (SPIR-V's OpImageQueryLod is
    fragment-stage only). The GL 3.30 core and ES 3.00 dialects refuse it with the version rule, as does any
    multisampled sampler (no GLSL overload exists). The IR gains ir.ImageQueryLod, carrying the query's sampler
    and coordinate because SPIR-V, MSL and HLSL need both and the IR has no sampled-image value; it is a recorded
    deviation from Rust naga, whose IR has no level-of-detail query. The SPIR-V backend writes
    OpImageQueryLod on an OpSampledImage (Capability ImageQuery), the MSL backend
    calculate_clamped_lod/calculate_unclamped_lod packed into a float2 (MSL 2.2; 1D textures are refused —
    Metal has no such query for them), the HLSL backend CalculateLevelOfDetail/CalculateLevelOfDetailUnclamped
    in a float2 wrapper (depth images need shader model 6.8 for a comparison sampler and non-float sampled
    images have no such method, so both are refused), and the GLSL backend textureQueryLod (desktop GLSL 4.00+,
    never ES: glslangValidator happens to accept it at 3.30, but the specification declares it at 4.00 and the
    writer refuses a target the driver would reject). A 16-row matrix runs every accepted form through
    glslangValidator, spirv-val, MSL, dxc and the GLSL round trip, pins the SPIR-V shape to glslang's, and
    asserts each backend's refusals.

Fixed

  • DXIL: an image query's own operands are counted, so the reassociation pass sees them (found while
    landing textureQueryLod). The writer's operand collector returned only the query's image, so the level of
    an imageQuerySize (pre-existing) and the sampler and coordinate of a textureQueryLod were invisible to
    the pass's use counting — a query whose operands nothing else read could be treated as dead. The collector
    now walks the query's every operand, in both walkers, pinned by a unit test.

  • MSL: a vector operand to a subgroup collective is written as one scalar simd call per component instead
    of a call on the vector, which Metal rejects
    (card P2-GLSLIN-028). Metal's simd_sum/simd_min/… take
    and return scalars, while the subgroup operation on a vector is defined per component (SPIR-V's
    OpGroupNonUniformFAdd on a vector type reduces each component independently, which glslang emits); the
    writer now evaluates the operand once and expands the call per component, with the result rebuilt into the
    vector. The HLSL and SPIR-V writers already carried vectors (dxc compiles WaveActiveSum on vectors), and
    three matrix rows run the vector forms through glslang, spirv-val, MSL, HLSL and the GLSL round trip.

  • GLSL frontend: four declaration rules are enforced instead of accepted silently (NAGA-FEAT-002, cards
    P2-GLSLIN-023..026).

    • A storage image whose declared class contradicts its layout(...) format is refused at the qualifier with
      glslang's wording — iimage2D takes signed integer formats, uimage2D unsigned integer ones, image2D
      the floating-point and normalized ones (GLSL 4.60 §4.4.8: "It is a compile-time error to declare an image
      variable where the format qualifier does not match the image variable type"). Before, the format replaced
      the placeholder and the declared class was dropped, so layout(r32ui) uniform iimage2D img; lowered with
      the wrong sign.
    • A shared variable with an initializer is refused (GLSL 4.60 §4.3.8: "Variables declared as shared may
      not have initializers"); before, the initializer was lowered as if the GL model gave shared storage a
      defined starting value.
    • A user declaration of a name beginning with the reserved gl_ prefix is refused at every declaration
      site — module-scope and local variables, parameters, functions, block type names, block instances and
      block members, named blocks' members included (GLSL 4.60 §3.7). The builtins keep resolving, and struct
      type names and
      struct members stay accepted: the reservation covers names declared as variables and functions, and
      glslang accepts struct gl_S { float gl_y; }; in both its GL and Vulkan modes. A predeclared builtin's
      redeclaration (layout(origin_upper_left) in vec4 gl_FragCoord;) is refused with the same message — the
      frontend does not model builtin redeclarations, and refusing beats the silent location input it used to
      become.
    • A repeated module-scope name is refused with glslang's 'a' : redefinition. One table now holds every
      module-scope declaration — plain uniforms collected into the default block, interface blocks' instances
      and instance-less members, opaque resources, combined image samplers, module-scope constants and
      variables. Before, the later declaration won silently while the earlier one's references still resolved
      to it. A local that shadows a module-scope name stays legal, and the members of a block declared with an
      instance name stay out of the table — GLSL scopes them to the instance, and glslang accepts two such
      blocks with a member of the same name.
    • Every refusal was probed against glslangValidator 11:16.2.0 and is pinned by a unit test and the new
      24-row declaration-rules matrix (glslang, spirv-val, MSL, HLSL and the GLSL round trip on the accepted
      forms); the image matrix gained the four class/format refusal rows. The atomic upgrade's
      initializer guard can no longer be reached from source — the declaration refusal fires first, with one
      diagnostic — and stays as a defensive check of the IR invariant.
  • MSL: a subgroup scan of Min, Max, And, Or or Xor is refused instead of being silently written as a
    reduction.
    The MSL writer mapped those operations to simd_min/simd_max/simd_and/simd_or/simd_xor
    without looking at the collective operation, so an InclusiveScan or ExclusiveScan — reachable today from
    SPIR-V input through OpGroupNonUniform* with a scan group operation — compiled to a plain reduction: the
    shader built and returned the wrong value. Metal has no prefix form for these operations, so the writer now
    refuses the scan with a message naming the gap. The reductions are unchanged, and the Add and Mul scans keep
    their simd_prefix_* forms. The GLSL frontend keeps refusing the scans, with its message updated to match.