diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2021-06-10 14:57:09 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-10 11:57:09 -0700 |
| commit | 37e8917d10626b519470f2e34625f0efe741352f (patch) | |
| tree | 4e8e51bd63ebc03fcdf0c893b675906cf507d73c /source/slang/core.meta.slang | |
| parent | 0d9bd79e8fd4d57e1a723ca6b6a45efec2b42872 (diff) | |
CUDA layout corner cases/testing (#1881)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Add support for sizeOf/alignOf/offsetOf to stdlib.
Add $G intrinsic expansion that works of the generic parameters not the param type
* Test cuda layout.
* Fix CUDA layout issues.
Fix reflection to handle other built in types.
Fix __offsetOf
* Tests of reflection and layout as reported directly from CUDA.
* Comment about use of aligned size as size.
* Fix warning from VS.
* Check alignment is pow2.
* Small improvements to alignment calcs.
* Tab to spaces.
* Fix alignment pointer sizes on 32 bit OS for CUDA.
* Fix CUDA reflection on 32 bit.
Diffstat (limited to 'source/slang/core.meta.slang')
| -rw-r--r-- | source/slang/core.meta.slang | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index afdd96029..761316d86 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -1962,6 +1962,35 @@ __target_intrinsic(cuda, " @ ") __target_intrinsic(cpp, " @ ") int __SyntaxError(); +/// For downstream compilers that allow sizeof/alignof/offsetof +/// Can't be called in the C/C++ style. Need to use __size_of<some_type>() as opposed to sizeof(some_type). +__generic<T> +__target_intrinsic(cuda, "sizeof($G0)") +__target_intrinsic(cpp, "sizeof($G0)") +int __sizeOf(); + +__generic<T> +__target_intrinsic(cuda, "sizeof($T0)") +__target_intrinsic(cpp, "sizeof($T0)") +int __sizeOf(T v); + +__generic<T> +__target_intrinsic(cuda, "SLANG_ALIGN_OF($G0)") +__target_intrinsic(cpp, "SLANG_ALIGN_OF($G0)") +int __alignOf(); + +__generic<T> +__target_intrinsic(cuda, "SLANG_ALIGN_OF($T0)") +__target_intrinsic(cpp, "SLANG_ALIGN_OF($T0)") +int __alignOf(T v); + +// It would be nice to have offsetof equivalent, but it's not clear how that would work in terms of the Slang language. +// Here we allow calculating the offset of a field in bytes from an *instance* of the type. +__generic<T,F> +__target_intrinsic(cuda, "int(((char*)&($1)) - ((char*)&($0)))") +__target_intrinsic(cpp, "int(((char*)&($1)) - ((char*)&($0))") +int __offsetOf(in T t, in F field); + /// Mark beginning of "interlocked" operations in a fragment shader. __target_intrinsic(glsl, "beginInvocationInterlockARB") __glsl_extension(GL_ARB_fragment_shader_interlock) |
