From 37e8917d10626b519470f2e34625f0efe741352f Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 10 Jun 2021 14:57:09 -0400 Subject: 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. --- source/slang/core.meta.slang | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'source/slang/core.meta.slang') 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() as opposed to sizeof(some_type). +__generic +__target_intrinsic(cuda, "sizeof($G0)") +__target_intrinsic(cpp, "sizeof($G0)") +int __sizeOf(); + +__generic +__target_intrinsic(cuda, "sizeof($T0)") +__target_intrinsic(cpp, "sizeof($T0)") +int __sizeOf(T v); + +__generic +__target_intrinsic(cuda, "SLANG_ALIGN_OF($G0)") +__target_intrinsic(cpp, "SLANG_ALIGN_OF($G0)") +int __alignOf(); + +__generic +__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 +__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) -- cgit v1.2.3