diff options
| -rw-r--r-- | docs/command-line-slangc-reference.md | 18 | ||||
| -rw-r--r-- | source/slang/slang-hlsl-to-vulkan-layout-options.cpp | 18 | ||||
| -rw-r--r-- | source/slang/slang-hlsl-to-vulkan-layout-options.h | 29 | ||||
| -rw-r--r-- | source/slang/slang-options.cpp | 9 | ||||
| -rw-r--r-- | source/slang/slang-parameter-binding.cpp | 6 | ||||
| -rw-r--r-- | tests/bindings/hlsl-to-vulkan-shift.hlsl | 2 | ||||
| -rw-r--r-- | tests/bindings/hlsl-to-vulkan-shift.hlsl.expected | 8 | ||||
| -rw-r--r-- | tests/diagnostics/hlsl-to-vulkan-shift-diagnostic.hlsl | 2 |
8 files changed, 62 insertions, 30 deletions
diff --git a/docs/command-line-slangc-reference.md b/docs/command-line-slangc-reference.md index 3fcd7a68c..a1387df5f 100644 --- a/docs/command-line-slangc-reference.md +++ b/docs/command-line-slangc-reference.md @@ -355,9 +355,15 @@ Force using scalar block layout for uniform and shader storage buffers in GLSL o <a id="fvk-b-shift"></a> ## -fvk-b-shift, -fvk-s-shift, -fvk-t-shift, -fvk-u-shift -**-vk-<[vulkan-shift](#vulkan-shift)>-shift <N> <space>** +**-fvk-<[vulkan-shift](#vulkan-shift)>-shift <N> <space>** + +For example '-fvk-b-shift <N> <space>' shifts by N the inferred binding numbers for all resources in 'b' registers of space <space>. For a resource attached with :register(bX, <space>) but not \[vk::binding(...)\], sets its Vulkan descriptor set to <space> and binding number to X + N. If you need to shift the inferred binding numbers for more than one space, provide more than one such option. If more than one such option is provided for the same space, the last one takes effect. If you need to shift the inferred binding numbers for all sets, use 'all' as <space>. + +* \[DXC description\](https://github.com/Microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst#implicit-binding-number-assignment) + +* \[GLSL wiki\](https://github.com/KhronosGroup/glslang/wiki/HLSL-FAQ#auto-mapped-binding-numbers) + -For example '-vk-b-shift <N> <space>' shifts by N the inferred binding numbers for all resources in 'b' registers of space <space>. For a resource attached with :register(bX, <space>) but not \[vk::binding(...)\], sets its Vulkan descriptor set to <space> and binding number to X + N. If you need to shift the inferred binding numbers for more than one space, provide more than one such option. If more than one such option is provided for the same space, the last one takes effect. If you need to shift the inferred binding numbers for all sets, use 'all' as <space>. <a id="fvk-bind-globals"></a> @@ -824,10 +830,10 @@ Stage Vulkan Shift -* `b` : Vulkan Buffer resource -* `s` : Vulkan Sampler resource -* `t` : Vulkan Texture resource -* `u` : Vulkan Uniform resource +* `b` : Constant buffer view +* `s` : Sampler +* `t` : Shader resource view +* `u` : Unorderd access view <a id="capability"></a> # capability diff --git a/source/slang/slang-hlsl-to-vulkan-layout-options.cpp b/source/slang/slang-hlsl-to-vulkan-layout-options.cpp index bb02a079c..1033c0f56 100644 --- a/source/slang/slang-hlsl-to-vulkan-layout-options.cpp +++ b/source/slang/slang-hlsl-to-vulkan-layout-options.cpp @@ -8,14 +8,16 @@ namespace { // anonymous typedef HLSLToVulkanLayoutOptions::Kind ShiftKind; -/* {b|s|t|u} */ +/* {b|s|t|u} +https://github.com/KhronosGroup/glslang/wiki/HLSL-FAQ +*/ static NamesDescriptionValue s_vulkanShiftKinds[] = { - { ValueInt(ShiftKind::Buffer), "b", "Vulkan Buffer resource" }, - { ValueInt(ShiftKind::Sampler), "s", "Vulkan Sampler resource" }, - { ValueInt(ShiftKind::Texture), "t", "Vulkan Texture resource" }, - { ValueInt(ShiftKind::Uniform), "u", "Vulkan Uniform resource" }, + { ValueInt(ShiftKind::ConstantBuffer), "b", "Constant buffer view" }, + { ValueInt(ShiftKind::Sampler), "s", "Sampler" }, + { ValueInt(ShiftKind::ShaderResource), "t", "Shader resource view" }, + { ValueInt(ShiftKind::UnorderedAccess), "u", "Unorderd access view" }, }; } // anonymous @@ -136,10 +138,10 @@ HLSLToVulkanLayoutOptions::Binding HLSLToVulkanLayoutOptions::inferBinding(Kind case ParameterCategory::Uniform: case ParameterCategory::ConstantBuffer: { - return Kind::Uniform; + return Kind::ConstantBuffer; } - case ParameterCategory::ShaderResource: return Kind::Texture; - case ParameterCategory::UnorderedAccess: return Kind::Buffer; + case ParameterCategory::ShaderResource: return Kind::ShaderResource; + case ParameterCategory::UnorderedAccess: return Kind::UnorderedAccess; case ParameterCategory::SamplerState: return Kind::Sampler; default: diff --git a/source/slang/slang-hlsl-to-vulkan-layout-options.h b/source/slang/slang-hlsl-to-vulkan-layout-options.h index 642f6b5f4..b9eb3046d 100644 --- a/source/slang/slang-hlsl-to-vulkan-layout-options.h +++ b/source/slang/slang-hlsl-to-vulkan-layout-options.h @@ -32,15 +32,36 @@ public: Index index = -1; }; + // https://github.com/KhronosGroup/glslang/wiki/HLSL-FAQ // {b|s|t|u} enum class Kind { Invalid = -1, - Buffer, ///< Buffer - Sampler, ///< Sampler - Texture, ///< Texture - Uniform, ///< Uniform + /// Unordered access view (u) + /// + /// RWByteAddressBuffer/RWStructuredBuffer + /// Append/ConsumeStructuredBuffer + /// RWBuffer + /// RWTextureXD/Array + UnorderedAccess, + + /// Sampler (s) + /// + /// SamplerXD + /// SamplerState/SamplerComparisonState + Sampler, + + /// Shader Resource (t) + /// + /// TextureXD/Array + /// ByteAddressBuffer/StructuredBuffer/Buffer/TBuffer + ShaderResource, + + /// Constant buffer (b) + /// + /// ConstantBufferViews, CBuffer + ConstantBuffer, CountOf, }; diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 552d5bc47..dd4473497 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -484,13 +484,16 @@ void initCommandOptions(CommandOptions& options) { OptionKind::GLSLForceScalarLayout, "-force-glsl-scalar-layout", nullptr, "Force using scalar block layout for uniform and shader storage buffers in GLSL output."}, - { OptionKind::VulkanBindShift, vkShiftNames.getBuffer(), "-vk-<vulkan-shift>-shift <N> <space>", - "For example '-vk-b-shift <N> <space>' shifts by N the inferred binding numbers for all resources in 'b' registers of space <space>. " + { OptionKind::VulkanBindShift, vkShiftNames.getBuffer(), "-fvk-<vulkan-shift>-shift <N> <space>", + "For example '-fvk-b-shift <N> <space>' shifts by N the inferred binding numbers for all resources in 'b' registers of space <space>. " "For a resource attached with :register(bX, <space>) but not [vk::binding(...)], " "sets its Vulkan descriptor set to <space> and binding number to X + N. If you need to shift the " "inferred binding numbers for more than one space, provide more than one such option. " "If more than one such option is provided for the same space, the last one takes effect. " - "If you need to shift the inferred binding numbers for all sets, use 'all' as <space>." }, + "If you need to shift the inferred binding numbers for all sets, use 'all' as <space>. " + "\n" + "* [DXC description](https://github.com/Microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst#implicit-binding-number-assignment)\n" + "* [GLSL wiki](https://github.com/KhronosGroup/glslang/wiki/HLSL-FAQ#auto-mapped-binding-numbers)\n" }, { OptionKind::VulkanBindGlobals, "-fvk-bind-globals", "-fvk-bind-globals <N> <descriptor-set>", "Places the $Globals cbuffer at descriptor set <descriptor-set> and binding <N>."}, { OptionKind::EnableEffectAnnotations, diff --git a/source/slang/slang-parameter-binding.cpp b/source/slang/slang-parameter-binding.cpp index e22bc0597..1d38bc2f0 100644 --- a/source/slang/slang-parameter-binding.cpp +++ b/source/slang/slang-parameter-binding.cpp @@ -575,7 +575,7 @@ LayoutSemanticInfo extractHLSLLayoutSemanticInfo( return info; } -LayoutSemanticInfo ExtractLayoutSemanticInfo( +static LayoutSemanticInfo _extractLayoutSemanticInfo( ParameterBindingContext* context, HLSLLayoutSemantic* semantic) { @@ -938,7 +938,7 @@ static void addExplicitParameterBindings_HLSL( for (auto semantic : varDecl.getDecl()->getModifiersOfType<HLSLLayoutSemantic>()) { // Need to extract the information encoded in the semantic - LayoutSemanticInfo semanticInfo = ExtractLayoutSemanticInfo(context, semantic); + LayoutSemanticInfo semanticInfo = _extractLayoutSemanticInfo(context, semantic); auto kind = semanticInfo.kind; if (kind == LayoutResourceKind::None) continue; @@ -1076,7 +1076,7 @@ static void addExplicitParameterBindings_GLSL( } // Get the HLSL binding info - const auto hlslInfo = ExtractLayoutSemanticInfo(context, hlslRegSemantic); + const auto hlslInfo = _extractLayoutSemanticInfo(context, hlslRegSemantic); if (hlslInfo.kind == LayoutResourceKind::None) { // Is no hlsl resource binding diff --git a/tests/bindings/hlsl-to-vulkan-shift.hlsl b/tests/bindings/hlsl-to-vulkan-shift.hlsl index 8981b6be6..13f76297d 100644 --- a/tests/bindings/hlsl-to-vulkan-shift.hlsl +++ b/tests/bindings/hlsl-to-vulkan-shift.hlsl @@ -1,4 +1,4 @@ -//TEST:REFLECTION:-target glsl -profile ps_4_0 -entry main -fvk-t-shift 5 all -fvk-t-shift 7 2 -fvk-s-shift -3 0 -fvk-b-shift 1 2 +//TEST:REFLECTION:-target glsl -profile ps_4_0 -entry main -fvk-t-shift 5 all -fvk-t-shift 7 2 -fvk-s-shift -3 0 -fvk-u-shift 0 all -fvk-u-shift 1 2 -fvk-b-shift 1 0 struct Data { diff --git a/tests/bindings/hlsl-to-vulkan-shift.hlsl.expected b/tests/bindings/hlsl-to-vulkan-shift.hlsl.expected index b0d8ace6f..939f847ca 100644 --- a/tests/bindings/hlsl-to-vulkan-shift.hlsl.expected +++ b/tests/bindings/hlsl-to-vulkan-shift.hlsl.expected @@ -21,7 +21,7 @@ standard output = { }, { "name": "c", - "binding": {"kind": "descriptorTableSlot", "index": 0}, + "binding": {"kind": "descriptorTableSlot", "index": 3}, "type": { "kind": "constantBuffer", "elementType": { @@ -86,7 +86,7 @@ standard output = { }, { "name": "u", - "binding": {"kind": "descriptorTableSlot", "index": 2}, + "binding": {"kind": "descriptorTableSlot", "index": 11}, "type": { "kind": "resource", "baseShape": "structuredBuffer", @@ -157,7 +157,7 @@ standard output = { }, { "name": "c", - "binding": {"kind": "descriptorTableSlot", "index": 0} + "binding": {"kind": "descriptorTableSlot", "index": 3} }, { "name": "t2", @@ -165,7 +165,7 @@ standard output = { }, { "name": "u", - "binding": {"kind": "descriptorTableSlot", "index": 2} + "binding": {"kind": "descriptorTableSlot", "index": 11} }, { "name": "u2", diff --git a/tests/diagnostics/hlsl-to-vulkan-shift-diagnostic.hlsl b/tests/diagnostics/hlsl-to-vulkan-shift-diagnostic.hlsl index f69a0c3d5..4c98b4e93 100644 --- a/tests/diagnostics/hlsl-to-vulkan-shift-diagnostic.hlsl +++ b/tests/diagnostics/hlsl-to-vulkan-shift-diagnostic.hlsl @@ -1,4 +1,4 @@ -//DIAGNOSTIC_TEST:SIMPLE:-target glsl -profile ps_4_0 -entry main -fvk-t-shift 5 all -fvk-t-shift 7 2 -fvk-s-shift -3 0 -fvk-b-shift 1 2 -no-codegen +//DIAGNOSTIC_TEST:SIMPLE:-target glsl -profile ps_4_0 -entry main -fvk-t-shift 5 all -fvk-t-shift 7 2 -fvk-s-shift -3 0 -fvk-u-shift 1 2 -no-codegen struct Data { |
