This commit is contained in:
mcrcortex
2025-03-04 12:14:28 +10:00
parent 743c423ba5
commit ff82c2d761
4 changed files with 34 additions and 23 deletions

View File

@@ -13,11 +13,17 @@ layout(binding = OUTPUT_BUFFER_BINDING, std430) restrict writeonly buffer Output
uvec2 outputBuffer[OUTPUT_SIZE];
};
layout(binding = QQQQQQ, std430) restrict buffer QQQ {
uint[] qq;
layout(binding = VISIBILITY_BUFFER_BINDING, std430) restrict buffer VisibilityBuffer {
uint[] visibility;
};
void main() {
outputBuffer[gl_LocalInvocationID.x] = nodes[minVisIds[gl_LocalInvocationID.x]].xy;//Move the position of the node id into the output buffer
//outputBuffer[gl_LocalInvocationID.x].x = qq[minVisIds[gl_LocalInvocationID.x]];//
uvec4 node = nodes[minVisIds[gl_LocalInvocationID.x]];
uvec2 res = node.xy;
if (all(equal(node, uvec4(0)))) {//If its a empty node, TODO: DONT THINK THIS IS ACTUALLY CORRECT
res = uvec2(-1);
}
outputBuffer[gl_LocalInvocationID.x] = res;//Move the position of the node id into the output buffer
//outputBuffer[gl_LocalInvocationID.x].x = visibility[minVisIds[gl_LocalInvocationID.x]];//
}

View File

@@ -18,31 +18,29 @@ layout(binding = OUTPUT_BUFFER_BINDING, std430) restrict volatile buffer Minimum
};
//Returns the id of the max value
uint atomicDerefMin(uint atId, uint id, uint value) {
uint existingId = minVisIds[atId];
uint atomicDerefMax(uint atId, uint id, uint value) {
while (true) {
const uint existingId = minVisIds[atId];
//Check if the value is less than the dereferenced value, if its not, return our own id
if (visiblity[existingId] <= value) {
return id;
}
//Attempt to swap, since we know we are less than the existingId
atomicCompSwap(minVisIds[atId], existingId, id);
uint c = atomicCompSwap(minVisIds[atId], existingId, id);
//Check if we did swap, else if we failed (or got reswapped else where) recheck
uint pExistingId = existingId;
existingId = minVisIds[atId];
if (existingId == id) {
return pExistingId;
//We did swap, (since the original mem contents was the existing id)
// which means existingId is now the max of the ptr
if (c == existingId) {
return existingId;
}
}
}
//TODO: optimize
void bubbleSort(uint start, uint id, uint value) {
void bubbleSort(uint start, uint id) {
for (uint i = start; i < OUTPUT_SIZE; i++) {
uint nextId = atomicDerefMin(i, id, value);
//Else we need to bubble the value up
id = nextId;
value = visiblity[id];
id = atomicDerefMax(i, id, visiblity[id]);
}
}
@@ -57,8 +55,8 @@ void main() {
}
UnpackedNode node;
unpackNode(node, gl_GlobalInvocationID.x);
if (isEmptyMesh(node) || (!hasMesh(node)) || (!hasChildren(node)) || all(equal(node.pos, ivec3(0)))) {
if (isEmptyMesh(node) || (!hasMesh(node))) {//|| (!hasChildren(node))
return;
}
bubbleSort(0, gl_GlobalInvocationID.x, vis);
bubbleSort(0, gl_GlobalInvocationID.x);
}