繁体   English   中英

GL_R32UI 单通道纹理缓冲区利用率

[英]GL_R32UI Single Channel Texture Buffer Utilization

glGenTextures(MAX_TEMP_ARRAY_NUMBER, m_array_buffers);
for (int i = 0; i < MAX_TEMP_ARRAY_NUMBER; i++)
{
    glBindTexture(GL_TEXTURE_2D, m_array_buffers[i]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    //glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32UI, m_imageW, m_imageH);
    //glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32UI, MAX_ARRAY_SIZE, 1);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_R32UI, m_imageW, m_imageH, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, NULL);
    glBindTexture(GL_TEXTURE_2D, 0);
}
for (size_t j = 0; j < MAX_TEMP_ARRAY_NUMBER; j++) {
    glBindImageTexture(j + MAX_SWAP_BUFFER_NUMBER + MAX_TEMP_BUFFER_NUMBER, m_image->array(j), 0, GL_FALSE, 0, GL_READ_WRITE, GL_R32UI);
}

glDispatchCompute(
    static_cast<GLuint>(std::ceil(imgW / 32.0f)),
    static_cast<GLuint>(std::ceil(imgH / 32.0f)), 1);
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
unsigned int* histogram = new unsigned int[m_image->width() * m_image->height()];
memset(histogram, 0, m_image->width()* m_image->height()* sizeof(unsigned int));
arrayBuffer = m_image->array(0);
//unsigned int* histogram = new unsigned int[MAX_ARRAY_SIZE];
//glGetTextureImage(arrayBuffer, 0, GL_R32UI, GL_UNSIGNED_INT, MAX_ARRAY_SIZE, (void *)histogram);
glGetTextureImage(arrayBuffer, 0, GL_R32UI, GL_UNSIGNED_INT, m_image->width()* m_image->height(), (void *)histogram);
//glBindImageTexture(MAX_SWAP_BUFFER_NUMBER + MAX_TEMP_BUFFER_NUMBER, arrayBuffer, 0, GL_TRUE, 0, GL_READ_WRITE, GL_R32UI);
//glGetTexImage(GL_TEXTURE_2D, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, histogram);
printf("Histogram : %d, %d, %d, %d, %d\n", histogram[0], histogram[1], histogram[2], histogram[3], histogram[4]);
delete histogram;

[计算着色器]

layout (r32ui, binding=4) uniform uimage2D uarray0;
layout (r32ui, binding=5) uniform uimage2D uarray1;

void main()
{
    ivec2 imageRes = imageSize(imageIn);
    ivec2 baseUV = ivec2(gl_GlobalInvocationID.xy);
    baseUV = clamp(baseUV, ivec2(0), imageSize(imageIn));
    vec3 imgColor = imageLoad(imageIn, baseUV).rgb;
        
//  imageAtomicAdd(uarray0, ivec2(int(round(imgColor * 256.0)),1), 1);
    imageStore(uarray0, baseUV, uvec4(uvec3(int(round(imgColor * 256.0))), 1.0));

我正在尝试在主机应用程序和计算着色器之间建立一个读写机制。 与 image2D 和 RGBA 通道通信,它工作得很好,但如果我尝试使用单个通道(如 GL_R32UI)来节省通信开销,则 glGetTextureImage(...) 或 glGetTexImage(...) 无法读取任何内容。

我尝试了许多规范化或非规范化 (GL_RED_INTEGER) 以及 glTexStorage2D(...) 或 glTexImage2D(...) 和 glGetTexImage(...) 或 glGetTextureImage(...) 的组合。 但我无法做出成功的案例。

我的电脑规格如下:

11th Gen Intel Core i7-1165G7
Renderer: Intel(R) Iris(R) Xe Graphics
Vendor: Intel
Version: 4.6.0 - Build 31.0.101.3959
Shading language version: 4.60 - Build 31.0.101.3959
Max texture size: 16384 x 16384
Max vertex texture image units: 32
Max texture image units: 32
Max geometry texture units: 32
Max anisotropic filtering value: 16
Max viewport size: 16384 x 16384
Max Clip Distances: 8
Max samples: 16

我想出了一个解决办法,但仍然有疑问。 为了在计算着色器中处理图像,我准备了具有因素组合的缓冲区 [float/int and single/multiple and unsigned/signed]

在下面的 3 次试验中,除了 format(GL_RGBA16UI) 之外,内部格式工作正常,然后我猜 format(GL_RGBA32UI) 现在也可以工作了。 但单通道 GL_R32UI 工作正常。

[设置部分]

glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA16F, m_imageW, m_imageH); glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA16, m_imageW, m_imageH); // GL_RGBA16UI is not working why? glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32UI, m_imageW, m_imageH);

[绑定部分]

glBindImageTexture(0, imgInput, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA16F); glBindImageTexture(1, imgOutput, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA16F);

for (size_t j = 0; j < MAX_TEMP_BUFFER_NUMBER; j++) { glBindImageTexture(j + MAX_SWAP_BUFFER_NUMBER, m_image->buffer(j), 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA16F); }

for (size_t j = 0; j < MAX_TEMP_ARRAY_NUMBER; j++) { glBindImageTexture(j + MAX_SWAP_BUFFER_NUMBER + MAX_TEMP_BUFFER_NUMBER, m_image->array(j), 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA16UI); } m_image->array(j), 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA16UI); }

for (size_t j = 0; j < MAX_TEMP_SINGLE_NUMBER; j++) { glBindImageTexture(j + MAX_SWAP_BUFFER_NUMBER + MAX_TEMP_BUFFER_NUMBER + MAX_TEMP_SINGLE_NUMBER, m_image->single(j), 0, GL_FALSE, 0, GL_READ_WRITE, GL_R32UI); }

[计算着色器]

#version 450 core

layout (local_size_x=32, local_size_y=32, local_size_z=1) in;

layout (rgba16f, binding=0) readonly uniform image2D imageIn; layout (rgba16f, binding=1) writeonly uniform image2D imageOut;

layout (rgba16f, binding=2) uniform image2D buffer0; layout (rgba16f, binding=3) uniform image2D buffer1;

layout (rgba16ui, binding=4) uniform uimage2D uarray0; layout (rgba16ui, binding=5) uniform uimage2D uarray1;

layout (r32ui, binding=6) uniform uimage2D single0; layout (r32ui, binding=7) uniform uimage2D single1;

glBindImageTexture(...) 需要正确的格式 (GL_RGBA16UI),但 glTexStorage2D(...) 使用格式 (GL_RGBA16) 并且行为与其他情况不同。

问题未解决?试试以下方法:

GL_R32UI 单通道纹理缓冲区利用率

暂无
暂无

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

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