microsoft / microsoft/hlsl-specs
Allow pointer math operations with vk::BufferPointer
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 222
- Forks
- 57
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 5
Description
Which proposal does this relate to?
https://github.com/microsoft/hlsl-specs/blob/main/proposals/0010-vk-buffer-ref.md
Describe the issue or outstanding question.
It would be very useful to allow pointer math with vk::BufferPointer. In the current state it isn't possible, as the DirectXCompiler doesn't accept math operations for vk::BufferPointer.
Example when trying to compile the following shader code (I tried in different ways, using .Get() too):
struct VSOutput {
float4 position : SV_Position;
float4 color : COLOR;
float3 normal : NORMAL;
float2 uv : TEXCOORD0;
};
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float4 color;
};
struct PushConstantsStruct
{
column_major float4x4 mvp;
vk::BufferPointer<Vertex> m_nBufferDeviceAddress;
};
[[vk::push_constant]] PushConstantsStruct PushConstants;
VSOutput main(uint vertexIndex : SV_VertexID) {
Vertex vertex = PushConstants.m_nBufferDeviceAddress + vertexIndex;
}
The returned error:
.\triangle_vert.hlsl:74:58: error: scalar, vector, or matrix expected
Vertex vertex = PushConstants.m_nBufferDeviceAddress + vertexIndex;
A workaround to this issue would be using a struct with an unsized array (for example Vertex vertices[]), but unfortunately it isn't possible in HLSL.
Instead, another workaround (which works with the latest state of DXC) would be computing an offset in bytes manually, add that offset to the base device pointer passed in input, and then bitcasting it into a vk::BufferPointer... but this is an extensive job to do every time.
Additional context
In the Slang Shading language pointer math is very easy to do, just like in GLSL.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with proposals/0010-vk-buffer-ref.md and the shader reproducer in this issue, then inspect how DXC currently handles vk::BufferPointer expressions. Define and validate the supported pointer arithmetic semantics, including the shown buffer-pointer plus vertex-index case. Done means the example compiles without manual byte-offset computation and the behavior is covered by appropriate compiler tests.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100