Skip to content

Implement the WaveActiveProduct HLSL Function #99165

@farzonl

Description

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

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
119 WaveActiveOp 6.0 ('library', 'compute', 'amplification', 'mesh', 'pixel', 'vertex', 'hull', 'domain', 'geometry', 'raygeneration', 'intersection', 'anyhit', 'closesthit', 'miss', 'callable', 'node')

SPIR-V

OpGroupNonUniformFMul:

Description:

A floating point multiply group operation of all
Value operands contributed by active invocations in the
group.

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

Execution is a Scope that identifies the group of
invocations affected by this command. It must be Subgroup.

The identity I for Operation is 1. If Operation is
ClusteredReduce, ClusterSize must be present.

The type of Value must be the same as Result Type. The method used
to perform the group operation on the contributed Value(s) from active
invocations is implementation defined.

ClusterSize is the size of cluster to use. ClusterSize must be a
scalar of integer type, whose Signedness operand is 0.
ClusterSize must come from a constant
instruction
. Behavior is undefined unless
ClusterSize is at least 1 and a power of 2. If ClusterSize is
greater than the size of the group, executing this instruction
results in undefined behavior.

Capability:
GroupNonUniformArithmetic, GroupNonUniformClustered,
GroupNonUniformPartitionedNV

Missing before version 1.3.

Word Count Opcode Results Operands

6 + variable

352

<id>
Result Type

Result <id>

Scope <id>
Execution

Group Operation
Operation

<id>
Value

Optional
<id>
ClusterSize

Test Case(s)

Example 1

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

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

Example 2

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

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

Example 3

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

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

HLSL:

Multiplies the values of the expression together across all active lanes in the current wave and replicates it back to all active lanes.

Syntax

<type> WaveActiveProduct(
   <type> expr
);

Parameters

expr

The expression to evaluate.

Return value

The product value.

Remarks

The order of operations is undefined.

This function is supported from shader model 6.0 in all shader stages.

 

See also

Overview of Shader Model 6

Shader Model 6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions