Initial Compute Shader for Plate Generation.

This commit is contained in:
Aada 2026-03-09 07:09:52 +02:00
parent 9d2dd0ca82
commit 47ca1265e6
8 changed files with 214 additions and 29 deletions

View file

@ -0,0 +1,40 @@
#[compute]
#version 450
// Invocations in the (x, y, z) dimension
layout(local_size_x = 1000, local_size_y = 1, local_size_z = 1) in;
// A binding to the buffer we create in our script
layout(set = 0, binding = 0, std430) restrict buffer PointBuffer {
int points[];
}
pointbuffer;
layout(set = 0, binding = 1, std430) restrict buffer NeighborBuffer {
int neighbors[];
}
neighborbuffer;
layout(set = 0, binding = 2, std430) restrict buffer PlateBuffer {
int plateid[];
}
platebuffer;
// The code we want to execute in each invocation
void main() {
// Iteration is gl_GlobalInvocationID.x
// Neighbors for Point gl_GlobalInvocationID.y
for (int point = 0; point < int(gl_WorkGroupSize.x); point++)
{
int localpoint = int(gl_WorkGroupID.x)*int(gl_WorkGroupSize.x) + point;
for (int neighbor = 0; neighbor < 6; neighbor++) {
if (neighborbuffer.neighbors[localpoint*6+neighbor] == -1)
{
continue;
}
if (platebuffer.plateid[localpoint] != -1 && platebuffer.plateid[neighborbuffer.neighbors[localpoint*6+neighbor]] == -1)
{
// Neighbor unclaimed, and we can claim it.
platebuffer.plateid[neighborbuffer.neighbors[localpoint*6+neighbor]] = platebuffer.plateid[localpoint];
}
}
}
}