简体   繁体   English

Vulkan中的OpenGL GLSL原子计数器

[英]OpenGL GLSL atomic counter in Vulkan

When I tried to migrate my OpenGL implementation to Vulkan, I found that 'uniform atomic_uint' is not supported in Vulkan. 当我尝试将OpenGL实现迁移到Vulkan时,我发现Vulkan不支持'uniform atomic_uint'。 My use case is simple: incrementing an integer across all fragments. 我的用例很简单:在所有片段上增加一个整数。 I tried to search the solution but did not find any latest solution. 我尝试搜索解决方案,但未找到任何最新解决方案。

Here is a list of old solutions: 以下是旧解决方案的列表:

  1. https://software.intel.com/en-us/articles/opengl-performance-tips-atomic-counter-buffers-versus-shader-storage-buffer-objects . https://software.intel.com/zh-CN/articles/opengl-performance-tips-atomic-counter-buffers-versus-shader-storage-buffer-objects It said that OpenGL atomic counter is similar to SSBO atomic operation and it may be implemented as SSBO atomic operations on some platforms. 它说OpenGL原子计数器类似于SSBO原子操作,并且在某些平台上可以实现为SSBO原子操作。 (Not sure whether it is still true today). (不确定今天是否仍然适用)。

  2. https://community.khronos.org/t/vulkan-atomic-counters/7146 . https://community.khronos.org/t/vulkan-atomic-counters/7146 It also said to use image load/store or atomic operations on SSBO as a replacement. 它还说使用SSBO上的图像加载/存储或原子操作作为替代。 (But the content is 2 years old.) (但内容为2岁。)

Since Vulkan is still growing, can anyone suggest a latest standard way to do atomic increment over an integer using GLSL in Vulkan? 由于Vulkan仍在增长,有人可以建议使用Vulkan中的GLSL在整数上进行原子增量的最新标准方法吗?

Edit: 编辑:

I've got my answer, but I will add more details. 我有我的答案,但我会添加更多详细信息。 In my OpenGL code, I have a render pass with a vertex shader and a fragment shader ( No compute shader involved). 在我的OpenGL代码中,我具有一个带有顶点着色器和片段着色器的渲染过程( 涉及计算着色器)。 In the fragment shader, I have the following glsl (simplified): 在片段着色器中,我具有以下glsl(简体):

#version 450
layout (binding = 0) uniform atomic_uint fragmentCount;

void main()
{
  atomicCounterIncrement(fragmentCount);
}

This shader works fine in OpenGL because OpenGL has enum 'GL_ATOMIC_COUNTER_BUFFER' in glBindBuffer and keyword 'atomic_uint' in glsl. 此着色器在OpenGL中工作正常,因为OpenGL在glBindBuffer中具有枚举'GL_ATOMIC_COUNTER_BUFFER',在glsl中具有关键字'atomic_uint'。 However, Vulkan does not have the corresponding built-in keyword. 但是,Vulkan没有相应的内置关键字。 Therefore, I try to seek a replacement for it. 因此,我尝试寻找替代品。 I did not ask how to query the number of fragments being rendered, though the shader here looks like I'm doing that. 我没有问如何查询正在渲染的片段的数量,尽管这里的着色器看起来像我正在做的那样。 I was wondering whether this 'atomic counter' in general graphics shaders exists in Vulkan. 我想知道Vulkan中是否存在通用图形着色器中的“原子计数器”。 As Nicol Bolas pointed out, there is no such thing in Vulkan and hardware-wise there is no implementation on NVIDIA GPU, so I decide to use SSBO and AtomicAdd to do the same thing. 正如Nicol Bolas指出的那样,在Vulkan中没有这样的事情,在硬件方面,NVIDIA GPU上也没有实现,因此我决定使用SSBO和AtomicAdd来做同样的事情。

Hope this makes my problem clearer. 希望这使我的问题更清楚。

Atomic counters don't exist in Vulkan, so you'll have to go with one of those solutions. Vulkan中不存在原子计数器,因此您必须使用其中一种解决方案。

BTW, atomic counters, as a distinct hardware concept, are only something that existed on AMD hardware. 顺便说一句,原子计数器作为一种独特的硬件概念,只是AMD硬件上存在的一种。 That is why Vulkan doesn't support them; 这就是为什么Vulkan不支持他们的原因。 non-AMD hardware basically emulates them as SSBO work. 非AMD硬件基本上将它们模拟为SSBO工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM