Skip to content

Commit cb83e5f

Browse files
authored
Merge pull request #326 from KhronosGroup/spencer-lunarg-patch-5
Extra edge case for Storage Texel Buffer
2 parents 8121dd8 + a4ae543 commit cb83e5f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

chapters/storage_image_and_texel_buffers.adoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,29 @@ OpDecorate %storageTexelBuffer Binding 0
327327
%storageTexelBuffer = OpVariable %ptr UniformConstant
328328
----
329329

330+
==== Using non-rgba Format for Texel Buffer
331+
332+
A common mistake when dealing with Texel Buffers is forgetting you are accessing a single texel at a time.
333+
This texel format can have 1 to 4 components (`R8` vs `RGBA8`).
334+
Some shading languages, such as GLSL, require you to write all 4 components where the extra components are ignored.
335+
336+
[source,glsl]
337+
----
338+
// VK_FORMAT_R32_UINT
339+
layout(set = 0, binding = 0, r32ui) uniform uimageBuffer storageTexelBuffer;
340+
341+
void main() {
342+
// Invalid in GLSL, need to use a uvec4
343+
uint a = 1;
344+
imageStore(storageTexelBuffer, 0, a);
345+
346+
// Common mistake is to assume this will write all 4 values to 4 consecutive texels.
347+
// Only "1" is written and the other 3 components are discarded because the format only contains 1 component
348+
uvec4 b = uvec4(1, 2, 3, 4);
349+
imageStore(storageTexelBuffer, 0, b);
350+
}
351+
----
352+
330353
=== Formats for Texel Buffers
331354

332355
Not all formats support texel buffer operations. The `VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT` and `VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT` flags in `VkFormatProperties` indicate whether a format can be used for uniform and storage texel buffers, respectively.

0 commit comments

Comments
 (0)