stream parallel load to Shader Storage Buffer Object


I am trying to load integer array in parallel, but i get an error:

int[][] colors;
IntStream.range(0, colors.length).parallel().forEach(i -> {
        GL15.glBufferSubData(GL43.GL_SHADER_STORAGE_BUFFER, pixelSIZE * i, colors[i]);

implementation without parallel() works fine:

IntStream.range(0, colors.length).forEach(i -> {
        GL15.glBufferSubData(GL43.GL_SHADER_STORAGE_BUFFER, pixelSIZE * i, colors[i]);

and for loop as well:

for (int i = 0; i < colors.length; i++) {
        GL15.glBufferSubData(GL43.GL_SHADER_STORAGE_BUFFER, pixelSIZE * i, colors[i]);


[thread 13608 also had an error][thread 19708 also had an error]

# A fatal error has been detected by the Java Runtime Environment:
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ff99ca48cd9, pid=15436, tid=0x0000000000004ce8
# JRE version: Java(TM) SE Runtime Environment (8.0_171-b11) (build 1.8.0_171-b11)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.171-b11 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C[thread 15904 also had an error]
[thread 1456 also had an error]
[thread 19652 also had an error]
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
# An error report file with more information is saved as:
# D:\Documents\NetBeansProjects\XRayInspector\hs_err_pid15436.log
# If you would like to submit a bug report, please visit:
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
C:\Users\Timur\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 19 seconds)

is it posible to use glBufferSubData in parallel?

i use lwjgl 3


1 Answer


OpenGL in itself is single threaded. A OpenGL context can (at one point in time) only be associated with one thread.

You can use multiple contexts (see shared context), but for the specific scenario I'm not sure if this will give you any performance advantage since the GPU will most likely serialize the commands.

answered on Stack Overflow Jun 8, 2020 by BDL

User contributions licensed under CC BY-SA 3.0