stream parallel load to Shader Storage Buffer Object

0

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]);
    }

error:

[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]
  [nvoglv64.dll+0x978cd9]
#
# 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:
#   http://bugreport.java.com/bugreport/crash.jsp
# 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

java
opengl
lwjgl
shader-storage-buffer
ssbo

1 Answer

0

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