summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-emit-spirv.cpp
diff options
context:
space:
mode:
authorJulius Ikkala <julius.ikkala@gmail.com>2025-08-21 08:47:18 +0300
committerGitHub <noreply@github.com>2025-08-21 05:47:18 +0000
commit35f8e092f2aa3ed5e3cf03387e712f798ff4850e (patch)
treebdafc75e4df90157568758ebf7b8128ecd066f0c /source/slang/slang-emit-spirv.cpp
parent05f0f5603561daed2c134e13bc64649362759968 (diff)
Introduce CDataLayout & -fvk-use-c-layout (#8136)
Closes #8112. ~~The issue asks for a "C layout", but in this PR I use the term "CPU layout" because this naming was pre-existing in the codebase as `kCPULayoutRulesImpl_`. The primary purpose of this layout is to match CPU-side struct definitions with the shader side. I'm open to better naming suggestions, though.~~ Edit: switched back to using `CDataLayout` & `-fvk-use-c-layout`, as the CPU target depends on the object layout rules of existing CPU layout rules, but they're incompatible with actual shaders. So a new `kCLayoutRulesImpl_` was needed anyway. --------- Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
Diffstat (limited to 'source/slang/slang-emit-spirv.cpp')
-rw-r--r--source/slang/slang-emit-spirv.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index 6b42896d0..d6f4ac176 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -1847,10 +1847,22 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
IRSizeAndAlignment sizeAndAlignment;
uint32_t stride;
- getNaturalSizeAndAlignment(
- m_targetProgram->getOptionSet(),
- valueType,
- &sizeAndAlignment);
+ if (auto layout = valueType->findDecoration<IRSizeAndAlignmentDecoration>())
+ {
+ auto rule = IRTypeLayoutRules::get(layout->getLayoutName());
+ getSizeAndAlignment(
+ m_targetProgram->getOptionSet(),
+ rule,
+ valueType,
+ &sizeAndAlignment);
+ }
+ else
+ {
+ getNaturalSizeAndAlignment(
+ m_targetProgram->getOptionSet(),
+ valueType,
+ &sizeAndAlignment);
+ }
uint64_t valueSize = sizeAndAlignment.size;
// Any unsized data type (e.g. struct or array) will have size of