From d161d97681937f0546eb8835cf9e497cb1b4369c Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 3 Dec 2018 14:57:19 -0800 Subject: Add Vulkan translations for HLSL barrier operations (#737) Fixes #730 The most basic of these already had translations added, and the Slang approach to cross-compilation made adding the new ones almost trivial. I also took the time to confirm that using "operator comma" for the sequencing (since the single HLSL function call needs to expand to a sequence of GLSL function calls) works fine with glslang. I added a test case to confirm that all of these operations can compile down to SPIR-V. I am not personally confident that these translations are perfect, but they are based on what was [linked](https://anteru.net/blog/2016/mapping-between-hlsl-and-glsl/index.html) from #730. The one difference is where that blog post was listing `memoryBarrierImage, memoryBarrierImage` I assumed they meant `memoryBarrierImage, memoryBarrierBuffer`. --- source/slang/hlsl.meta.slang | 12 ++++++------ source/slang/hlsl.meta.slang.h | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'source') diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 57c4e1324..e16cc0275 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -338,9 +338,11 @@ __generic bool all(vector x); __generic bool all(matrix x); // Barrier for writes to all memory spaces (HLSL SM 5.0) +__target_intrinsic(glsl, "memoryBarrier(), groupMemoryBarrier(), memoryBarrierImage(), memoryBarrierBuffer()") void AllMemoryBarrier(); // Thread-group sync and barrier for writes to all memory spaces (HLSL SM 5.0) +__target_intrinsic(glsl, "memoryBarrier(), groupMemoryBarrier(), memoryBarrierImage(), memoryBarrierBuffer(), barrier()") void AllMemoryBarrierWithGroupSync(); // Test if any components is non-zero (HLSL SM 1.0) @@ -546,7 +548,10 @@ __generic matrix T determinant(matrix m); // Barrier for device memory +__target_intrinsic(glsl, "memoryBarrier(), memoryBarrierImage(), memoryBarrierBuffer()") void DeviceMemoryBarrier(); + +__target_intrinsic(glsl, "memoryBarrier(), memoryBarrierImage(), memoryBarrierBuffer(), barrier()") void DeviceMemoryBarrierWithGroupSync(); // Vector distance @@ -674,12 +679,7 @@ float2 GetRenderTargetSamplePosition(int Index); __target_intrinsic(glsl, "groupMemoryBarrier") void GroupMemoryBarrier(); -// Note: the unmatched parentheses in the GLSL lowering are -// to cancel out the parens that the emit logic uses, so that -// we can emit this as if it were an expression. -// -// TODO: investigate whether we can just use "operator comma" here. -__target_intrinsic(glsl, "groupMemoryBarrier()); (barrier()") +__target_intrinsic(glsl, "groupMemoryBarrier(), barrier()") void GroupMemoryBarrierWithGroupSync(); // Atomics diff --git a/source/slang/hlsl.meta.slang.h b/source/slang/hlsl.meta.slang.h index 9b8205536..7b8bbaef6 100644 --- a/source/slang/hlsl.meta.slang.h +++ b/source/slang/hlsl.meta.slang.h @@ -383,9 +383,11 @@ SLANG_RAW("__generic bool all(vector x);\n" SLANG_RAW("__generic bool all(matrix x);\n") SLANG_RAW("\n") SLANG_RAW("// Barrier for writes to all memory spaces (HLSL SM 5.0)\n") +SLANG_RAW("__target_intrinsic(glsl, \"memoryBarrier(), groupMemoryBarrier(), memoryBarrierImage(), memoryBarrierBuffer()\")\n") SLANG_RAW("void AllMemoryBarrier();\n") SLANG_RAW("\n") SLANG_RAW("// Thread-group sync and barrier for writes to all memory spaces (HLSL SM 5.0)\n") +SLANG_RAW("__target_intrinsic(glsl, \"memoryBarrier(), groupMemoryBarrier(), memoryBarrierImage(), memoryBarrierBuffer(), barrier()\")\n") SLANG_RAW("void AllMemoryBarrierWithGroupSync();\n") SLANG_RAW("\n") SLANG_RAW("// Test if any components is non-zero (HLSL SM 1.0)\n") @@ -591,7 +593,10 @@ SLANG_RAW("\n") SLANG_RAW("__generic T determinant(matrix m);\n") SLANG_RAW("\n") SLANG_RAW("// Barrier for device memory\n") +SLANG_RAW("__target_intrinsic(glsl, \"memoryBarrier(), memoryBarrierImage(), memoryBarrierBuffer()\")\n") SLANG_RAW("void DeviceMemoryBarrier();\n") +SLANG_RAW("\n") +SLANG_RAW("__target_intrinsic(glsl, \"memoryBarrier(), memoryBarrierImage(), memoryBarrierBuffer(), barrier()\")\n") SLANG_RAW("void DeviceMemoryBarrierWithGroupSync();\n") SLANG_RAW("\n") SLANG_RAW("// Vector distance\n") @@ -719,12 +724,7 @@ SLANG_RAW("// Group memory barrier\n") SLANG_RAW("__target_intrinsic(glsl, \"groupMemoryBarrier\")\n") SLANG_RAW("void GroupMemoryBarrier();\n") SLANG_RAW("\n") -SLANG_RAW("// Note: the unmatched parentheses in the GLSL lowering are\n") -SLANG_RAW("// to cancel out the parens that the emit logic uses, so that\n") -SLANG_RAW("// we can emit this as if it were an expression.\n") -SLANG_RAW("//\n") -SLANG_RAW("// TODO: investigate whether we can just use \"operator comma\" here.\n") -SLANG_RAW("__target_intrinsic(glsl, \"groupMemoryBarrier()); (barrier()\")\n") +SLANG_RAW("__target_intrinsic(glsl, \"groupMemoryBarrier(), barrier()\")\n") SLANG_RAW("void GroupMemoryBarrierWithGroupSync();\n") SLANG_RAW("\n") SLANG_RAW("// Atomics\n") -- cgit v1.2.3