Skip to content

Commit 487ae03

Browse files
authored
Add LoadAligned and StoreAligned methods to ByteAddressBuffers (shader-slang#4066)
Fixes shader-slang#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.
1 parent 9f23046 commit 487ae03

14 files changed

+561
-90
lines changed

source/slang/core.meta.slang

+9
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,15 @@ int __naturalStrideOf()
24122412
return __naturalStrideOf_impl(__declVal<T>());
24132413
}
24142414

2415+
__intrinsic_op($(kIROp_AlignOf))
2416+
int __alignOf_intrinsic_impl<T>(T t);
2417+
2418+
[ForceInline]
2419+
int __alignOf_intrinsic<T>()
2420+
{
2421+
return __alignOf_intrinsic_impl<T>(__default<T>());
2422+
}
2423+
24152424
__intrinsic_op($(kIROp_TreatAsDynamicUniform))
24162425
T asDynamicUniform<T>(T v);
24172426

0 commit comments

Comments
 (0)