DirectXShaderCompiler
DirectXShaderCompiler copied to clipboard
[SPIR-V] Bugs when write to out vertices in mesh shader
when compiling mesh shader code like this into spir_v, it fails to write to gl_Position, producing black image
void MSMain(
uint dtid : SV_DispatchThreadID,
uint gtid : SV_GroupThreadID,
uint gid : SV_GroupID,
uint tig : SV_GroupIndex,
in payload TaskPayload s_Payload,
out vertices VSOutput verts[MAX_VERTEX_NUM],
out indices uint3 tris[MAX_PRIMITIVE_NUM])
{
verts[local_thread_id].Pos= transformtoNDC(position);
GroupMemoryBarrier();
/* some calculation read from verts[local_thread_id].Pos*/
GroupMemoryBarrier();
verts[local_thread_id] = doStuff ( verts[local_thread_id].SV_POSITION);
}
the compiled code, captured from NSight, create a temp param_var_verts, but failed to write to it
uint _152[32] = in_var_meshLetId;
uint _158 = _152[gl_WorkGroupID.x];
MeshletInfo _160 = ce_MeshLetInfos._m0[_158];
uint _166 = (_160.mVertexCount + 31u) / 32u;
VSOutput param_var_verts[64];
....
uint _210 = ((_202 * cbMesh.ce_VertexStride) + uint(cbMesh.ce_PositionOffset.x)) >> 2u;
vec4 _233 = ((vec4(uintBitsToFloat(uvec3(ce_Vertices._m0[_210], ce_Vertices._m0[_210 + 1u], ce_Vertices._m0[_210 + 2u])), 1.0) * cbModel.ce_World) * cbPassMeta.ce_View) * cbPassMeta.ce_Projection;
vec4 _236 = _233;
_236.y = -_233.y;
gl_out[_175].gl_Position = _236;
// nevery write to param_var_verts, but read from
float _242 = -param_var_verts[_175].Pos.w;
ndcVertexCullBits[_175] = ((((((0u | uint(param_var_verts[_175].Pos.x < _242)) | ((param_var_verts[_175].Pos.x > param_var_verts[_175].Pos.w) ? 2u : 0u)) | ((param_var_verts[_175].Pos.y < _242) ? 4u : 0u)) | ((param_var_verts[_175].Pos.y > param_var_verts[_175].Pos.w) ? 8u : 0u)) | ((param_var_verts[_175].Pos.z < 0.0) ? 16u : 0u)) | ((param_var_verts[_175].Pos.z > param_var_verts[_175].Pos.w) ? 32u : 0u)) | ((param_var_verts[_175].Pos.w <= 0.0) ? 64u : 0u);
local_to_global[_175] = _202;
GroupMemoryBarrier();
// read from param_var_verts[_175].Pos.w
GroupMemoryBarrier();
// read from param_var_verts[_175].Pos.w
gl_out[_388].gl_Position = param_var_verts[_388].Pos;
Thanks for reporting, @CgGraphic. Would you be able to provide a minimal reproducer with all the definitions necessary to compile it, together with your full compiler invocation command?
Without a sample that we can compile this issue isn't feasible to reproduce. Closing this issue for now but we'd be happy to re-open it if complete repro steps are provided.