Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPIR-V] Naive codegen for ByteAddressBuffer #3533

Closed
HansKristian-Work opened this issue Jan 31, 2024 · 0 comments · Fixed by #4036
Closed

[SPIR-V] Naive codegen for ByteAddressBuffer #3533

HansKristian-Work opened this issue Jan 31, 2024 · 0 comments · Fixed by #4036
Assignees
Labels
goal:client support Feature or fix needed for a current slang user. kind:enhancement a desirable new feature, option, or behavior

Comments

@HansKristian-Work
Copy link

[vk::binding(2, 3)] RWByteAddressBuffer buffer0;

[shader("compute")]
[numthreads(1,1,1)]
void computeMain(uint3 threadId : SV_DispatchThreadID)
{
	buffer0.Store(64, buffer0.Load<uint4>(32));
}
#version 450
layout(row_major) uniform;
layout(row_major) buffer;
layout(std430, binding = 2, set = 3) buffer StructuredBuffer_uint_t_0 {
    uint _data[];
} buffer0_0;

#line 7 0
uvec4 RWByteAddressBuffer_Load_0(int _S1)
{

#line 2192 1
    return uvec4(buffer0_0._data[_S1 / 4], buffer0_0._data[(_S1 + 4) / 4], buffer0_0._data[(_S1 + 8) / 4], buffer0_0._data[(_S1 + 12) / 4]);
}


#line 2192
void RWByteAddressBuffer_Store_0(int _S2, uvec4 _S3)
{

#line 2192
    uint _S4 = buffer0_0._data[_S2 / 4] = _S3[0];

#line 2192
    uint _S5 = buffer0_0._data[(_S2 + 4) / 4] = _S3[1];

#line 2192
    uint _S6 = buffer0_0._data[(_S2 + 8) / 4] = _S3[2];

#line 2192
    uint _S7 = buffer0_0._data[(_S2 + 12) / 4] = _S3[3];

#line 2733
    return;
}


#line 5 0
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main()
{

#line 5
    RWByteAddressBuffer_Store_0(64, RWByteAddressBuffer_Load_0(32));


    return;
}

Scalar unroll happens even when offsets are known to be aligned. Slang should support a version of Load/Store that takes explicit alignment, and vectorizes the access appropriately. dxil-spirv does heroics here for example.

@csyonghe csyonghe added the kind:enhancement a desirable new feature, option, or behavior label Feb 1, 2024
@csyonghe csyonghe added this to the Q2 2024 (Spring) milestone Feb 1, 2024
@swoods-nv swoods-nv added the goal:client support Feature or fix needed for a current slang user. label Feb 22, 2024
sriramm-nv added a commit to sriramm-nv/slang that referenced this issue Apr 25, 2024
Fixes shader-slang#3533

- Add a new VectorizedLoad and VectorizedStore function in ByteAddress
legalize pass
sriramm-nv added a commit to sriramm-nv/slang that referenced this issue Apr 26, 2024
Fixes shader-slang#3533

- Add a new VectorizedLoad and VectorizedStore function in ByteAddress
legalize pass
sriramm-nv added a commit to sriramm-nv/slang that referenced this issue Apr 29, 2024
Fixes shader-slang#3533

- Add a new VectorizedLoad and VectorizedStore function in ByteAddress
legalize pass
sriramm-nv added a commit to sriramm-nv/slang that referenced this issue Apr 30, 2024
Fixes shader-slang#3533

- Add a new VectorizedLoad and VectorizedStore function in ByteAddress
legalize pass
sriramm-nv added a commit that referenced this issue Apr 30, 2024
Fixes #3533

- Add logic to perform aligned memory operations for loading from and storing to composite resources, like vectors within the ByteAddress legalize pass.

- Checks 
Added a new test for byte address with/without alignment.

---------

Co-authored-by: Yong He <yonghe@outlook.com>
djohansson pushed a commit to djohansson/slang that referenced this issue Sep 21, 2024
…-slang#4036)

Fixes shader-slang#3533

- Add logic to perform aligned memory operations for loading from and storing to composite resources, like vectors within the ByteAddress legalize pass.

- Checks 
Added a new test for byte address with/without alignment.

---------

Co-authored-by: Yong He <yonghe@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:client support Feature or fix needed for a current slang user. kind:enhancement a desirable new feature, option, or behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants