Skip to content

Commit

Permalink
Consider dynamically indexed gl_Position in mesh.
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKristian-Work committed Jul 3, 2023
1 parent 601b60c commit 8ec95fb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifndef SPIRV_CROSS_CONSTANT_ID_0
#define SPIRV_CROSS_CONSTANT_ID_0 1
#endif
static const int spec_const_index = SPIRV_CROSS_CONSTANT_ID_0;
static const uint3 gl_WorkGroupSize = uint3(2u, 3u, 4u);

struct BlockOut
Expand Down Expand Up @@ -57,6 +61,8 @@ void mesh_main(inout gl_MeshPerVertexEXT gl_MeshVerticesEXT[24], inout uint3 gl_
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position.x = _46.x;
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position.z = _46.y;
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position.w = _46.z;
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position[gl_LocalInvocationIndex % 4u] = float(gl_GlobalInvocationID.z);
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position[spec_const_index] = spvFlipVertY(float(gl_GlobalInvocationID.z));
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_ClipDistance[0] = 4.0f;
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_CullDistance[0] = 3.0f;
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_CullDistance[1] = 5.0f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,27 @@ struct TaskPayload
int c;
};

layout(constant_id = 0) const int spec_const_index = 1;

taskPayloadSharedEXT TaskPayload payload;

void main()
{
SetMeshOutputsEXT(24, 22);

gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position = vec4(gl_GlobalInvocationID, 1.0);
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position.y = float(gl_WorkGroupID);
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position.xzw = vec3(gl_GlobalInvocationID);
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position = vec4(gl_GlobalInvocationID, 1.0);
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position.y = float(gl_WorkGroupID);
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position.xzw = vec3(gl_GlobalInvocationID);
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position[gl_LocalInvocationIndex % 4] = float(gl_GlobalInvocationID.z);
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position[spec_const_index] = float(gl_GlobalInvocationID.z);

gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_ClipDistance[0] = 4.0;
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_CullDistance[0] = 3.0;
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_CullDistance[1] = 5.0;
gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_CullDistance[1] = 5.0;

barrier();
if (gl_LocalInvocationIndex < 22)
{
gl_PrimitiveTriangleIndicesEXT[gl_LocalInvocationIndex] = uvec3(0, 1, 2) + gl_LocalInvocationIndex;
{
gl_PrimitiveTriangleIndicesEXT[gl_LocalInvocationIndex] = uvec3(0, 1, 2) + gl_LocalInvocationIndex;
}
}
15 changes: 10 additions & 5 deletions spirv_glsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10313,17 +10313,22 @@ string CompilerGLSL::access_chain_internal(uint32_t base, const uint32_t *indice

if (access_meshlet_position_y)
{
uint32_t id = 0;
if (is_literal)
{
id = index;
access_meshlet_position_y = index == 1;
}
else
{
auto &c = get<SPIRConstant>(index);
id = c.scalar();
const auto *c = maybe_get<SPIRConstant>(index);
if (c)
access_meshlet_position_y = c->scalar() == 1;
else
{
// We don't know, but we have to assume no.
// Flip Y in mesh shaders is an opt-in horrible hack, so we'll have to assume shaders try to behave.
access_meshlet_position_y = false;
}
}
access_meshlet_position_y = (id == 1);
}

expr += deferred_index;
Expand Down

0 comments on commit 8ec95fb

Please sign in to comment.