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-options.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'source/slang/slang-options.cpp') diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 33103442d..12b32998f 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -400,6 +400,7 @@ void initCommandOptions(CommandOptions& options) { OptionKind::GLSLForceScalarLayout, "-force-glsl-scalar-layout,-fvk-use-scalar-layout", nullptr, "Make data accessed through ConstantBuffer, ParameterBlock, StructuredBuffer, ByteAddressBuffer and general pointers follow the 'scalar' layout when targeting GLSL or SPIRV."}, + { OptionKind::ForceDXLayout, "-fvk-use-dx-layout", nullptr, "Pack members using FXCs member packing rules when targeting GLSL or SPIRV." }, { OptionKind::VulkanBindShift, vkShiftNames.getBuffer(), "-fvk--shift ", "For example '-fvk-b-shift ' shifts by N the inferred binding numbers for all resources in 'b' registers of space . " "For a resource attached with :register(bX, ) but not [vk::binding(...)], " @@ -2054,6 +2055,11 @@ SlangResult OptionsParser::_parse( getCurrentTarget()->optionSet.add(CompilerOptionName::GLSLForceScalarLayout, true); break; } + case OptionKind::ForceDXLayout: + { + getCurrentTarget()->optionSet.add(CompilerOptionName::ForceDXLayout, true); + break; + } case OptionKind::EnableEffectAnnotations: { m_compileRequest->setEnableEffectAnnotations(true); @@ -2780,6 +2786,11 @@ SlangResult OptionsParser::_parse( m_compileRequest->setTargetForceGLSLScalarBufferLayout(targetID, true); } + if (rawTarget.optionSet.shouldUseDXLayout()) + { + m_compileRequest->setTargetForceDXLayout(targetID, true); + } + if (rawTarget.optionSet.getBoolOption(CompilerOptionName::GenerateWholeProgram)) { m_compileRequest->setTargetGenerateWholeProgram(targetID, true); -- cgit v1.2.3