microsoft / hlsl-specs

HLSL Specifications
MIT License
124 stars 35 forks source link

[0010] The layout of the pointee buffer is not well defined. #306

Open s-perron opened 3 months ago

s-perron commented 3 months ago

Which document does this relate to? https://github.com/microsoft/hlsl-specs/blob/9c42e278961dbf5b77d7d18b1e7ba7f6c0856154/proposals/0010-vk-buffer-ref.md

Describe the issue you see with the spec

In the Buffer Pointer Pointee Buffer Layout section, it says:

The pointee of a vk::BufferPointer is considered to be a buffer and will be laid out as the user directs all buffers to be laid out

The problem is that I am not sure why type of buffer this is referring to. I assume it refers to structured buffers, but it could be a constant buffer, which are laid out differently. See the SPIR-V documentation for how different types are laid out.

Note that the types have to follow the standard storage buffer layout rules.

It is also worth considering the conversations in https://github.com/microsoft/DirectXShaderCompiler/issues/4924.

Additional context

The layout for the vk::RawBuffer* have been an issue for people, and we should avoid the same mistakes with vk::BufferPointer. The layout needs to be well documented, and tested.

s-perron commented 3 months ago

@cassiebeckley Could you please look into this?

devshgraphicsprogramming commented 3 months ago

Any device that has the non-uvec2 variant (uint64_t) of Buffer Device Address, is extremely likely to have Scalar Layout as a feature as well.

P.S. SSBOs can be laid out as UBOs as well (and scalar laid out too), so there's at least 3 different possible layouts that can be applied there.

P.P.S. -fkv-use-scalar-layout makes all HLSL StructuredBuffers have a scalar layout, I'd just dodge the bullet and require RawBufferPointers to always be scalar instead of having a headache of supporting two layouts in the codegen for that.