optimize dispatch calls

This commit is contained in:
2025-11-08 22:23:22 +01:00
parent 9f40a59612
commit db1bbd6d0a
3 changed files with 22 additions and 11 deletions

View File

@@ -2,6 +2,8 @@
layout(rgba32f, binding = 0) uniform writeonly image2D outputImage;
layout(location = 0) uniform uint triangleCount;
layout(std430, binding = 3) buffer layoutName
{
vec2 o_Points[];
@@ -26,14 +28,17 @@ layout(std430, binding = 3) buffer layoutName
// gl_WorkGroupID : This is the current work group for this shader invocation. Each of the XYZ components will be on the half-open range [0, gl_NumWorkGroups.XYZ).
// gl_LocalInvocationID : This is the current invocation of the shader within the work group. Each of the XYZ components will be on the half-open range [0, gl_WorkGroupSize.XYZ).
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
// avant : 1 3 9
// après : 3 9 27
// count : 1 3 9
layout(local_size_x = 64) in;
void main()
{
uint triangleCount = gl_NumWorkGroups.x;
uint currentPoint = gl_WorkGroupID.x;
uint currentPoint = gl_GlobalInvocationID.x;
if (currentPoint >= triangleCount)
return;
uint offset = (triangleCount - 1) / 2;
uint firstPointIndex = offset * 3 + 1;
o_Points[firstPointIndex + currentPoint * 3] = o_Points[offset + currentPoint] / 2 + vec2(0, 0.36);
o_Points[firstPointIndex + currentPoint * 3 + 1] = o_Points[offset + currentPoint] / 2 + vec2(-0.5, -0.5);

View File

@@ -1,14 +1,10 @@
#version 460 core
layout(location = 0) in vec2 a_Position;
layout(std430, binding = 3) buffer layoutName
{
vec2 data_SSBO[];
};
out vec2 v_TexCoord;
void main()
{
gl_Position = vec4(data_SSBO[gl_InstanceID], 0.0, 1.0);

View File

@@ -139,7 +139,7 @@ int main()
GLuint vertexBuffer;
glCreateBuffers(1, &vertexBuffer);
constexpr int DEPTH = 13;
constexpr int DEPTH = 14;
auto vertices = GetPoints(DEPTH);
@@ -155,6 +155,8 @@ int main()
glVertexArrayAttribBinding(vertexArray, 0, 0);
glVertexArrayAttribBinding(vertexArray, 1, 0);
Timer timer;
GLuint ssbo;
glGenBuffers(1, &ssbo);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
@@ -173,7 +175,13 @@ int main()
std::size_t count = 1;
for (std::size_t i = 0; i < DEPTH; i++)
{
glDispatchCompute(count, 1, 1);
glUniform1ui(0, count);
std::cout << count << std::endl;
int dispatchCount = (count - 1) / 64 + 1;
std::cout << "DC : " <<dispatchCount<< std::endl;
glDispatchCompute(dispatchCount, 1, 1);
// Ensure all writes to the image are complete
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
@@ -181,6 +189,8 @@ int main()
count *= 3;
}
std::cout << "Generated points in " << timer.ElapsedMillis() << " ms\n";
while (!glfwWindowShouldClose(window))
{
// ScopedTimer timer("Main Loop");