From e1c6fecd90142761aaecbf4e281beb87893fc531 Mon Sep 17 00:00:00 2001 From: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Date: Mon, 26 Aug 2024 15:11:41 -0400 Subject: Implement `-fvk-use-dx-layout` (#4912) * Implement `-fvk-use-dx-layout` Fixes: #4126 Changes: * Added fvk-use-dx-layout * Modified `HLSLConstantBufferLayoutRulesImpl` for correctness (ex: Array is always 16 byte aligned) * Added kFXCShaderResourceLayoutRulesFamilyImpl and kFXCConstantBufferLayoutRulesFamilyImpl to handle fvk-use-dx-layout * Added `ConstantBufferLayoutRules` to manage constant buffer rules * Added `alignCompositeElementOfNonAggregate`/`alignCompositeElementOfAggregate` to handle forced alignment of composites for ConstantBuffers * `StructuredBuffer` rules are mostly equal to `scalar` layout, not much was needed to be changed to support this behavior. * seperate legacy constant buffer and how Slang does constant-buffer normally * undo an addition * remove accidental test * Address review and fix Address review and remove GLSL support since GLSL requires a seperate legalization (need to linearlize structs like with `legalizeMetalIR` to assign explicit offsets) * comments * remove aggregate and non-aggregate logic We don't need this distinction for the logic --------- Co-authored-by: Yong He --- source/slang/slang-type-layout.cpp | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-type-layout.cpp') diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp index f5fbfafdf..7d6d047d3 100644 --- a/source/slang/slang-type-layout.cpp +++ b/source/slang/slang-type-layout.cpp @@ -400,6 +400,12 @@ struct HLSLConstantBufferLayoutRulesImpl : DefaultLayoutRulesImpl } }; +/// GLSL fvk-use-dx-layout for `ShaderResource` +struct FXCShaderResourceLayoutRulesImpl : DefaultLayoutRulesImpl +{ + // Currently this FXC layout is equal to how we compute 'DefaultLayoutRulesImpl' +}; + /* CPU layout requires that all sizes are a multiple of alignment. */ struct CPULayoutRulesImpl : DefaultLayoutRulesImpl @@ -894,6 +900,7 @@ struct CUDARayTracingLayoutRulesImpl : DefaultVaryingLayoutRulesImpl DefaultLayoutRulesImpl kDefaultLayoutRulesImpl; Std140LayoutRulesImpl kStd140LayoutRulesImpl; Std430LayoutRulesImpl kStd430LayoutRulesImpl; +FXCShaderResourceLayoutRulesImpl kFXCShaderResourceLayoutRulesImpl; HLSLConstantBufferLayoutRulesImpl kHLSLConstantBufferLayoutRulesImpl; HLSLStructuredBufferLayoutRulesImpl kHLSLStructuredBufferLayoutRulesImpl; @@ -1206,6 +1213,18 @@ LayoutRulesImpl kScalarLayoutRulesImpl_ = { &kGLSLObjectLayoutRulesImpl, }; +LayoutRulesImpl kFXCShaderResourceLayoutRulesFamilyImpl = { + &kGLSLLayoutRulesFamilyImpl, + &kFXCShaderResourceLayoutRulesImpl, + &kGLSLObjectLayoutRulesImpl, +}; + +LayoutRulesImpl kFXCConstantBufferLayoutRulesFamilyImpl = { + &kGLSLLayoutRulesFamilyImpl, + &kHLSLConstantBufferLayoutRulesImpl, + &kGLSLObjectLayoutRulesImpl, +}; + LayoutRulesImpl kGLSLAnyValueLayoutRulesImpl_ = { &kGLSLLayoutRulesFamilyImpl, &kDefaultLayoutRulesImpl, @@ -1300,6 +1319,9 @@ LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getConstantBufferRules(CompilerOptio { if (compilerOptions.shouldUseScalarLayout()) return &kScalarLayoutRulesImpl_; + else if (compilerOptions.shouldUseDXLayout()) + return &kFXCConstantBufferLayoutRulesFamilyImpl; + return &kStd140LayoutRulesImpl_; } @@ -1307,6 +1329,9 @@ LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getParameterBlockRules(CompilerOptio { if (compilerOptions.shouldUseScalarLayout()) return &kScalarLayoutRulesImpl_; + else if (compilerOptions.shouldUseDXLayout()) + return &kFXCConstantBufferLayoutRulesFamilyImpl; + return &kStd140LayoutRulesImpl_; } @@ -1324,6 +1349,9 @@ LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getTextureBufferRules(CompilerOption { if (compilerOptions.shouldUseScalarLayout()) return &kScalarLayoutRulesImpl_; + else if (compilerOptions.shouldUseDXLayout()) + return &kFXCConstantBufferLayoutRulesFamilyImpl; + return &kStd430LayoutRulesImpl_; } @@ -1347,6 +1375,9 @@ LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getShaderStorageBufferRules(Compiler { if (compilerOptions.shouldUseScalarLayout()) return &kScalarLayoutRulesImpl_; + else if (compilerOptions.shouldUseDXLayout()) + return &kFXCShaderResourceLayoutRulesFamilyImpl; + return &kStd430LayoutRulesImpl_; } @@ -1365,10 +1396,13 @@ LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getHitAttributesParameterRules() return &kGLSLHitAttributesParameterLayoutRulesImpl_; } -LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getStructuredBufferRules(CompilerOptionSet& options) +LayoutRulesImpl* GLSLLayoutRulesFamilyImpl::getStructuredBufferRules(CompilerOptionSet& compilerOptions) { - if (options.shouldUseScalarLayout()) + if (compilerOptions.shouldUseScalarLayout()) return &kScalarLayoutRulesImpl_; + else if (compilerOptions.shouldUseDXLayout()) + return &kFXCShaderResourceLayoutRulesFamilyImpl; + return &kGLSLStructuredBufferLayoutRulesImpl_; } -- cgit v1.2.3