This commit is contained in:
xsl
2025-09-04 10:54:47 +08:00
commit 6bc8f61b18
1808 changed files with 208268 additions and 0 deletions
@@ -0,0 +1,25 @@
#version 450
/* Copyright (c) 2023, Holochip Corporation
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
layout(location = 3) in vec3 inColor;
layout(location = 0) out vec4 outColor;
void main()
{
outColor = vec4(inColor, 1.0);
}
@@ -0,0 +1,62 @@
#version 450
/* Copyright (c) 2023-2025, Holochip Corporation
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#extension GL_EXT_mesh_shader: require
#extension GL_GOOGLE_include_directive: require
#include "mesh_shader_shared.h"
layout(local_size_x = numMeshInvocationsX, local_size_y = numMeshInvocationsY, local_size_z = 1) in;
// we'll emit 4 vertices on 2 primitives per mesh shader invocation
layout(triangles, max_vertices = 4 * numMeshInvocationsX * numMeshInvocationsY, max_primitives = 2 * numMeshInvocationsX * numMeshInvocationsY) out;
taskPayloadSharedEXT SharedData sharedData;
// Example of a default output layout and location format:
layout (location=3) out vec3 outColor[];
void main()
{
if ( gl_LocalInvocationIndex == 0 )
{
// set the number of vertices and primitives to put out just once for the complete workgroup
SetMeshOutputsEXT( 4 * numMeshInvocationsX * numMeshInvocationsY, 2 * numMeshInvocationsX * numMeshInvocationsY);
}
// determine 4 vertices by combining some global position and offset, as well as some local offset and size
vec2 globalOffset = sharedData.offsets[gl_WorkGroupID.x];
vec2 localSize = sharedData.size / gl_WorkGroupSize.xy;
vec2 localOffset = gl_LocalInvocationID.xy * localSize;
vec2 v0 = sharedData.position + globalOffset + localOffset;
vec2 v1 = v0 + vec2( localSize.x, 0.0f );
vec2 v2 = v0 + localSize;
vec2 v3 = v0 + vec2( 0.0f, localSize.y );
uint vertexBaseIndex = 4 * gl_LocalInvocationIndex;
gl_MeshVerticesEXT[vertexBaseIndex + 0].gl_Position = vec4( v0, 0.0f, 1.0f );
gl_MeshVerticesEXT[vertexBaseIndex + 1].gl_Position = vec4( v1, 0.0f, 1.0f );
gl_MeshVerticesEXT[vertexBaseIndex + 2].gl_Position = vec4( v2, 0.0f, 1.0f );
gl_MeshVerticesEXT[vertexBaseIndex + 3].gl_Position = vec4( v3, 0.0f, 1.0f );
uint primitiveBaseIndex = 2 * gl_LocalInvocationIndex;
gl_PrimitiveTriangleIndicesEXT[primitiveBaseIndex + 0] = uvec3( vertexBaseIndex + 0, vertexBaseIndex + 1, vertexBaseIndex + 2 );
gl_PrimitiveTriangleIndicesEXT[primitiveBaseIndex + 1] = uvec3( vertexBaseIndex + 2, vertexBaseIndex + 3, vertexBaseIndex + 0 );
outColor[vertexBaseIndex + 0] = vec3( 1.0f, 0.0f, 0.0f );
outColor[vertexBaseIndex + 1] = vec3( 0.0f, 1.0f, 0.0f );
outColor[vertexBaseIndex + 2] = vec3( 0.0f, 0.0f, 1.0f );
outColor[vertexBaseIndex + 3] = vec3( 1.0f, 1.0f, 0.0f );
}
@@ -0,0 +1,86 @@
#version 450
/* Copyright (c) 2023-2025, Holochip Corporation
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#extension GL_EXT_mesh_shader: require
#extension GL_GOOGLE_include_directive: require
#extension GL_KHR_shader_subgroup_ballot : require // subgroupBallot, subgroupBallotBitCount, subgroupBallotExclusiveBitCount
#include "mesh_shader_shared.h"
// Use numTaskInvocationsX * numTaskInvocationsY task shader invocations per task shader workgroup,
// resulting in N * N * numTaskInvocationsX * numTaskInvocationsY invocations
layout(local_size_x = numTaskInvocationsX, local_size_y = numTaskInvocationsY, local_size_z = 1) in;
layout (binding = 0) uniform UBO
{
float cull_center_x;
float cull_center_y;
float cull_radius;
float meshlet_density;
} ubo;
taskPayloadSharedEXT SharedData sharedData;
float square(float x)
{
return x * x;
}
float square(vec2 p )
{
return p.x * p.x + p.y * p.y;
}
void main()
{
// calculate size and offset of sub-rect per task shader invocation
vec2 size = 2.0f / ( gl_NumWorkGroups.xy * gl_WorkGroupSize.xy );
vec2 offset = gl_GlobalInvocationID.xy * size;
// determine the four corners of the sub-rect and check if it's completely out of the culling circle
// (ignoring the case that a sub-rect could completely include the culling circle...)
vec2 position = vec2(ubo.cull_center_x, ubo.cull_center_y);
vec2 p0 = position + offset;
vec2 p1 = p0 + vec2(size.x, 0.0f);
vec2 p2 = p0 + size;
vec2 p3 = p0 + vec2(0.0f, size.y);
float squaredRadius = square(ubo.cull_radius);
bool isValid = ( square(p0) < squaredRadius )
&& ( square(p1) < squaredRadius )
&& ( square(p2) < squaredRadius)
&& ( square(p3) < squaredRadius);
// contribute a single bit by this task shader invocation
uvec4 validVotes = subgroupBallot(isValid);
if ( isValid )
{
// get the next free index into the offsets array
uint index = subgroupBallotExclusiveBitCount(validVotes);
sharedData.offsets[index] = offset;
}
if ( gl_LocalInvocationIndex == 0 )
{
// for just one task shader invocation we can emit mesh shaders
sharedData.position = position;
sharedData.size = size;
// get the actual number of task shader invocations that are determined to display something
uint validCount = subgroupBallotBitCount(validVotes);
EmitMeshTasksEXT(validCount, 1, 1);
}
}
@@ -0,0 +1,34 @@
/* Copyright (c) 2023, Holochip Corporation
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Example of the data shared with its associated mesh shader:
// Note that all of these could be removed. One can pass positionTransformation, subDimension, and cullRadius from a UBO.
// however, in the interests of demonstrating how to use shared data between task and mesh shaders.
// Number of task shader invocations per task shader workgroup
const uint numTaskInvocationsX = 2;
const uint numTaskInvocationsY = 2;
const uint numMeshInvocationsX = 2;
const uint numMeshInvocationsY = 2;
struct SharedData
{
vec2 position;
vec2 offsets[numTaskInvocationsX * numTaskInvocationsY];
vec2 size;
};