Sitelet https://github.com/gpuweb/gpuweb/pull/297
Skip to content

Add GPUTexelBufferView - #297

Closed
kvark wants to merge 1 commit into
gpuweb:masterfrom
kvark:texel
Closed

kvark wants to merge 1 commit into
gpuweb:masterfrom
kvark:texel

Conversation

@kvark

@kvark kvark commented May 13, 2019

Copy link
Copy Markdown
Contributor

Closes #162

1. What is the API?

In D3D12 and Metal, texel buffer views are exposed the same way as texture views: via SRV/UAV and MTLTexture correspondingly. In Vulkan, there is a separate VkBufferView type describing this object.

I suggest us go with a separate object type as well (as opposed to piggy-backing on GPUTextureView) because the produced view is more restricted than a normal texture view. It can only be used for bind group creation, where we already have an implicit enumeration GPUBindingResource, so it's trivial to extend it.

2. Which texture formats can buffers be viewed as ?

One option would be to have some sort of query to ask the implementation if a specific texture format can be used for a texel view. I think having this query would harm portability and leave heavy fingerprints. Therefore, I suggest us just listing the formats in the spec document for MVP:

format sampled-texel storage-texel
r8unorm v
r8unorm-srgb
r8snorm v
r8uint v
r8sint v
r16unorm
r16snorm
r16uint v
r16sint v
r16float v
rg8unorm v
rg8unorm-srgb
rg8snorm v
rg8uint v
rg8sint v
b5g6r5unorm
r32uint v v
r32sint v v
r32float v v
rg16unorm
rg16snorm
rg16uint v
rg16sint v
rg16float v
rgba8unorm v v
rgba8unorm-srgb
rgba8snorm v v
rgba8uint v v
rgba8sint v v
bgra8unorm v v
bgra8unorm-srgb
rgb10a2unorm v
rg11b10float v
rg32uint v v
rg32sint v v
rg32float v v
rgba16unorm
rgba16snorm
rgba16uint v v
rgba16sint v v
rgba16float v v
rgba32uint v v
rgba32sint v v
rgba32float v v
depth32float
depth32float-stencil8

@Kangz

Kangz commented May 13, 2019

Copy link
Copy Markdown
Contributor

What's the difference between a texel buffer view and a storage buffer? Why do we need both? (I don't really what texel views mean in hardware)

@kvark

kvark commented May 13, 2019

Copy link
Copy Markdown
Contributor Author

Good question. I can't think of a case where a storage texel buffer storage would be better than just a storage buffer. There are some minor things like sampling from it, or an ability to have the same shader handling both buffer and texture storages, but it feels fairly minor.

The read-only (or "sampled") texel buffer views seem useful though.

@dneto0

dneto0 commented May 16, 2019

Copy link
Copy Markdown
Contributor

In Vulkan:

  • the storage texel buffer is does not use sampling, so no filtering is applied. However, it does let you do a format conversion (including swizzle and width conversion) on the load or store. In SPIR-V the OpTypeImage is required to have Sampled=2, (i.e. not used with a sampler), Dim=Buffer. Use OpImageRead with this.
  • the uniform texel buffer is used with images that do have samplers (Sampled=1, Dim=Buffer), but the sampling parameters are ignored so again there is no filtering applied. It again lets you do the format conversion for the accessed texel on load. Use OpImageFetch with this.

@Kangz

Kangz commented May 17, 2019

Copy link
Copy Markdown
Contributor

Thanks for digging into the details of texel buffers in Vulkan. The feature seems completely superseded by storage buffer, so we should postpone this (and I'd suggest we do this indefinitely)

@kvark

kvark commented May 17, 2019

Copy link
Copy Markdown
Contributor Author

Closing as agreed during F2F.

@kvark kvark closed this May 17, 2019
@magcius

magcius commented May 17, 2019 •

Copy link
Copy Markdown

The format conversion parts are necessary for HLSL support, since the type of a StructuredBuffer doesn't necessarily have to match the underlying buffer's format.

@Kangz

Kangz commented May 17, 2019

Copy link
Copy Markdown
Contributor

Buffers are untyped, you can implement StructuredBuffers by loading data and reinterpret_cast in the shader.

@magcius

magcius commented May 17, 2019 •

Copy link
Copy Markdown

reinterpret_cast is not what I mean. I mean that you can load StructuredBuffer<float> from HLSL, and it can be backed by a SN16-typed buffer. In Vulkan, the way to do this is with a texel buffer view, and that's what dxc/spiregg will emit. Removing this functionality from the web makes it difficult to support dxc's StructuredBuffer.

@Kangz

Kangz commented May 17, 2019

Copy link
Copy Markdown
Contributor

The content of buffers is untyped so you an implement that StructuredBuffer with a storage buffer containing an unsized array of floats.

@magcius

magcius commented May 17, 2019

Copy link
Copy Markdown

I understand that I do not describe the buffer type directly to WebGPU, but texel views let me state that buffer contains data packed as SN16 (16-bit signed normal integers representing the range from -1.0 to 1.0) and load it in the shader as a float. This is known as a "typed surface load/store", it's implemented in GLSL through the extension GL_EXT_shader_image_load_formatted, StructuredBuffers in HLSL do it by default, and Vulkan storage buffers do not support it.

@devshgraphicsprogramming

Copy link
Copy Markdown

@dneto0 provides a pretty good summary of what they are in Vulkan.

The feature seems completely superseded by storage buffer, so we should postpone this (and I'd suggest we do this indefinitely)

@Kangz and others, the main reason why there's still a distinction between STB (SSBO in OpenGL) and UTB (TBO in OpenGL) and why Uniform Texel Buffer (no idea why they called it "Uniform" in Vulkan) remains relevant is the following:

  1. UTB/TBO loads go through the same path and cache as texel fetches from normal read-only sampled (and possibly filtered) textures. Because of that, unaligned, swizzled, and/or random address reads from UTBs/TBOs could be expected to be faster than those from SSBOs.
  2. The automatic type conversions as @magcius pointed out
  3. Different Performance characteristics, SSBO might be slower because UTB/TBO is assumed to be read-only, non coherent, etc. Basically on some hardware you'd want to put skinning matrices in TBOs instead of SSBOs, especially the hardware that can produce "waterfalling".

@kvark

kvark commented Aug 7, 2019

Copy link
Copy Markdown
Contributor Author

@devshgraphicsprogramming that's some great info/insight here! I think what's missing is some benchmarking to quantify the benefits of texel buffers, perhaps in extreme cases where it's supposed to be faster.

@devshgraphicsprogramming

Copy link
Copy Markdown

@kvark we've been wanting to profile this for our engine for almost a year
buildaworldnet/IrrlichtBAW#119
I'll check back when/if I'm done, but those tests will be for NVidia/AMD/Intel only, no idea how it looks like on Mobile GPUs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support "uniform texel buffer" and "storage texel buffer" ?

5 participants