0

我正在尝试并行加载整数数组,但出现错误:

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

没有parallel()工作正常的实施:

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

以及 for 循环:

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]
  [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)

可以并行使用 glBufferSubData 吗?

我用 lwjgl 3

4

1 回答 1

0

OpenGL 本身是单线程的。OpenGL 上下文只能(在某一时间点)与一个线程相关联。

您可以使用多个上下文(请参阅共享上下文),但对于特定场景,我不确定这是否会给您带来任何性能优势,因为 GPU 很可能会序列化命令。

于 2020-06-08T09:27:24.990 回答