[SPIR-V] SPV_NV_mesh_shader can produce invalid SPIR-V

未关闭
#9,037 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
领域
compilers

调研方向

Start from the SPIR-V emission of mesh-shader DispatchMesh (the OpStore to TaskCountNV, which currently flattens xyz), the LocalSize execution mode for MeshNV, and the BuiltIn CullPrimitiveEXT decoration for SV_CullPrimitive. Reproduce with the three HLSL snippets using -spirv with the NV target. Done means each case gets a clear diagnostic under NV and the EXT path still compiles with -fspv-target-env=vulkan1.3.

由索引模型根据 Issue 内容生成。

描述

bug needs-triage spirv

Description
[SPIR-V] SPV_NV_mesh_shader accepts 2-D/3-D dispatch and SV_CullPrimitive, producing wrong or invalid SPIR-V
When DXC emits SPV_NV_mesh_shader, three inputs that NV can't represent are not diagnosed:

1. DispatchMesh(x, y, z)  with y or z != 1. GL_NV_mesh_shader launches a one-dimensional array of tasks, and TaskCountNV is a scalar. DXC's SPIR-V back-end flattens the arguments to  xyz , so the mesh shader's SV_GroupID is silently wrong whenever y - z > 1.
2. numthreads with Y or Z != 1 in mesh or amplification shaders. GL_NV_mesh_shader guarantees a work group size of only 1 in Y and Z, and calls its workgroups one-dimensional. glslang rejects NV local_size_y/local_size_z greater than 1, but DXC is emitting LocalSize 8 4 1 .
3. SV_CullPrimitive. NV has no per-primitive cull built-in. DXC emits BuiltIn CullPrimitiveEXT without the EXT capability and fails SPIR-V validation with a "please file a bug report" fatal error.

Steps to Reproduce

// as.hlsl — dxc -T as_6_5 -E main -spirv as.hlsl
struct Payload { uint x; };
groupshared Payload p;
[numthreads(1, 1, 1)]
void main() {
  p.x = 0;
  DispatchMesh(2, 3, 1, p);
}

// ms_nt.hlsl — dxc -T ms_6_5 -E main -spirv ms_nt.hlsl
struct VertOut { float4 pos : SV_Position; };
[outputtopology("triangle")]
[numthreads(8, 4, 1)]
void main(uint3 tid : SV_GroupThreadID,
          out vertices VertOut verts[32], out indices uint3 tris[32]) {
  SetMeshOutputCounts(32, 32);
  uint i = tid.y * 8 + tid.x;
  verts[i].pos = float4(tid, 1);
  tris[i] = uint3(0, 1, 2);
}

// ms_cull.hlsl — dxc -T ms_6_5 -E main -spirv ms_cull.hlsl
struct VertOut { float4 pos : SV_Position; };
struct PrimOut { bool cull : SV_CullPrimitive; };
[outputtopology("triangle")]
[numthreads(1, 1, 1)]
void main(out vertices VertOut verts[3], out indices uint3 tris[1],
          out primitives PrimOut prims[1]) {
  SetMeshOutputCounts(3, 1);
  verts[0].pos = float4(0, 0, 0, 1);
  tris[0] = uint3(0, 1, 2);
  prims[0].cull = false;
}

Actual Behavior

  1. Compiles. OpStore %TaskCountNV %uint_6 launches 6 tasks in one dimension, so the mesh shader sees SV_GroupID = (0..5, 0, 0) instead of a 2×3 grid.
  2. Compiles, emitting OpExecutionMode %main LocalSize 8 4 1 for MeshNV.
  3. Fails:
fatal error: generated SPIR-V is invalid: Operand 3 of Decorate requires one of these capabilities: MeshShadingEXT
  OpDecorate %4 BuiltIn CullPrimitiveEXT
note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues ...

Expected: clear errors under NV for all three. Each compiles with  -fspv-target-env=vulkan1.3 , which selects EXT.

Environment

  • DXC version 1.10.2609.0
  • Host Operating System Windows
主要语言
C++
星标
3.7k
派生
926
平均合并
3 天 22 小时
30 天内合并 PR
45

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/DirectXShaderCompiler 的其他 Issue

查看 microsoft/DirectXShaderCompiler 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。