diff options
Diffstat (limited to 'prelude')
| -rw-r--r-- | prelude/slang-cpp-types.h | 22 | ||||
| -rw-r--r-- | prelude/slang-cuda-prelude.h | 18 |
2 files changed, 38 insertions, 2 deletions
diff --git a/prelude/slang-cpp-types.h b/prelude/slang-cpp-types.h index d57ac0e09..311fa667d 100644 --- a/prelude/slang-cpp-types.h +++ b/prelude/slang-cpp-types.h @@ -166,6 +166,12 @@ struct ByteAddressBuffer const size_t dataIdx = index >> 2; return uint4{data[dataIdx], data[dataIdx + 1], data[dataIdx + 2], data[dataIdx + 3]}; } + template<typename T> + T Load(size_t offset) const + { + SLANG_PRELUDE_ASSERT(offset + sizeof(T) <= sizeInBytes && (offset & (alignof(T)-1)) == 0); + return *(T const*)((char*)data + offset); + } const uint32_t* data; size_t sizeInBytes; //< Must be multiple of 4 @@ -201,7 +207,13 @@ struct RWByteAddressBuffer const size_t dataIdx = index >> 2; return uint4{data[dataIdx], data[dataIdx + 1], data[dataIdx + 2], data[dataIdx + 3]}; } - + template<typename T> + T Load(size_t offset) const + { + SLANG_PRELUDE_ASSERT(offset + sizeof(T) <= sizeInBytes && (offset & (alignof(T)-1)) == 0); + return *(T const*)((char*)data + offset); + } + void Store(size_t index, uint32_t v) const { SLANG_PRELUDE_ASSERT(index + 4 <= sizeInBytes && (index & 3) == 0); @@ -231,7 +243,13 @@ struct RWByteAddressBuffer data[dataIdx + 2] = v.z; data[dataIdx + 3] = v.w; } - + template<typename T> + void Store(size_t offset, T const& value) const + { + SLANG_PRELUDE_ASSERT(offset + sizeof(T) <= sizeInBytes && (offset & (alignof(T)-1)) == 0); + *(T*)((char*)data + offset) = value; + } + uint32_t* data; size_t sizeInBytes; //< Must be multiple of 4 }; diff --git a/prelude/slang-cuda-prelude.h b/prelude/slang-cuda-prelude.h index 4a91848e4..eb676f03b 100644 --- a/prelude/slang-cuda-prelude.h +++ b/prelude/slang-cuda-prelude.h @@ -383,6 +383,12 @@ struct ByteAddressBuffer const size_t dataIdx = index >> 2; return uint4{data[dataIdx], data[dataIdx + 1], data[dataIdx + 2], data[dataIdx + 3]}; } + template<typename T> + SLANG_CUDA_CALL T Load(size_t offset) const + { + SLANG_PRELUDE_ASSERT(offset + sizeof(T) <= sizeInBytes && (offset & (alignof(T)-1)) == 0); + return *(T const*)((char*)data + offset); + } const uint32_t* data; size_t sizeInBytes; //< Must be multiple of 4 @@ -418,6 +424,12 @@ struct RWByteAddressBuffer const size_t dataIdx = index >> 2; return uint4{data[dataIdx], data[dataIdx + 1], data[dataIdx + 2], data[dataIdx + 3]}; } + template<typename T> + SLANG_CUDA_CALL T Load(size_t offset) const + { + SLANG_PRELUDE_ASSERT(offset + sizeof(T) <= sizeInBytes && (offset & (alignof(T)-1)) == 0); + return *(T const*)((char*)data + offset); + } SLANG_CUDA_CALL void Store(size_t index, uint32_t v) const { @@ -448,6 +460,12 @@ struct RWByteAddressBuffer data[dataIdx + 2] = v.z; data[dataIdx + 3] = v.w; } + template<typename T> + SLANG_CUDA_CALL void Store(size_t offset, T const& value) const + { + SLANG_PRELUDE_ASSERT(offset + sizeof(T) <= sizeInBytes && (offset & (alignof(T)-1)) == 0); + *(T*)((char*)data + offset) = value; + } uint32_t* data; size_t sizeInBytes; //< Must be multiple of 4 |
