diff options
| author | Julius Ikkala <julius.ikkala@gmail.com> | 2025-08-21 08:47:18 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-21 05:47:18 +0000 |
| commit | 35f8e092f2aa3ed5e3cf03387e712f798ff4850e (patch) | |
| tree | bdafc75e4df90157568758ebf7b8128ecd066f0c /source/slang/slang-ir-lower-buffer-element-type.cpp | |
| parent | 05f0f5603561daed2c134e13bc64649362759968 (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-ir-lower-buffer-element-type.cpp')
| -rw-r--r-- | source/slang/slang-ir-lower-buffer-element-type.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/source/slang/slang-ir-lower-buffer-element-type.cpp b/source/slang/slang-ir-lower-buffer-element-type.cpp index ed0a3b309..2f40c6cf9 100644 --- a/source/slang/slang-ir-lower-buffer-element-type.cpp +++ b/source/slang/slang-ir-lower-buffer-element-type.cpp @@ -426,6 +426,8 @@ struct LoweredElementTypeContext return "std430"; case IRTypeLayoutRuleName::Natural: return "natural"; + case IRTypeLayoutRuleName::C: + return "c"; default: return "default"; } @@ -797,7 +799,26 @@ struct LoweredElementTypeContext if (as<IRBoolType>(scalarType)) { // Bool is an abstract type in SPIRV, so we need to lower them into an int. - info.loweredType = builder.getIntType(); + + // Find an integer type of the correct size for the current layout rule. + IRSizeAndAlignment boolSizeAndAlignment; + if (getSizeAndAlignment( + target->getOptionSet(), + config.layoutRule, + scalarType, + &boolSizeAndAlignment) == SLANG_OK) + { + IntInfo ii; + ii.width = boolSizeAndAlignment.size * 8; + ii.isSigned = true; + info.loweredType = builder.getType(getIntTypeOpFromInfo(ii)); + } + else + { + // Just in case that fails for some reason, just use an int. + info.loweredType = builder.getIntType(); + } + if (vectorType) info.loweredType = builder.getVectorType( info.loweredType, @@ -1467,6 +1488,8 @@ IRTypeLayoutRules* getTypeLayoutRulesFromOp(IROp layoutTypeOp, IRTypeLayoutRules return IRTypeLayoutRules::getStd430(); case kIROp_ScalarBufferLayoutType: return IRTypeLayoutRules::getNatural(); + case kIROp_CBufferLayoutType: + return IRTypeLayoutRules::getC(); } return defaultLayout; } @@ -1482,6 +1505,10 @@ IRTypeLayoutRules* getTypeLayoutRuleForBuffer(TargetProgram* target, IRType* buf if (!target->shouldEmitSPIRVDirectly()) return IRTypeLayoutRules::getNatural(); + // If the user specified a C-compatible buffer layout, then do that. + if (target->getOptionSet().shouldUseCLayout()) + return IRTypeLayoutRules::getC(); + // If the user specified a scalar buffer layout, then just use that. if (target->getOptionSet().shouldUseScalarLayout()) return IRTypeLayoutRules::getNatural(); |
