I’m trying to figure out how to pass buffer textures to compute shaders using the gpu module but it seems like it does nothing at all despite accepting the texture, what am I doing wrong here?
“FLOAT_2D” seems to work fine but for sake of simplicity, I wanted to use a 1D addressing for my data since I’d be dumping vertex coordinates on the texels to perform some transformations. gpu.capabilities.max_texture_size_get() returns 16384 for my machine, which is smaller than the size of most meshes I would want to fit on a texture, so it would require a 2D texture, which complicates indexing.
from gpu.types import GPUShaderCreateInfo, GPUTexture
import gpu
cr_info = GPUShaderCreateInfo()
cr_info.local_group_size(1, 1, 1)
cr_info.image(0, 'R32F', 'FLOAT_BUFFER', 'imageb', qualifiers={'WRITE'})
cr_info.compute_source('''//glsl
void main(){
int idx = int(gl_GlobalInvocationID.x);
imageStore(imageb, idx, vec4(idx, 0, 0, 0));
}
''')
shader = gpu.shader.create_from_info(cr_info)
tex = GPUTexture((10, 10), format='R32F')
tex.clear(format='FLOAT', value=(2, 2, 2, 2))
shader.bind()
shader.image('imageb', tex)
gpu.compute.dispatch(shader, 100, 1, 1)
print(tex.read())