gpt4 book ai didi

opengl - GLSL:我可以在同一个着色器(pass)中组合 MRT、ssbo 和 imageAtomic 操作吗?

转载 作者:行者123 更新时间:2023-12-04 19:29:13 25 4
gpt4 key购买 nike

OpenGL 中的 2-pass 渲染系统使用绑定(bind)到 2 个帧缓冲区纹理 tex1 和 tex2 的 MRT 着色器。 mrt pass 的目标是计算场景中的过度绘制并在gather pass 中渲染出来。我使用帧缓冲区纹理来传递结果。

它还有一个非常大的工作 ssbo 缓冲区(并且使用固定的屏幕分辨率)并且需要很长时间才能链接,但我可以使用它来执行 atomicAdds。我想要完成的是用 uiimage2D 上的 imageAtomicAdd 操作替换它,就像使用 mrt 通行证一样。

问题是 imageAtomicAdd 的结果总是为零,我希望它会像 atomicAdd 那样上升。

#version 440 core

layout(early_fragment_tests) in;

// this works fine
layout (location = 0) out vec4 tex1;
layout (location = 1) out vec4 tex2;

// this works fine
layout(std430, binding = 3) buffer ssbo_data
{
uint v[1024*768];
};

// this does not work at all.
uniform volatile layout(r32ui) uimage2D imgCounter;

out vec4 frag_colour;

void main ()
{
ivec2 coords = ivec2(gl_FragCoord.xy);
uint addValue = 1u;

uint countOverdraw1 = atomicAdd(v[coords.x + coords.y * 1024], 1u);
uint countOverdraw2 = imageAtomicAdd(imgCounter, ivec2(0,0), 1u);

memoryBarrier();

// supports 256 levels of overdraw..
float overdrawDepth = 256.0;
vec3 c1 = vec3(float(countOverdraw1+1)/overdrawDepth ,0,1);
vec3 c2 = vec3(float(countOverdraw2+1)/overdrawDepth ,0,1);

tex1 = vec4(c1,1);
tex2 = vec4(c2,1);
frag_colour = vec4(1,1,1,1);
}

来自 khronos website on image atomic operations我收集到..

Atomic operations to any texel that is outside of the boundaries of the bound image will return 0 and do nothing.



.. 但坐标 ivec2(0,0) 将在纹理大小 (1024 x 768) 的范围内。

也许纹理设置不正确?这就是我构建 uiimage2D 的方式(从管道流拼凑在一起):

编辑:我根据 Nicol Bolas 的回答建议更新代码:设置纹理参数而不是采样器参数
char data[1024*768*4];
glGenTextures(1, &m_Handle);

m_Target = GL_TEXTURE_2D;

glActiveTexture(GL_TEXTURE0+6);
glBindTexture(m_Target,m_Handle);

// updated : a sampler object was bound to the texture, but is now removed

glTexParameteri(m_Target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // updated
glTexParameteri(m_Target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // updated
glTexParameteri(m_Target, GL_TEXTURE_WRAP_R, GL_REPEAT); // updated
glTexParameteri(m_Target, GL_TEXTURE_WRAP_S, GL_REPEAT); // updated
glTexParameteri(m_Target, GL_TEXTURE_WRAP_T, GL_REPEAT); // updated
glTexImage2D(m_Target, 0, R32UI, 1024, 768, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, data);

如果我通过 gDEBugger GL 运行它,我会看到“此时纹理数据不可用”并且虽然纹理的“纹理 4”参数已填充并正确,但“纹理参数”和“0 级参数”均未填写' 显示(不适用)。此时捕获调试器会引发大量问题,这些问题不会出现在 gDEBugger 之外。以下是前几个:
GL_INVALID_OPERATION error generated. The required buffer is missing.
GL_INVALID_ENUM error generated. <pname> requires feature(s) disabled in the current profile.
GL_INVALID_OPERATION error generated. <index> exceeds the maximum number of supported texture units.
GL_INVALID_ENUM error generated. or require feature(s) disabled in the current profile.
GL_INVALID_OPERATION error generated. Can't mix integer and non-integer data
...

我明确地强制使用 GL 4.4 或 GL4.4“核心”配置文件,所以我有点困惑,缺少所需的缓冲区可能是什么问题。会不会错误地将 imgCounter 视为帧缓冲区 MRT 设置的一部分?

最佳答案

那个纹理是不完整的。

请注意,当您绑定(bind)纹理以用于图像加载/存储操作时,您不会将采样器与它一起绑定(bind)。所以所有这些glSamplerParameter调用对纹理的完整性状态没有意义。

纹理不完整,因为过滤参数为GL_LINEAR ,但纹理是无符号整数格式。创建整数格式纹理时,应始终将纹理的参数设置为有效值。

关于opengl - GLSL:我可以在同一个着色器(pass)中组合 MRT、ssbo 和 imageAtomic 操作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46788286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com