summaryrefslogtreecommitdiff
path: root/source/slang/hlsl.meta.slang
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-11-19 09:07:34 -0800
committerGitHub <noreply@github.com>2018-11-19 09:07:34 -0800
commit7e0c5ad677e04be4ecd2ce087d856ba26f1667a4 (patch)
treefd4168b307fff97e3811defe4813029b660ec697 /source/slang/hlsl.meta.slang
parent0f67d92df9ca1f528b7a7fc8a8712aaea56f7115 (diff)
Add Vulkan cross-compilation for byte-address buffers (#721)
* Add Vulkan cross-compilation for byte-address buffers This covers `ByteAddressBuffer`, `RWByteAddressBuffer`, and `RasterizerOrderedByteAddressBuffer`. A declaration of any of these types translates to a GLSL `buffer` declaration with a single `uint` array of data. Most of the methods on these types then have straightforward translations to operations on the array. The overall translation is similar to what was already being done for structured buffers. While implementing GLSL translation for the various atomic (`Interlocked*`) methods, I discovered that some of these included declarations that aren't actually included in HLSL. I cleaned these up, including in the declarations of the global `Interlocked*` functions. The test case that is included here covers only the most basic functionality: `Load`, `Load2`, `Load4` and `Store`. We should try to back-fill tests for the remaining methods when we have time. Two large caveats with this work: 1. We don't handle arrays of byte-address buffers, just as we don't handle arrays of structured buffers. That will take additional work. 2. We don't handle byte-address (or structured) buffers being passed as function parameters, since the parameter would need to be declared as a bare `uint[]` array. * Fixup: don't lump raytracing acceleration structures in with buffers Raytracing acceleration structures share a common base class with byte-address buffers (they are both buffer resources without a specific element type), and I was mistakently matching on this base class in an attempt to have a catch-all that applied to all byte-address buffers. The fix here was to add a distinct base class for all byte-address buffers and catch that instead. * Fixup: typos
Diffstat (limited to 'source/slang/hlsl.meta.slang')
-rw-r--r--source/slang/hlsl.meta.slang61
1 files changed, 44 insertions, 17 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang
index 36cefc699..57c4e1324 100644
--- a/source/slang/hlsl.meta.slang
+++ b/source/slang/hlsl.meta.slang
@@ -18,19 +18,28 @@ __magic_type(HLSLByteAddressBufferType)
__intrinsic_type($(kIROp_HLSLByteAddressBufferType))
struct ByteAddressBuffer
{
+ __target_intrinsic(glsl, "$1 = $0.length()")
void GetDimensions(
out uint dim);
+ __target_intrinsic(glsl, "$0[$1]")
uint Load(int location);
+
uint Load(int location, out uint status);
+ __target_intrinsic(glsl, "uvec2($0[$1], $0[$1+1])")
uint2 Load2(int location);
+
uint2 Load2(int location, out uint status);
+ __target_intrinsic(glsl, "uvec3($0[$1], $0[$1+1], $0[$1+2])")
uint3 Load3(int location);
+
uint3 Load3(int location, out uint status);
+ __target_intrinsic(glsl, "uvec4($0[$1], $0[$1+1], $0[$1+2], $0[$1+3])")
uint4 Load4(int location);
+
uint4 Load4(int location, out uint status);
};
@@ -93,112 +102,136 @@ __magic_type(HLSL$(item.name)Type)
__intrinsic_type($(item.op))
struct $(item.name)
{
- // Note(tfoley): supports alll operations from `ByteAddressBuffer`
+ // Note(tfoley): supports all operations from `ByteAddressBuffer`
// TODO(tfoley): can this be made a sub-type?
+ __target_intrinsic(glsl, "$1 = $0.length()")
void GetDimensions(
out uint dim);
+ __target_intrinsic(glsl, "$0[$1]")
uint Load(int location);
+
uint Load(int location, out uint status);
+ __target_intrinsic(glsl, "uvec2($0[$1], $0[$1+4])")
uint2 Load2(int location);
+
uint2 Load2(int location, out uint status);
+ __target_intrinsic(glsl, "uvec3($0[$1], $0[$1+4], $0[$1+8])")
uint3 Load3(int location);
+
uint3 Load3(int location, out uint status);
+ __target_intrinsic(glsl, "uvec4($0[$1], $0[$1+4], $0[$1+8], $0[$1+12])")
uint4 Load4(int location);
+
uint4 Load4(int location, out uint status);
// Added operations:
+ __target_intrinsic(glsl, "($3 = atomicAdd($0[$1], $2))")
void InterlockedAdd(
UINT dest,
UINT value,
out UINT original_value);
+
+ __target_intrinsic(glsl, "atomicAdd($0[$1], $2)")
void InterlockedAdd(
UINT dest,
UINT value);
+ __target_intrinsic(glsl, "($3 = atomicAnd($0[$1], $2))")
void InterlockedAnd(
UINT dest,
UINT value,
out UINT original_value);
+
+ __target_intrinsic(glsl, "atomicAnd($0[$1], $2)")
void InterlockedAnd(
UINT dest,
UINT value);
+ __target_intrinsic(glsl, "($4 = atomicCompSwap($0[$1], $2, $3))")
void InterlockedCompareExchange(
UINT dest,
UINT compare_value,
UINT value,
out UINT original_value);
- void InterlockedCompareExchange(
- UINT dest,
- UINT compare_value,
- UINT value);
+ __target_intrinsic(glsl, "atomicCompSwap($0[$1], $2, $3)")
void InterlockedCompareStore(
UINT dest,
UINT compare_value,
UINT value);
- void InterlockedCompareStore(
- UINT dest,
- UINT compare_value);
+ __target_intrinsic(glsl, "($3 = atomicExchange($0[$1], $2))")
void InterlockedExchange(
UINT dest,
UINT value,
out UINT original_value);
- void InterlockedExchange(
- UINT dest,
- UINT value);
+ __target_intrinsic(glsl, "($3 = atomicMax($0[$1], $2))")
void InterlockedMax(
UINT dest,
UINT value,
out UINT original_value);
+
+ __target_intrinsic(glsl, "atomicMax($0[$1], $2)")
void InterlockedMax(
UINT dest,
UINT value);
+ __target_intrinsic(glsl, "($3 = atomicMin($0[$1], $2))")
void InterlockedMin(
UINT dest,
UINT value,
out UINT original_value);
+
+ __target_intrinsic(glsl, "atomicMin($0[$1], $2)")
void InterlockedMin(
UINT dest,
UINT value);
+ __target_intrinsic(glsl, "($3 = atomicOr($0[$1], $2))")
void InterlockedOr(
UINT dest,
UINT value,
out UINT original_value);
+
+ __target_intrinsic(glsl, "atomicOr($0[$1], $2)")
void InterlockedOr(
UINT dest,
UINT value);
+ __target_intrinsic(glsl, "($3 = atomicXor($0[$1], $2))")
void InterlockedXor(
UINT dest,
UINT value,
out UINT original_value);
+
+ __target_intrinsic(glsl, "atomicXor($0[$1], $2)")
void InterlockedXor(
UINT dest,
UINT value);
+ __target_intrinsic(glsl, "$0[$1] = $2")
void Store(
uint address,
uint value);
+ __target_intrinsic(glsl, "$0[$1] = $2.x, $0[$1+4] = $2.y")
void Store2(
uint address,
uint2 value);
+ __target_intrinsic(glsl, "$0[$1] = $2.x, $0[$1+4] = $2.y, $0[$1+8] = $2.z")
void Store3(
uint address,
uint3 value);
+ __target_intrinsic(glsl, "$0[$1] = $2.x, $0[$1+4] = $2.y, $0[$1+8] = $2.z, $0[$1+12] = $2.w")
void Store4(
uint address,
uint4 value);
@@ -687,12 +720,6 @@ void InterlockedCompareStore(__ref int dest, int compare_value, int value);
__target_intrinsic(glsl, "$atomicCompSwap($A, $1, $2)")
void InterlockedCompareStore(__ref uint dest, uint compare_value, uint value);
-__target_intrinsic(glsl, "$atomicExchange($A, $1)")
-void InterlockedExchange(__ref int dest, int value);
-
-__target_intrinsic(glsl, "$atomicExchange($A, $1)")
-void InterlockedExchange(__ref uint dest, uint value);
-
__target_intrinsic(glsl, "($2 = $atomicExchange($A, $1))")
void InterlockedExchange(__ref int dest, int value, out int original_value);