From c9ef8d58a135061262fd321a82061d27dc733cf5 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 3 May 2023 20:16:58 -0400 Subject: HLSL->Vulkan binding support (#2865) * WIP around VK shift binding. * Refactor around options parsing. * Remove needless passing around of sink. * Some more tidying around OptionsParser. * Handle vulkan shift parsing. * Fix small issue around vk binding and "all". * Fixing some small issues. Missing break. * Split out VulkanLayoutOptions * WIP binding taking into account HLSL->Vulkan options. * First attempt at making binding work with HLSLVulkanOptions. * VulkanLayoutOptions -> HLSLToVulkanLayoutOptions * WIP with HLSL-Vulkan binding. * Some more testing around vk-shift. * Improvements around global binding. More tests. * Improve test coverage. Improve checking for requirements around default space. * Update command line options. * Small fixes. * Small fix in options reporting. * Fix warning issue. * Some fixes for isDefault for HLSLToVulkanLayoutOptions. * Update hlsl-to-vulkan-shift output. The difference was due to default handling if shift isn't specified, and not being specified was not correctly tracked. --- tests/bindings/hlsl-to-vulkan-combined.hlsl | 9 ++ .../bindings/hlsl-to-vulkan-combined.hlsl.expected | 54 +++++++ tests/bindings/hlsl-to-vulkan-global.hlsl | 12 ++ tests/bindings/hlsl-to-vulkan-global.hlsl.expected | 77 +++++++++ tests/bindings/hlsl-to-vulkan-shift.hlsl | 21 +++ tests/bindings/hlsl-to-vulkan-shift.hlsl.expected | 178 +++++++++++++++++++++ 6 files changed, 351 insertions(+) create mode 100644 tests/bindings/hlsl-to-vulkan-combined.hlsl create mode 100644 tests/bindings/hlsl-to-vulkan-combined.hlsl.expected create mode 100644 tests/bindings/hlsl-to-vulkan-global.hlsl create mode 100644 tests/bindings/hlsl-to-vulkan-global.hlsl.expected create mode 100644 tests/bindings/hlsl-to-vulkan-shift.hlsl create mode 100644 tests/bindings/hlsl-to-vulkan-shift.hlsl.expected (limited to 'tests') diff --git a/tests/bindings/hlsl-to-vulkan-combined.hlsl b/tests/bindings/hlsl-to-vulkan-combined.hlsl new file mode 100644 index 000000000..20668b01b --- /dev/null +++ b/tests/bindings/hlsl-to-vulkan-combined.hlsl @@ -0,0 +1,9 @@ +//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 + +Sampler2D t0 : register(t2); +Sampler2D t1 : register(t7, space2); + +float4 main() : SV_TARGET +{ + return float4(1, 1, 1, 0); +} \ No newline at end of file diff --git a/tests/bindings/hlsl-to-vulkan-combined.hlsl.expected b/tests/bindings/hlsl-to-vulkan-combined.hlsl.expected new file mode 100644 index 000000000..127d0fe4c --- /dev/null +++ b/tests/bindings/hlsl-to-vulkan-combined.hlsl.expected @@ -0,0 +1,54 @@ +result code = 0 +standard error = { +} +standard output = { +{ + "parameters": [ + { + "name": "t0", + "binding": {"kind": "descriptorTableSlot", "index": 7}, + "type": { + "kind": "resource", + "baseShape": "texture2D" + } + }, + { + "name": "t1", + "binding": {"kind": "descriptorTableSlot", "space": 2, "index": 14}, + "type": { + "kind": "resource", + "baseShape": "texture2D" + } + } + ], + "entryPoints": [ + { + "name": "main", + "stage:": "fragment", + "result:": { + "stage": "fragment", + "binding": {"kind": "varyingOutput", "index": 0}, + "semanticName": "SV_TARGET", + "type": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } + }, + "bindings": [ + { + "name": "t0", + "binding": {"kind": "descriptorTableSlot", "index": 7} + }, + { + "name": "t1", + "binding": {"kind": "descriptorTableSlot", "space": 2, "index": 14} + } + ] + } + ] +} +} diff --git a/tests/bindings/hlsl-to-vulkan-global.hlsl b/tests/bindings/hlsl-to-vulkan-global.hlsl new file mode 100644 index 000000000..aceec02ba --- /dev/null +++ b/tests/bindings/hlsl-to-vulkan-global.hlsl @@ -0,0 +1,12 @@ +//TEST:REFLECTION:-target glsl -profile ps_4_0 -entry main -fvk-bind-globals 5 9 + +uniform int a; +uniform float b; + +Texture2D t; +SamplerState sampler; + +float4 main() : SV_TARGET +{ + return t.SampleLevel(sampler, float2(a,b), 0) + float4(a, b, 1, 0); +} \ No newline at end of file diff --git a/tests/bindings/hlsl-to-vulkan-global.hlsl.expected b/tests/bindings/hlsl-to-vulkan-global.hlsl.expected new file mode 100644 index 000000000..b0b8f6a17 --- /dev/null +++ b/tests/bindings/hlsl-to-vulkan-global.hlsl.expected @@ -0,0 +1,77 @@ +result code = 0 +standard error = { +} +standard output = { +{ + "parameters": [ + { + "name": "a", + "binding": {"kind": "uniform", "offset": 0, "size": 4}, + "type": { + "kind": "scalar", + "scalarType": "int32" + } + }, + { + "name": "b", + "binding": {"kind": "uniform", "offset": 4, "size": 4}, + "type": { + "kind": "scalar", + "scalarType": "float32" + } + }, + { + "name": "t", + "binding": {"kind": "descriptorTableSlot", "index": 0}, + "type": { + "kind": "resource", + "baseShape": "texture2D" + } + }, + { + "name": "sampler", + "binding": {"kind": "descriptorTableSlot", "index": 1}, + "type": { + "kind": "samplerState" + } + } + ], + "entryPoints": [ + { + "name": "main", + "stage:": "fragment", + "result:": { + "stage": "fragment", + "binding": {"kind": "varyingOutput", "index": 0}, + "semanticName": "SV_TARGET", + "type": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } + }, + "bindings": [ + { + "name": "a", + "binding": {"kind": "uniform", "offset": 0, "size": 4} + }, + { + "name": "b", + "binding": {"kind": "uniform", "offset": 4, "size": 4} + }, + { + "name": "t", + "binding": {"kind": "descriptorTableSlot", "index": 0} + }, + { + "name": "sampler", + "binding": {"kind": "descriptorTableSlot", "index": 1} + } + ] + } + ] +} +} diff --git a/tests/bindings/hlsl-to-vulkan-shift.hlsl b/tests/bindings/hlsl-to-vulkan-shift.hlsl new file mode 100644 index 000000000..8981b6be6 --- /dev/null +++ b/tests/bindings/hlsl-to-vulkan-shift.hlsl @@ -0,0 +1,21 @@ +//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 + +struct Data +{ + float a; + int b; +}; + +Texture2D t : register(t0); +SamplerState s : register(s4); +ConstantBuffer c : register(b2); + +Texture2D t2 : register(t0, space2); + +RWStructuredBuffer u : register(u11); +RWStructuredBuffer u2 : register(u3, space2); + +float4 main() : SV_TARGET +{ + return float4(1, 1, 1, 0); +} \ No newline at end of file diff --git a/tests/bindings/hlsl-to-vulkan-shift.hlsl.expected b/tests/bindings/hlsl-to-vulkan-shift.hlsl.expected new file mode 100644 index 000000000..b0d8ace6f --- /dev/null +++ b/tests/bindings/hlsl-to-vulkan-shift.hlsl.expected @@ -0,0 +1,178 @@ +result code = 0 +standard error = { +} +standard output = { +{ + "parameters": [ + { + "name": "t", + "binding": {"kind": "descriptorTableSlot", "index": 5}, + "type": { + "kind": "resource", + "baseShape": "texture2D" + } + }, + { + "name": "s", + "binding": {"kind": "descriptorTableSlot", "index": 1}, + "type": { + "kind": "samplerState" + } + }, + { + "name": "c", + "binding": {"kind": "descriptorTableSlot", "index": 0}, + "type": { + "kind": "constantBuffer", + "elementType": { + "kind": "struct", + "name": "Data", + "fields": [ + { + "name": "a", + "type": { + "kind": "scalar", + "scalarType": "float32" + }, + "binding": {"kind": "uniform", "offset": 0, "size": 4} + }, + { + "name": "b", + "type": { + "kind": "scalar", + "scalarType": "int32" + }, + "binding": {"kind": "uniform", "offset": 4, "size": 4} + } + ] + }, + "containerVarLayout": { + "binding": {"kind": "descriptorTableSlot", "index": 0} + }, + "elementVarLayout": { + "type": { + "kind": "struct", + "name": "Data", + "fields": [ + { + "name": "a", + "type": { + "kind": "scalar", + "scalarType": "float32" + }, + "binding": {"kind": "uniform", "offset": 0, "size": 4} + }, + { + "name": "b", + "type": { + "kind": "scalar", + "scalarType": "int32" + }, + "binding": {"kind": "uniform", "offset": 4, "size": 4} + } + ] + }, + "binding": {"kind": "uniform", "offset": 0, "size": 16} + } + } + }, + { + "name": "t2", + "binding": {"kind": "descriptorTableSlot", "space": 2, "index": 7}, + "type": { + "kind": "resource", + "baseShape": "texture2D" + } + }, + { + "name": "u", + "binding": {"kind": "descriptorTableSlot", "index": 2}, + "type": { + "kind": "resource", + "baseShape": "structuredBuffer", + "access": "readWrite", + "resultType": { + "kind": "struct", + "name": "Data", + "fields": [ + { + "name": "a", + "type": { + "kind": "scalar", + "scalarType": "float32" + }, + "binding": {"kind": "uniform", "offset": 0, "size": 4} + }, + { + "name": "b", + "type": { + "kind": "scalar", + "scalarType": "int32" + }, + "binding": {"kind": "uniform", "offset": 4, "size": 4} + } + ] + } + } + }, + { + "name": "u2", + "binding": {"kind": "descriptorTableSlot", "space": 2, "index": 4}, + "type": { + "kind": "resource", + "baseShape": "structuredBuffer", + "access": "readWrite", + "resultType": { + "kind": "scalar", + "scalarType": "int32" + } + } + } + ], + "entryPoints": [ + { + "name": "main", + "stage:": "fragment", + "result:": { + "stage": "fragment", + "binding": {"kind": "varyingOutput", "index": 0}, + "semanticName": "SV_TARGET", + "type": { + "kind": "vector", + "elementCount": 4, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } + }, + "bindings": [ + { + "name": "t", + "binding": {"kind": "descriptorTableSlot", "index": 5} + }, + { + "name": "s", + "binding": {"kind": "descriptorTableSlot", "index": 1} + }, + { + "name": "c", + "binding": {"kind": "descriptorTableSlot", "index": 0} + }, + { + "name": "t2", + "binding": {"kind": "descriptorTableSlot", "space": 2, "index": 7} + }, + { + "name": "u", + "binding": {"kind": "descriptorTableSlot", "index": 2} + }, + { + "name": "u2", + "binding": {"kind": "descriptorTableSlot", "space": 2, "index": 4} + } + ] + } + ] +} +} -- cgit v1.2.3