Commit 136979d6 authored by Radek Ošlejšek's avatar Radek Ošlejšek
Browse files

Merge branch '297-gpu-ray-casting-optimizations' into 'master'

Optimizations and better java docs for GPU ray casting

See merge request grp-fidentis/analyst2!338
parents 4aee5d9f 3fc88541
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -7,7 +7,8 @@ import cz.fidentis.analyst.glsl.buffers.impl.SsboBufferImpl;
import java.util.List;

import static com.jogamp.opengl.GL.GL_STATIC_DRAW;
import static com.jogamp.opengl.GL2ES3.GL_DYNAMIC_READ;
import static com.jogamp.opengl.GL2ES3.GL_DYNAMIC_COPY;
import static com.jogamp.opengl.GL2ES3.GL_STATIC_COPY;
import static com.jogamp.opengl.GL2ES3.GL_STATIC_READ;

/**
@@ -25,14 +26,14 @@ public class RayCastingDistBufferGroup extends AbstractBufferGroup {
    public RayCastingDistBufferGroup(GLContext glContext) {
        super(glContext, List.of(
                new SsboBufferImpl(BufferDef.RC_DIST_RAYS, glContext, GL_STATIC_DRAW, 4 * 4 * 2),
                new SsboBufferImpl(BufferDef.RC_DIST_VERTICES, glContext, GL_STATIC_DRAW, 4 * 4),
                new SsboBufferImpl(BufferDef.RC_DIST_TRIANGLES, glContext, GL_STATIC_DRAW, 4 * 4 * 2),
                new SsboBufferImpl(BufferDef.RC_DIST_SORTED_TRIANGLES, glContext, GL_DYNAMIC_READ, 4),
                new SsboBufferImpl(BufferDef.RC_DIST_CELL_BOUNDS, glContext, GL_DYNAMIC_READ, 4),
                new SsboBufferImpl(BufferDef.RC_DIST_VERTICES, glContext, GL_STATIC_DRAW, 4 * 4 * 2),
                new SsboBufferImpl(BufferDef.RC_DIST_TRIANGLES, glContext, GL_STATIC_DRAW, 4 * 4),
                new SsboBufferImpl(BufferDef.RC_DIST_SORTED_TRIANGLES, glContext, GL_STATIC_COPY, 4),
                new SsboBufferImpl(BufferDef.RC_DIST_CELL_BOUNDS, glContext, GL_STATIC_COPY, 4),
                new SsboBufferImpl(BufferDef.RC_DIST_GRID_INFO, glContext, GL_STATIC_READ, 8 * 4),
                new SsboBufferImpl(BufferDef.RC_DIST_DISTANCES, glContext, GL_STATIC_READ, 4 * 4),
                new SsboBufferImpl(BufferDef.RC_DIST_CELL_ELEMENTS, glContext, GL_DYNAMIC_READ, 4),
                new SsboBufferImpl(BufferDef.RC_DIST_TRIANGLES_REDUCTION, glContext, GL_DYNAMIC_READ, 8 * 4)
                new SsboBufferImpl(BufferDef.RC_DIST_CELL_ELEMENTS, glContext, GL_DYNAMIC_COPY, 4),
                new SsboBufferImpl(BufferDef.RC_DIST_TRIANGLES_REDUCTION, glContext, GL_DYNAMIC_COPY, 8 * 4)
        ));
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -9,8 +9,8 @@ import java.nio.ByteBuffer;
import java.util.function.Consumer;

import static com.jogamp.opengl.GL.*;
import static com.jogamp.opengl.GL2ES2.GL_RED;
import static com.jogamp.opengl.GL3ES3.GL_SHADER_STORAGE_BUFFER;
import static com.jogamp.opengl.GL2.GL_RED;
import static com.jogamp.opengl.GL3.GL_SHADER_STORAGE_BUFFER;

/**
 * Shader storage buffer objects (SSBO) for the {@code GL_SHADER_STORAGE_BUFFER} target.
+6 −0
Original line number Diff line number Diff line
@@ -19,6 +19,12 @@ public interface GlslProgram {
     */
    int getProgramId();

    /**
     * Returns the GLSL program definition which was used to create this program.
     * @return program's definition
     */
    GlslProgramDef getProgramDef();

    /**
     * Returns ID of the given named uniform location in the OpenGL context.
     * @param key name
+3 −3
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ public enum GlslProgramDef {
    /**
     * Used by uniform grid construction, calculates the grid's bounding box and estimates the proper cell size.
     */
    GRID_PARAMETERS_GLSL_PROGRAM(List.of(GlslShaderDef.GRID_PARAMETERS_CS)),
    GRID_PARAMETERS_GLSL_PROGRAM(List.of(GlslShaderDef.GRID_PARAMETERS_CS), List.of("level", "invocations")),

    /**
     * Used by uniform grid construction, precomputes how much memory we need to allocate for which cell.
@@ -69,7 +69,7 @@ public enum GlslProgramDef {
    /**
     * Used by uniform grid construction, creates an array (cell bounds) which is used to index cell's triangles.
     */
    GRID_CELL_BOUNDS_GLSL_PROGRAM(List.of(GlslShaderDef.GRID_CELL_BOUNDS_CS)),
    GRID_CELL_BOUNDS_GLSL_PROGRAM(List.of(GlslShaderDef.GRID_CELL_BOUNDS_CS), List.of("level", "upsweep")),

    /**
     * Used by uniform grid construction, creates an array with triangles to which cell bounds point.
@@ -79,7 +79,7 @@ public enum GlslProgramDef {
    /**
     * Ray-casting distance measurement between two meshes using already created uniform grid.
     */
    DISTANCE_RAY_CASTING_GLSL_PROGRAM(List.of(GlslShaderDef.DISTANCE_RAY_CASTING_CS));
    DISTANCE_RAY_CASTING_GLSL_PROGRAM(List.of(GlslShaderDef.DISTANCE_RAY_CASTING_CS), List.of("relative_distance_multiplier"));

    /* *****************************************************************************
     * END OF DEFINITIONS
+9 −9
Original line number Diff line number Diff line
package cz.fidentis.analyst.glsl.code;

import static com.jogamp.opengl.GL2ES2.GL_FRAGMENT_SHADER;
import static com.jogamp.opengl.GL2ES2.GL_VERTEX_SHADER;
import static com.jogamp.opengl.GL3ES3.GL_COMPUTE_SHADER;
import static com.jogamp.opengl.GL2.GL_FRAGMENT_SHADER;
import static com.jogamp.opengl.GL2.GL_VERTEX_SHADER;
import static com.jogamp.opengl.GL3.GL_COMPUTE_SHADER;

/**
 * Definitions of defined GLSL shaders.
@@ -28,12 +28,12 @@ public enum GlslShaderDef {
     * SHADERS FPR THE COMPUTATION OF RAY-CASTING-BASED MESH DISTANCE MEASUREMENT
     ***********************************************************************************/

    TRIANGLE_STATS_CS("TriangleStatsCS.glsl", GL_COMPUTE_SHADER),
    GRID_PARAMETERS_CS("GridParametersCS.glsl", GL_COMPUTE_SHADER),
    GRID_CELL_BOUNDS_CS("GridCellBoundsCS.glsl", GL_COMPUTE_SHADER),
    GRID_CELL_OVERLAP_COUNT_CS("GridCellOverlapCountCS.glsl", GL_COMPUTE_SHADER),
    GRID_SORTED_TRIANGLES_CS("GridSortedTrianglesFillCS.glsl", GL_COMPUTE_SHADER),
    DISTANCE_RAY_CASTING_CS("DistanceRayCastingCS.glsl", GL_COMPUTE_SHADER);
    TRIANGLE_STATS_CS("raycasting/TriangleStatsCS.glsl", GL_COMPUTE_SHADER),
    GRID_PARAMETERS_CS("raycasting/GridParametersCS.glsl", GL_COMPUTE_SHADER),
    GRID_CELL_BOUNDS_CS("raycasting/GridCellBoundsCS.glsl", GL_COMPUTE_SHADER),
    GRID_CELL_OVERLAP_COUNT_CS("raycasting/GridCellOverlapCountCS.glsl", GL_COMPUTE_SHADER),
    GRID_SORTED_TRIANGLES_CS("raycasting/GridCellTrianglesFillCS.glsl", GL_COMPUTE_SHADER),
    DISTANCE_RAY_CASTING_CS("raycasting/DistanceRayCastingCS.glsl", GL_COMPUTE_SHADER);

    /* *****************************************************************************
     * END OF DEFINITIONS
Loading