diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-12-03 14:57:19 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-03 14:57:19 -0800 |
| commit | d161d97681937f0546eb8835cf9e497cb1b4369c (patch) | |
| tree | 3d02ba21b7ca3fe739232b2846401511b80e4b52 /source | |
| parent | 3d60cc0ca818556b78f38a59eb5521044b8a6b71 (diff) | |
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`.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/hlsl.meta.slang | 12 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang.h | 12 |
2 files changed, 12 insertions, 12 deletions
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<T : __BuiltinType, let N : int> bool all(vector<T,N> x); __generic<T : __BuiltinType, let N : int, let M : int> bool all(matrix<T,N,M> 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<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M __generic<T : __BuiltinFloatingPointType, let N : int> T determinant(matrix<T,N,N> 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<T : __BuiltinType, let N : int> bool all(vector<T,N> x);\n" SLANG_RAW("__generic<T : __BuiltinType, let N : int, let M : int> bool all(matrix<T,N,M> 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 : __BuiltinFloatingPointType, let N : int> T determinant(matrix<T,N,N> 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") |
