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 SetMeshOutputCounts HLSL Function #99231

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

Implement the SetMeshOutputCounts HLSL Function #99231

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

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
168 SetMeshOutputCounts 6.5 ('mesh',)

SPIR-V

OpSetMeshOutputsEXT:

Description:

Reserved.

Capability:
MeshShadingEXT

Reserved.

Word Count Opcode Results Operands

3

5295

<id>
Vertex Count

<id>
Primitive Count

Test Case(s)

Example 1

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

[numthreads(1, 1, 1)]
[outputtopology("triangle")]
[shader("mesh")]
void fn(in uint gi : SV_GroupIndex, in uint vi : SV_ViewID) {

SetMeshOutputCounts(1, 1);
}

SPIRV Example(s):

Example 2

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

struct MeshPerVertex {
	float4 position : SV_Position;
};
[numthreads(1, 1, 1)]
[outputtopology("triangle")]
[shader("mesh")]
void fn(in uint gi : SV_GroupIndex, in uint vi : SV_ViewID,
	out vertices MeshPerVertex verts[3], out indices uint3 primitiveInd[3]) {

SetMeshOutputCounts(1, 1);
}

HLSL:

This function sets the actual number of outputs from the threadgroup.

Syntax

void SetMeshOutputCounts(
    uint numVertices,
    uint numPrimitives);

Remarks

At the beginning of the shader the implementation internally sets a
count of vertices and primitives to be exported from a threadgroup to 0.
It means that if a mesh shader returns without calling this function,
it will not output any mesh. This function sets the actual number of
outputs from the threadgroup.

Some restrictions on the function use and interactions with output arrays follow.

  1. This function can only be called once per shader.

  2. This call must occur before any writes to any of the
    shared output arrays.
    The validator will verify this is the case.

  3. If the compiler can prove that this function is not called,
    then the threadgroup doesn't have any output.
    If the shader writes to any of the
    shared output arrays,
    compilation and shader validation will fail.
    If the shader does not call any of these functions,
    the compiler will issue a warning,
    and no rasterization work will be issued.

  4. Only the input values from the first active thread are used.

  5. This call must dominate all writes to
    shared output arrays.
    In other words, there must not be any execution path
    that even appears to reach any writes to any output array
    without first having executed this call.

@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