summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-10-15 15:19:46 -0400
committerGitHub <noreply@github.com>2019-10-15 15:19:46 -0400
commitfb44993b38dd98261f20e718c3e282634902b391 (patch)
tree3483d51b1c804fc5988183f62c7e45e80d840c8e
parent2420f47b56647d33e5dbb6730718905a767c7244 (diff)
GetDimension on GLSL for StructuredBuffer (#1081)
* Fix GetDimensions for glsl. * Add test for Load on RWStructuredBuffer as part of GetDimension.
-rw-r--r--source/slang/hlsl.meta.slang5
-rw-r--r--source/slang/hlsl.meta.slang.h15
-rw-r--r--tests/cross-compile/get-dimensions.slang59
-rw-r--r--tests/cross-compile/get-dimensions.slang.expected.txt8
4 files changed, 80 insertions, 7 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang
index 9bd1c2928..a24d6c414 100644
--- a/source/slang/hlsl.meta.slang
+++ b/source/slang/hlsl.meta.slang
@@ -48,6 +48,7 @@ __magic_type(HLSLStructuredBufferType)
__intrinsic_type($(kIROp_HLSLStructuredBufferType))
struct StructuredBuffer
{
+ __target_intrinsic(glsl, "$1 = $0._data.length(); $2 = 0")
void GetDimensions(
out uint numStructs,
out uint stride);
@@ -252,7 +253,7 @@ static const struct {
char const* name;
} kMutableStructuredBufferCases[] =
{
- { kIROp_HLSLRWStructuredBufferType, "RWStructuredBuffer" },
+ { kIROp_HLSLRWStructuredBufferType, "RWStructuredBuffer" },
{ kIROp_HLSLRasterizerOrderedStructuredBufferType, "RasterizerOrderedStructuredBuffer" },
};
for(auto item : kMutableStructuredBufferCases) {
@@ -266,12 +267,14 @@ struct $(item.name)
{
uint DecrementCounter();
+ __target_intrinsic(glsl, "$1 = $0._data.length(); $2 = 0")
void GetDimensions(
out uint numStructs,
out uint stride);
uint IncrementCounter();
+ __target_intrinsic(glsl, "$0._data[$1]")
T Load(int location);
T Load(int location, out uint status);
diff --git a/source/slang/hlsl.meta.slang.h b/source/slang/hlsl.meta.slang.h
index 9989915f0..86ec0c556 100644
--- a/source/slang/hlsl.meta.slang.h
+++ b/source/slang/hlsl.meta.slang.h
@@ -57,6 +57,7 @@ SLANG_SPLICE(kIROp_HLSLStructuredBufferType
SLANG_RAW(")\n")
SLANG_RAW("struct StructuredBuffer\n")
SLANG_RAW("{\n")
+SLANG_RAW(" __target_intrinsic(glsl, \"$1 = $0._data.length(); $2 = 0\")\n")
SLANG_RAW(" void GetDimensions(\n")
SLANG_RAW(" out uint numStructs,\n")
SLANG_RAW(" out uint stride);\n")
@@ -119,7 +120,7 @@ static const struct {
{ kIROp_HLSLRasterizerOrderedByteAddressBufferType, "RasterizerOrderedByteAddressBuffer" },
};
for(auto item : kMutableByteAddressBufferCases) {
-SLANG_RAW("#line 104 \"hlsl.meta.slang\"")
+SLANG_RAW("#line 105 \"hlsl.meta.slang\"")
SLANG_RAW("\n")
SLANG_RAW("\n")
SLANG_RAW("__magic_type(HLSL")
@@ -272,7 +273,7 @@ SLANG_RAW("};\n")
SLANG_RAW("\n")
}
-SLANG_RAW("#line 247 \"hlsl.meta.slang\"")
+SLANG_RAW("#line 248 \"hlsl.meta.slang\"")
SLANG_RAW("\n")
SLANG_RAW("\n")
@@ -281,11 +282,11 @@ static const struct {
char const* name;
} kMutableStructuredBufferCases[] =
{
- { kIROp_HLSLRWStructuredBufferType, "RWStructuredBuffer" },
+ { kIROp_HLSLRWStructuredBufferType, "RWStructuredBuffer" },
{ kIROp_HLSLRasterizerOrderedStructuredBufferType, "RasterizerOrderedStructuredBuffer" },
};
for(auto item : kMutableStructuredBufferCases) {
-SLANG_RAW("#line 259 \"hlsl.meta.slang\"")
+SLANG_RAW("#line 260 \"hlsl.meta.slang\"")
SLANG_RAW("\n")
SLANG_RAW("\n")
SLANG_RAW("\n")
@@ -305,12 +306,14 @@ SLANG_RAW("\n")
SLANG_RAW("{\n")
SLANG_RAW(" uint DecrementCounter();\n")
SLANG_RAW("\n")
+SLANG_RAW(" __target_intrinsic(glsl, \"$1 = $0._data.length(); $2 = 0\")\n")
SLANG_RAW(" void GetDimensions(\n")
SLANG_RAW(" out uint numStructs,\n")
SLANG_RAW(" out uint stride);\n")
SLANG_RAW("\n")
SLANG_RAW(" uint IncrementCounter();\n")
SLANG_RAW("\n")
+SLANG_RAW(" __target_intrinsic(glsl, \"$0._data[$1]\")\n")
SLANG_RAW(" T Load(int location);\n")
SLANG_RAW(" T Load(int location, out uint status);\n")
SLANG_RAW("\n")
@@ -323,7 +326,7 @@ SLANG_RAW("};\n")
SLANG_RAW("\n")
}
-SLANG_RAW("#line 287 \"hlsl.meta.slang\"")
+SLANG_RAW("#line 290 \"hlsl.meta.slang\"")
SLANG_RAW("\n")
SLANG_RAW("\n")
SLANG_RAW("__generic<T>\n")
@@ -1568,7 +1571,7 @@ for (int aa = 0; aa < kBaseBufferAccessLevelCount; ++aa)
sb << "};\n";
}
-SLANG_RAW("#line 1495 \"hlsl.meta.slang\"")
+SLANG_RAW("#line 1498 \"hlsl.meta.slang\"")
SLANG_RAW("\n")
SLANG_RAW("\n")
SLANG_RAW("\n")
diff --git a/tests/cross-compile/get-dimensions.slang b/tests/cross-compile/get-dimensions.slang
new file mode 100644
index 000000000..eaa9b0cca
--- /dev/null
+++ b/tests/cross-compile/get-dimensions.slang
@@ -0,0 +1,59 @@
+//DISABLE_TEST:REFLECTION: -profile cs_5_0 -entry computeMain -target cpp
+//TEST(compute):COMPARE_COMPUTE_EX:-vk -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-d3d12 -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-d3d11 -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute
+
+struct Thing
+{
+ int a;
+ float b;
+};
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):dxbinding(0),glbinding(0),out,name outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+//TEST_INPUT:ubuffer(data=[7 2 9 53], stride=4):dxbinding(1),glbinding(1),name buffer0
+RWStructuredBuffer<int> buffer0;
+
+//TEST_INPUT:ubuffer(data=[23 2], stride=4):dxbinding(2),glbinding(2),name buffer1
+RWStructuredBuffer<int> buffer1;
+
+//TEST_INPUT:ubuffer(data=[-10 17 9 4 2 0], stride=4):dxbinding(3),glbinding(3),name buffer2
+RWStructuredBuffer<float> buffer2;
+
+//TEST_INPUT:ubuffer(data=[1 0 3 0 7 0], stride=8):dxbinding(4),glbinding(4),name buffer3
+RWStructuredBuffer<Thing> buffer3;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int index = int(dispatchThreadID.x);
+ int last = -1;
+
+ uint count, stride;
+ if (index == 0)
+ {
+ buffer0.GetDimensions(count, stride);
+ last = buffer0.Load(count - 1);
+ }
+ else if (index == 1)
+ {
+ buffer1.GetDimensions(count, stride);
+ last = buffer1[count - 1];
+ }
+ else if (index == 2)
+ {
+ buffer2.GetDimensions(count, stride);
+ last = int(buffer2.Load(count -1));
+ }
+ else
+ {
+ buffer3.GetDimensions(count, stride);
+
+ last = buffer3.Load(count - 1).a;
+ }
+
+ outputBuffer[index * 2] = int(count);
+ outputBuffer[index * 2 + 1] = last;
+} \ No newline at end of file
diff --git a/tests/cross-compile/get-dimensions.slang.expected.txt b/tests/cross-compile/get-dimensions.slang.expected.txt
new file mode 100644
index 000000000..b90b9551c
--- /dev/null
+++ b/tests/cross-compile/get-dimensions.slang.expected.txt
@@ -0,0 +1,8 @@
+4
+35
+2
+2
+6
+0
+3
+7