diff options
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/slang-emit.cpp | 2 | ||||
| -rw-r--r-- | source/slang/slang-ir-collect-global-uniforms.cpp | 49 | ||||
| -rw-r--r-- | source/slang/slang-ir-collect-global-uniforms.h | 5 |
3 files changed, 52 insertions, 4 deletions
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index f5b818c5d..31e6d17be 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -802,7 +802,7 @@ Result linkAndOptimizeIR( // can assume that all ordinary/uniform data is strictly // passed using constant buffers. // - collectGlobalUniformParameters(irModule, outLinkedIR.globalScopeVarLayout); + collectGlobalUniformParameters(irModule, outLinkedIR.globalScopeVarLayout, target); #if 0 dumpIRIfEnabled(codeGenContext, irModule, "GLOBAL UNIFORMS COLLECTED"); #endif diff --git a/source/slang/slang-ir-collect-global-uniforms.cpp b/source/slang/slang-ir-collect-global-uniforms.cpp index fb2a2233c..aad0de44f 100644 --- a/source/slang/slang-ir-collect-global-uniforms.cpp +++ b/source/slang/slang-ir-collect-global-uniforms.cpp @@ -49,6 +49,7 @@ struct CollectGlobalUniformParametersContext // IRModule* module; IRVarLayout* globalScopeVarLayout; + CodeGenTarget target = CodeGenTarget::Unknown; IRGlobalParam* _getGlobalParamFromLayoutFieldKey(IRInst* key) { @@ -174,7 +175,47 @@ struct CollectGlobalUniformParametersContext // parameters that were present in the layout information (they are // represented as the fields of the global-scope `struct` layout). // - for (auto fieldLayoutAttr : globalParamsStructTypeLayout->getFieldLayoutAttrs()) + // For CUDA targets, we need to ensure unsized arrays come last to satisfy + // the layout constraint in slang-ir-layout.cpp + auto fieldAttrs = globalParamsStructTypeLayout->getFieldLayoutAttrs(); + + // Create ordered field list - for CUDA, put unsized arrays last + List<IRStructFieldLayoutAttr*> orderedFields; + + if (target == CodeGenTarget::CUDASource) + { + // For CUDA: separate regular and unsized array fields + List<IRStructFieldLayoutAttr*> regularFields; + List<IRStructFieldLayoutAttr*> unsizedArrayFields; + + for (auto fieldLayoutAttr : fieldAttrs) + { + auto globalParam = + _getGlobalParamFromLayoutFieldKey(fieldLayoutAttr->getFieldKey()); + if (globalParam && as<IRUnsizedArrayType>(globalParam->getDataType())) + { + unsizedArrayFields.add(fieldLayoutAttr); + } + else + { + regularFields.add(fieldLayoutAttr); + } + } + + // Add regular fields first, then unsized arrays + for (auto field : regularFields) + orderedFields.add(field); + for (auto field : unsizedArrayFields) + orderedFields.add(field); + } + else + { + // For other targets: preserve original order + for (auto field : fieldAttrs) + orderedFields.add(field); + } + + for (auto fieldLayoutAttr : orderedFields) { // We expect the IR layout pass to have encoded field per-field // layout so that the "key" for the field is the corresponding @@ -339,11 +380,15 @@ struct CollectGlobalUniformParametersContext } }; -void collectGlobalUniformParameters(IRModule* module, IRVarLayout* globalScopeVarLayout) +void collectGlobalUniformParameters( + IRModule* module, + IRVarLayout* globalScopeVarLayout, + CodeGenTarget target) { CollectGlobalUniformParametersContext context; context.module = module; context.globalScopeVarLayout = globalScopeVarLayout; + context.target = target; context.processModule(); } diff --git a/source/slang/slang-ir-collect-global-uniforms.h b/source/slang/slang-ir-collect-global-uniforms.h index 76f56f074..5f9393a9b 100644 --- a/source/slang/slang-ir-collect-global-uniforms.h +++ b/source/slang/slang-ir-collect-global-uniforms.h @@ -11,6 +11,9 @@ struct IRVarLayout; /// Collect global-scope shader parameters that use uniform/ordinary /// storage into a single `struct` (possibly wrapped in a constant buffer). /// -void collectGlobalUniformParameters(IRModule* module, IRVarLayout* globalScopeVarLayout); +void collectGlobalUniformParameters( + IRModule* module, + IRVarLayout* globalScopeVarLayout, + CodeGenTarget target = CodeGenTarget::Unknown); } // namespace Slang |
