summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-type-layout.cpp12
-rw-r--r--source/slang/slang-type-layout.h4
2 files changed, 8 insertions, 8 deletions
diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp
index 0fc7958d0..fe32c93b1 100644
--- a/source/slang/slang-type-layout.cpp
+++ b/source/slang/slang-type-layout.cpp
@@ -369,6 +369,8 @@ struct HLSLConstantBufferLayoutRulesImpl : DefaultLayoutRulesImpl
}
};
+/* CPU layout requires that all sizes are a multiple of alignment.
+*/
struct CPULayoutRulesImpl : DefaultLayoutRulesImpl
{
typedef DefaultLayoutRulesImpl Super;
@@ -385,6 +387,7 @@ struct CPULayoutRulesImpl : DefaultLayoutRulesImpl
return SimpleLayoutInfo( LayoutResourceKind::Uniform, 1, 1 );
}
+ // This always returns a layout where the size is the same as the alignment.
default: return Super::GetScalarLayout(baseType);
}
}
@@ -519,14 +522,7 @@ struct CUDALayoutRulesImpl : DefaultLayoutRulesImpl
// Nothing is aligned more than 16
alignment = std::min(alignment, size_t(16));
- // TODO(JS): It's not 100% clear what is right in terms of size in respect of *alignment*. If the size is the 'used' bytes, then
- // it can be less that the aligned size. If that's the case the GetArrayLayout (and MatrixLayout) is *wrong* in that on the last element
- // it uses the size (not the aligned size/stride).
- //
- // Here I am assuming it's reasonable for the size to be the aligned size. That being the case the GetArrayLayout/GetMatrixLayout will be
- // correct without special handling.
- //
- // The assert below checks that is indeed the case.
+ // For CUDA the size must be a multiple of alignment, as this is the amount of bytes used 'exclusively' by the type.
// The size must be a multiple of the alignment
SLANG_ASSERT(_isAligned(size, alignment));
diff --git a/source/slang/slang-type-layout.h b/source/slang/slang-type-layout.h
index be7ccdf8f..8c50b4eb3 100644
--- a/source/slang/slang-type-layout.h
+++ b/source/slang/slang-type-layout.h
@@ -251,6 +251,10 @@ struct SimpleLayoutInfo
LayoutResourceKind kind;
// How many resources of that kind?
+ //
+ // For uniform, the size is the number of bytes "reserved" exclusively for an instance of that type.
+ // In *general* it is not necessary for a size to be rounded up to the alignment. Some targets do
+ // though - for example C++ and CUDA targets always have size as a multiple of alignment.
LayoutSize size;
// only useful in the uniform case