Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the WavePrefixProduct HLSL Function #99173

Open
12 tasks
Tracked by #99235
farzonl opened this issue Jul 16, 2024 · 0 comments
Open
12 tasks
Tracked by #99235

Implement the WavePrefixProduct HLSL Function #99173

farzonl opened this issue Jul 16, 2024 · 0 comments
Labels
backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.

Comments

@farzonl
Copy link
Member

farzonl commented Jul 16, 2024

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

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
121 WavePrefixOp 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 WavePrefixProduct_test.hlsl -T lib_6_8 -enable-16bit-types -O0

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

Example 2

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

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

Example 3

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

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

HLSL:

Returns the product of all of the values in the active lanes in this wave with indices less than this lane.

Syntax

<type> WavePrefixProduct(
   <type> value
);

Parameters

value

The value to multiply.

Return value

The product of all the values.

Remarks

The order of operations on this routine cannot be guaranteed. So, effectively, the [precise] flag is ignored within it.

A postfix product can be computed by multiplying the prefix product by the current lane's value.

Note that the active lane with the lowest index will always receive a 1 for its prefix product.

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

Examples

uint numToMultiply = 2;
uint prefixProduct = WavePrefixProduct( numToMultiply );

On a machine with a wave size of 8, and all lanes active except lanes 0 and 4, the following values would be returned from WavePrefixProduct.

lane index status prefixProduct
0 inactive n/a
1 active = 1
2 active = 1*2
3 active = 1*2*2
4 inactive n/a
5 active = 1*2*2*2
6 active = 1*2*2*2*2
7 active = 1*2*2*2*2*2

See also

Overview of Shader Model 6

Shader Model 6

@farzonl farzonl added backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues. labels Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.
Projects
Status: No status
Development

No branches or pull requests

1 participant