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

Loop getting optimized out in mesh shader #3401

Closed
Dynamitos opened this issue Dec 11, 2023 · 3 comments
Closed

Loop getting optimized out in mesh shader #3401

Dynamitos opened this issue Dec 11, 2023 · 3 comments
Assignees
Labels
goal:client support Needed to support a slang use case kind:bug something doesn't work like it should priority:high required for next milestone

Comments

@Dynamitos
Copy link
Contributor

When declaring a simple loop to output data from a mesh shader, the loop completely disappears when outputting glsl code (probably also for other targets, but I can't read spriv-asm and nothing is shown on screen).

Example modified from the test cases:

const static float2 positions[3] = {
  float2(0.0, -0.5),
  float2(0.5, 0.5),
  float2(-0.5, 0.5)
};

const static float3 colors[3] = {
  float3(1.0, 1.0, 0.0),
  float3(0.0, 1.0, 1.0),
  float3(1.0, 0.0, 1.0)
};
struct Vertex
{
  float4 pos : SV_Position;
  float3 color : Color;
  int index : Index;
};

const static uint MAX_VERTS = 12;
const static uint MAX_PRIMS = 4;

[outputtopology("triangle")]
[shader("mesh")]
[numthreads(3, 1, 1)]
void meshMain(
    in uint tig : SV_GroupIndex,
    out Vertices<Vertex, MAX_VERTS> verts,
    out Indices<uint3, MAX_PRIMS> triangles)
{
    const uint numVertices = 12;
    const uint numPrimitives = 4;
    SetMeshOutputCounts(numVertices, numPrimitives);

    for(uint i = tig; i < numVertices; ++i)
    {
        const int tri = i / 3;
        verts[i] = {float4(positions[i % 3], 0, 1), colors[i % 3], tri};
    }

    for(uint i = tig; i < numPrimitives; ++i)
    {
        triangles[i] = i * 3 + uint3(0,1,2);
    }
}

To test, i compiled this on the commandline with: slangc.exe test.slang -profile sm_6_6 -target glsl -entry meshMain -capability spirv_1_5 -o test.glsl

#version 450
#extension GL_EXT_mesh_shader : require
layout(row_major) uniform;
layout(row_major) buffer;

#line 27 0
layout(local_size_x = 3, local_size_y = 1, local_size_z = 1) in;
layout(max_vertices = 12) out;
layout(max_primitives = 4) out;
layout(triangles) out;
void main()
{

    SetMeshOutputsEXT(12U, 4U);

#line 46
    return;
}
@csyonghe
Copy link
Collaborator

@expipiplus1 This should be fixed in tandem with #2804.
The Vertices type should not be semantically an out parameter, and its subscript operator should map to a dedicated instruction that will be treated by the compiler as an external memory object and therefore DCE shouldn't apply to any read/writes on that location.

@csyonghe csyonghe added this to the Q1 2024 (Winter) milestone Dec 12, 2023
@csyonghe csyonghe added priority:high required for next milestone kind:bug something doesn't work like it should labels Dec 12, 2023
@natduca
Copy link

natduca commented Dec 13, 2023

@csyonghe looks like #2804 is put for Q3 , should we move 2804 into Q1, too?

@csyonghe
Copy link
Collaborator

Moved #2804 to Q1.

@swoods-nv swoods-nv added the goal:client support Needed to support a slang use case label Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:client support Needed to support a slang use case kind:bug something doesn't work like it should priority:high required for next milestone
Projects
None yet
Development

No branches or pull requests

5 participants