diff options
| author | Sriram Murali <85252063+sriramm-nv@users.noreply.github.com> | 2024-05-13 23:57:57 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-13 23:57:57 -0700 |
| commit | 487ae034e2b03ddd67945132c8fecbd937952705 (patch) | |
| tree | 036d318a64385151ad9d5e7275c2e387fdca6cee /tests/compute/byte-address-buffer-align-error.slang | |
| parent | 9f23046138629f78995d54a7722ad6749bd84db9 (diff) | |
Add LoadAligned and StoreAligned methods to ByteAddressBuffers (#4066)
Fixes #4062
This change enables wide load/stores for byte-address-buffer backed
resources, when the data is accessed at an offset that is aligned.
**Goals**
- Improve performance by issuing wider instructions instead of sequence
of scalar instructions, for load and stores of byte-address buffers.
- Reduce code-size and readability of the generated shaders.
- Help naive users as well as ninja programmers, generate optimal code.
**Non Goals**
- Help with Structured buffers, or other resources.
- Target compilation time improvements.
**Key changes**
Adds 2 new overloads for Load and Store operations on ByteAddress Buffers.
1. Load / Store with an extra alignment parameter
```
resource.Load<T>(offset, alignment);
resource.Store<T>(offset, value, alignment);
```
2. LoadAligned / StoreAligned with no extra parameter,
with the same signature as orignial Load / Store.
```
resource.LoadAligned<T>(offset);
resource.StoreAligned<T>(offset, value);
```
- This overload will implicitly identify the alignment value,
from the base type T of the elementary unit of the resource.
**Supported resources**
1. Vectors
This can be upto 4 elements, i.e. float -- float4.
2. Arrays
This does not have a limit on number of elements, but on a
conservative estimate, we can limit to few hundreds.
3. Structures
This is used to group a resource of a single type.
```
struct {
float4 x;
}
```
**Code updates**
- Modified byte-address-ir legalize to handle struct, array and vector
kinds of load or store access
- Added custom hlsl stdlib functions to implement all the overloads for Load,
Store etc.
- Added C-like emitter, SPIR-V emitter for handling ByteAddressBuffers.
- Added a new core stdlib function intrinsic to wrap around alignOf<T>().
- Added a new peephole optimization entry to identify the equivalent
IntLiteral value from the alignOf<T>() inst.
- Added tests to check explicit, and implicit aligned Load and Store
operations.
Diffstat (limited to 'tests/compute/byte-address-buffer-align-error.slang')
| -rw-r--r-- | tests/compute/byte-address-buffer-align-error.slang | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/compute/byte-address-buffer-align-error.slang b/tests/compute/byte-address-buffer-align-error.slang new file mode 100644 index 000000000..34300d7c3 --- /dev/null +++ b/tests/compute/byte-address-buffer-align-error.slang @@ -0,0 +1,24 @@ +// byte-address-buffer-align-error.slang + +//TEST:SIMPLE(filecheck=CHECK):-target glsl -entry computeMain -stage compute +//TEST:SIMPLE(filecheck=CHECK):-target hlsl -entry computeMain -stage compute +//TEST:SIMPLE(filecheck=CHECK):-target spirv -entry computeMain -stage compute +//TEST:SIMPLE(filecheck=CHECK):-target spirv -emit-spirv-directly -entry computeMain -stage compute + +// Confirm compilation of `(RW)ByteAddressBuffer` with aligned load / stores to wider data types. + +[vk::binding(2, 3)] RWByteAddressBuffer buffer; +struct Block { + float4 val[2]; +}; +[shader("compute")] +[numthreads(1,1,1)] +void computeMain(uint3 threadId : SV_DispatchThreadID) +{ + // CHECK: error 41300: invalid alignment `{{.*}}` specified for the byte address buffer resource with the element size of `{{.*}}` + // CHECK: error 41300: invalid alignment `{{.*}}` specified for the byte address buffer resource with the element size of `{{.*}}` + buffer.Store<Block>(0, buffer.Load<Block>(1, 5)); + buffer.Store<Block>(1, buffer.Load<Block>(0), 3); + +} + |
