3

I have an float RGBA buffer that I want to pass to my compute shader as a Uniform Texel Buffer (for read-only access with no sampling). Can someone tell me how to do this in GLSL?

All examples I can find seem to be skipping that topic or have a at best weak nomenclature.

abergmeier
  • 13,224
  • 13
  • 64
  • 120
  • FYI, if you directly look at the vulkan spec, there are examples. `samplerBuffer` is for uniform texel buffer and `imageBuffer` is for storage texel buffer. – Shahbaz Dec 06 '17 at 19:04

1 Answers1

4

The descriptor type that Vulkan calls "uniform texel buffer" represents a concept that, in OpenGL parlance, is called a "buffer texture". While normally the GLSL type for this would be samplerBuffer, the Vulkan flavor of GLSL uses textureBuffer instead.

The corresponding descriptor for this type should of course use the VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER type. However, since Vulkan doesn't share OpenGL's notion that this is some kind of texture, the descriptor's data is a VkBufferView, not a VkImage or VkImageView. Specifically, VkWriteDescriptorSet::pTexelBufferView.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • 2
    Have a look set this example, it uses uniform texel buffers in compute shaders: https://github.com/PacktPublishing/Vulkan-Cookbook/tree/master/Samples/Source%20Files/12%20Advanced%20Rendering%20Techniques/03-Drawing_particles_using_compute_and_graphics_pipelines – Ekzuzy Oct 12 '17 at 04:53
  • 1
    And here is the compute shader from the mentioned example: https://github.com/PacktPublishing/Vulkan-Cookbook/blob/master/Samples/Data/Shaders/12%20Advanced%20Rendering%20Techniques/03%20Drawing%20particles%20using%20compute%20and%20graphics%20pipelines/shader.comp – Ekzuzy Oct 12 '17 at 05:00
  • As of 2022, according to the [GLSL 4.60 spec](https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.4.60.pdf), uniform texel buffers should be declared in GLSL as `uniform textureBuffer` variables (see "Texture Buffers (Uniform Texel Buffers)" under section 12.2.4 "Vulkan Only: Samplers, Images, Textures, and Buffers"). – Zoë Sparks Jun 01 '22 at 21:08
  • @ZoëSparks: Fixed. – Nicol Bolas Jun 01 '22 at 21:20