Fix various shaders problems, and tune command buffer size.

This commit is contained in:
TSnake41 2021-10-30 17:11:36 +02:00
parent 58c206aa41
commit 3221cfd1c7
3 changed files with 15 additions and 15 deletions

View File

@ -3,13 +3,13 @@
#define GOL_WIDTH 768 #define GOL_WIDTH 768
layout (local_size_x = 16, local_size_y = 16, local_size_x = 1) in; layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
layout(std430, binding = 1) readonly restrict buffer golLayout { layout(std430, binding = 1) readonly restrict buffer golLayout {
uint golBuffer[]; // golBuffer[x, y] = golBuffer[x + gl_NumWorkGroups.x * y] uint golBuffer[]; // golBuffer[x, y] = golBuffer[x + gl_NumWorkGroups.x * y]
}; };
layout(std430, set = 1, binding = 2) writeonly restrict buffer golLayout2 { layout(std430, binding = 2) writeonly restrict buffer golLayout2 {
uint golBufferDest[]; // golBufferDest[x, y] = golBufferDest[x + gl_NumWorkGroups.x * y] uint golBufferDest[]; // golBufferDest[x, y] = golBufferDest[x + gl_NumWorkGroups.x * y]
}; };
@ -27,25 +27,25 @@ void main()
// Top left // Top left
neighbour_count += fetchGol(x - 1, y - 1); neighbour_count += fetchGol(x - 1, y - 1);
// Top middle // Top middle
neighbour_count += fetchGol(x, y - 1); neighbour_count += fetchGol(x, y - 1);
// Top right // Top right
neighbour_count += fetchGol(x + 1, y - 1); neighbour_count += fetchGol(x + 1, y - 1);
// Left // Left
neighbour_count += fetchGol(x - 1, y); neighbour_count += fetchGol(x - 1, y);
// Right // Right
neighbour_count += fetchGol(x + 1, y); neighbour_count += fetchGol(x + 1, y);
// Bottom left // Bottom left
neighbour_count += fetchGol(x - 1, y + 1); neighbour_count += fetchGol(x - 1, y + 1);
// Bottom middle // Bottom middle
neighbour_count += fetchGol(x, y + 1); neighbour_count += fetchGol(x, y + 1);
// Bottom right // Bottom right
neighbour_count += fetchGol(x + 1, y + 1); neighbour_count += fetchGol(x + 1, y + 1);
@ -55,4 +55,4 @@ void main()
setGol(x, y, fetchGol(x, y)); setGol(x, y, fetchGol(x, y));
else else
setGol(x, y, 0); setGol(x, y, 0);
} }

View File

@ -9,9 +9,9 @@ struct GolUpdateCmd {
uint enabled; // whether to enable or disable zone uint enabled; // whether to enable or disable zone
}; };
layout (local_size_x = 1, local_size_y = 1, local_size_x = 1) in; layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(std430, binding = 1) writeonly restrict buffer golBufferLayout { layout(std430, binding = 1) buffer golBufferLayout {
uint golBuffer[]; // golBuffer[x, y] = golBuffer[x + GOL_WIDTH * y] uint golBuffer[]; // golBuffer[x, y] = golBuffer[x + GOL_WIDTH * y]
}; };
@ -26,7 +26,7 @@ layout(std430, binding = 3) readonly restrict buffer golUpdateLayout {
void main() void main()
{ {
uint cmd_index = gl_GlobalInvocationID.x; uint cmd_index = gl_GlobalInvocationID.x;
struct GolUpdateCmd cmd = commands[cmd_index]; GolUpdateCmd cmd = commands[cmd_index];
for (uint x = cmd.x; x < (cmd.x + cmd.w); x++) { for (uint x = cmd.x; x < (cmd.x + cmd.w); x++) {
for (uint y = cmd.y; y < (cmd.y + cmd.w); y++) { for (uint y = cmd.y; y < (cmd.y + cmd.w); y++) {
@ -39,4 +39,4 @@ void main()
} }
} }
} }
} }

View File

@ -15,7 +15,7 @@
* *
********************************************************************************************/ ********************************************************************************************/
#include <stdint.h> #include <stdlib.h>
#include "raylib.h" #include "raylib.h"
#include "rlgl.h" #include "rlgl.h"
@ -27,7 +27,7 @@
#define SSBO_SIZE (sizeof(unsigned int) * GOL_WIDTH * GOL_WIDTH) #define SSBO_SIZE (sizeof(unsigned int) * GOL_WIDTH * GOL_WIDTH)
// Maximum amount of queued draw commands (squares draw from mouse down events). // Maximum amount of queued draw commands (squares draw from mouse down events).
#define MAX_BUFFERED_TRANSFERTS 128 #define MAX_BUFFERED_TRANSFERTS 48
struct GolUpdateCmd { struct GolUpdateCmd {
unsigned int x; // x coordinate of the gol command unsigned int x; // x coordinate of the gol command