Skip to content

Implement the QuadReadAcrossY HLSL Function #99176

@farzonl

Description

@farzonl
  • Implement QuadReadAcrossY clang builtin,
  • Link QuadReadAcrossY clang builtin with hlsl_intrinsics.h
  • Add sema checks for QuadReadAcrossY to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for QuadReadAcrossY to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/QuadReadAcrossY.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/QuadReadAcrossY-errors.hlsl
  • Create the int_dx_QuadReadAcrossY intrinsic in IntrinsicsDirectX.td
  • Create the DXILOpMapping of int_dx_QuadReadAcrossY to 123 in DXIL.td
  • Create the QuadReadAcrossY.ll and QuadReadAcrossY_errors.ll tests in llvm/test/CodeGen/DirectX/
  • Create the int_spv_QuadReadAcrossY intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the QuadReadAcrossY lowering and map it to int_spv_QuadReadAcrossY in SPIRVInstructionSelector::selectIntrinsic.
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/QuadReadAcrossY.ll

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
123 QuadOp 6.0 ('library', 'compute', 'amplification', 'mesh', 'pixel', 'node')

SPIR-V

OpGroupNonUniformQuadSwap:

Description:

Swap the Value of the invocation within the
quad with another invocation in the quad using Direction.

Result Type must be a scalar or vector of floating-point
type
, integer type, or Boolean
type
.

Execution is a Scope, but has no effect on the
behavior of this instruction. It must be Subgroup.

The type of Value must be the same as Result Type.

Direction is the kind of swap to perform.

Direction must be a scalar of integer type, whose
Signedness operand is 0.

Direction must come from a constant
instruction
.

The value returned in Result is the value provided to Value by
another invocation in the same quad scope instance. The invocation
providing this value is determined according to Direction.

A Direction of 0 indicates a horizontal swap;

  • Invocations with quad indices of 0 and 1 swap values
  • Invocations with quad indices of 2 and 3 swap values
    A Direction of 1 indicates a vertical swap;
  • Invocations with quad indices of 0 and 2 swap values
  • Invocations with quad indices of 1 and 3 swap values
    A Direction of 2 indicates a diagonal swap;
  • Invocations with quad indices of 0 and 3 swap values
  • Invocations with quad indices of 1 and 2 swap values

Direction must be one of the above values.

If an active invocation reads Value from an inactive invocation, the
resulting value is undefined.

Capability:
GroupNonUniformQuad

Missing before version 1.3.

Word Count Opcode Results Operands

6

366

<id>
Result Type

Result <id>

Scope <id>
Execution

<id>
Value

<id>
Direction

Test Case(s)

Example 1

//dxc QuadReadAcrossY_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export float4 fn(float4 p1) {
    return QuadReadAcrossY(p1);
}

Example 2

//dxc QuadReadAcrossY_1_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export uint4 fn(uint4 p1) {
    return QuadReadAcrossY(p1);
}

Example 3

//dxc QuadReadAcrossY_2_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export int4 fn(int4 p1) {
    return QuadReadAcrossY(p1);
}

HLSL:

Returns the specified source value read from the other lane in this quad in the Y direction.

Syntax

<type> QuadReadAcrossY(
   <type> localValue
);

Parameters

localValue

The requested type.

Return value

The specified source value. If the source lane is inactive, the results are undefined.

Remarks

For more information on quads, refer to Overview of Shader Model 6.

This function is supported from shader model 6.0 only in pixel and compute shaders.

 

See also

Shader Model 6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions