Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mipmapping with compute shader

I have 3D textures of colors, normals and other data of my voxelized scene and because some of this data can't be just averaged i need to calculate mip levels by my own. The 3D texture sizes are (128+64) x 128 x 128, the additional 64 x 128 x 128 are for mip levels.

So when i take the first mip level, which is at (0, 0, 0) with a size of 128 x 128 x 128 and just copy voxels to the second level, which is at (128, 0, 0) the data appears there, but as soon as i copy the second level at (128, 0, 0) to the third at (128, 0, 64) the data doesn't appear at the 3rd level.

shader code:

#version 450 core

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

layout (location = 0) uniform unsigned int resolution;
layout (binding = 0, rgba32f) uniform image3D voxel_texture;

void main()
{
    ivec3 index = ivec3(gl_WorkGroupID);
    ivec3 spread_index = index * 2;

    vec4 voxel = imageLoad(voxel_texture, spread_index);
    imageStore(voxel_texture, index + ivec3(resolution, 0, 0), voxel);

    // This isn't working
    voxel = imageLoad(voxel_texture, spread_index + 
                      ivec3(resolution, 0, 0));
    imageStore(voxel_texture, index + ivec3(resolution, 0, 64), voxel);
}

The shader program is dispatched with

glUniform1ui(0, OCTREE_RES);

glBindImageTexture(0, voxel_textures[0], 0, GL_TRUE, 0, GL_READ_WRITE, 
                   GL_RGBA32F);

glDispatchCompute(64, 64, 64);

I don't know if i missed some basic thing, this is my first compute shader. I also tried to use memory barriers but it didn't change a thing.

like image 867
FamZ Avatar asked May 31 '16 16:05

FamZ


People also ask

Does mipmapping improve performance?

Increased performance – Mipmapping increases cache efficiency as full-size textures will not be needed as often, and the lower resolution mipmaps will fit more easily in the texture cache. This means texture data doesn't have to be fetched as often, reducing bandwidth usage and increasing application performance.

Does OpenGL support compute shaders?

Compute Shader Stage. To make GPU computing easier accessible especially for graphics applications while sharing common memory mappings, the OpenGL standard introduced the compute shader in OpenGL version 4.3 as a shader stage for computing arbitrary information.

Is higher mipmap better?

A high-resolution mipmap image is used for objects that are close to the user. Lower-resolution images are used as the object appears farther away. Mipmapping improves the quality of rendered textures at the expense of using more memory.

Does metal support compute shaders?

Platform-specific differences. Metal (for iOS and tvOS platforms) does not support atomic operations on Textures. Metal also does not support GetDimensions queries on buffers. Pass the buffer size info as constant to the shader if needed.


1 Answers

Well you can't expect your second imageLoad to read texels that you just wrote in your first store like that.

And there is no way to synchronize access outside of the 'local' workgroup.

You'll need either :

  • To use multiple invocation of your kernel to do each layer
  • To rewrite your shader logic so that you always fetch from the 'original' zone.
like image 65
246tNt Avatar answered Sep 30 '22 11:09

246tNt