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 WaveGetLaneCount HLSL Function #99159

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

Implement the WaveGetLaneCount HLSL Function #99159

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 WaveGetLaneCount clang builtin,
  • Link WaveGetLaneCount clang builtin with hlsl_intrinsics.h
  • Add sema checks for WaveGetLaneCount to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for WaveGetLaneCount to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/WaveGetLaneCount.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/WaveGetLaneCount-errors.hlsl
  • Create the int_dx_WaveGetLaneCount intrinsic in IntrinsicsDirectX.td
  • Create the DXILOpMapping of int_dx_WaveGetLaneCount to 112 in DXIL.td
  • Create the WaveGetLaneCount.ll and WaveGetLaneCount_errors.ll tests in llvm/test/CodeGen/DirectX/
  • Create the int_spv_WaveGetLaneCount intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the WaveGetLaneCount lowering and map it to int_spv_WaveGetLaneCount in SPIRVInstructionSelector::selectIntrinsic.
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveGetLaneCount.ll

DirectX

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

SPIR-V

SubgroupSize

Short Description

SubgroupSize - Size of a subgroup

Description

SubgroupSize

Decorating a variable with the SubgroupSize builtin decoration will
make that variable contain the implementation-dependent number of invocations in a subgroup .
This value must be a power-of-two integer.

If the pipeline was created with the
VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT flag
set, or the shader object was created with the
VK_SHADER_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT flag set, or
the SPIR-V module is at least version 1.6, the SubgroupSize
decorated variable will contain the subgroup size for each subgroup that
gets dispatched. This value must be between minSubgroupSize and maxSubgroupSize and
must be uniform with subgroup scope . The value may
vary across a single draw call, and for fragment shaders may vary
across a single primitive. In compute dispatches, SubgroupSize
must be uniform with command scope .

If the pipeline was created with a chained
VkPipelineShaderStageRequiredSubgroupSizeCreateInfo
structure, or the shader object was created with a chained
VkShaderRequiredSubgroupSizeCreateInfoEXT
structure, the SubgroupSize decorated variable will match requiredSubgroupSize .

If SPIR-V module is less than version 1.6 and the pipeline was not
created with the
VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT flag
set and no
VkPipelineShaderStageRequiredSubgroupSizeCreateInfo
structure was chained, and the shader was not created with the
VK_SHADER_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT flag set and no
VkShaderRequiredSubgroupSizeCreateInfoEXT
structure was chained, the variable decorated with SubgroupSize will
match subgroupSize .

The maximum number of invocations that an implementation can support per
subgroup is 128.

Note

The old behavior for SubgroupSize is considered deprecated as certain compute algorithms cannot be easily implemented without the guarantees of VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT and VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT .

Valid Usage


  • VUID-SubgroupSize-SubgroupSize-04382

    The variable decorated with SubgroupSize must be declared
    using the Input Storage Class


  • VUID-SubgroupSize-SubgroupSize-04383

    The variable decorated with SubgroupSize must be declared as a
    scalar 32-bit integer value

Test Case(s)

Example 1

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

export uint fn() {
    return WaveGetLaneCount();
}

SPIRV Example(s):

Example 2

//dxc WaveGetLaneCount_spirv_test.hlsl -T ps_6_8 -E fn -enable-16bit-types -spirv -fspv-target-env=universal1.5 -fcgl -O0


uint fn( ) : SV_Target {

	return WaveGetLaneCount();
}

HLSL:

Returns the number of lanes in a wave on this architecture.

Syntax

uint WaveGetLaneCount(void);

Parameters

This function has no parameters.

Return value

The result will be between 4 and 128, and includes all waves: active, inactive, and/or helper lanes. The result returned from this function may vary significantly depending on the driver implementation.

Remarks

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

 

Examples

 uint laneCount = WaveGetLaneCount();    // number of lanes in wave

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