diff options
| author | Yong He <yonghe@outlook.com> | 2023-08-23 05:49:33 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-23 20:49:33 +0800 |
| commit | 6437c38e0a3c2c1daf36cb5e543dc0b467fa4b15 (patch) | |
| tree | c117b964ada397d9cac01ff4759bcd16d35c7e20 /prelude | |
| parent | cdd5e6666f98903d61118ada5cba51424fd1577c (diff) | |
Lower all ByteAddressBuffer uses for SPIRV. (#3143)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'prelude')
| -rw-r--r-- | prelude/slang-cuda-prelude.h | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/prelude/slang-cuda-prelude.h b/prelude/slang-cuda-prelude.h index 1447be05b..ad757bdbb 100644 --- a/prelude/slang-cuda-prelude.h +++ b/prelude/slang-cuda-prelude.h @@ -1251,7 +1251,9 @@ struct ByteAddressBuffer SLANG_CUDA_CALL T Load(size_t index) const { SLANG_BOUND_CHECK_BYTE_ADDRESS(index, sizeof(T), sizeInBytes); - return *(const T*)(((const char*)data) + index); + T data; + memcpy(&data, ((const char*)this->data) + index, sizeof(T)); + return data; } const uint32_t* data; @@ -1292,7 +1294,9 @@ struct RWByteAddressBuffer SLANG_CUDA_CALL T Load(size_t index) const { SLANG_BOUND_CHECK_BYTE_ADDRESS(index, sizeof(T), sizeInBytes); - return *(const T*)((const char*)data + index); + T data; + memcpy(&data, ((const char*)this->data) + index, sizeof(T)); + return data; } SLANG_CUDA_CALL void Store(size_t index, uint32_t v) const @@ -1328,14 +1332,14 @@ struct RWByteAddressBuffer SLANG_CUDA_CALL void Store(size_t index, T const& value) const { SLANG_BOUND_CHECK_BYTE_ADDRESS(index, sizeof(T), sizeInBytes); - *(T*)(((char*)data) + index) = value; + memcpy((char*)data + index, &value, sizeof(T)); } /// Can be used in stdlib to gain access template <typename T> SLANG_CUDA_CALL T* _getPtrAt(size_t index) { - SLANG_BOUND_CHECK_BYTE_ADDRESS(index, sizeof(T), sizeInBytes); + SLANG_BOUND_CHECK_BYTE_ADDRESS(index, 4, sizeInBytes); return (T*)(((char*)data) + index); } |
