summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2024-04-03 14:19:15 -0400
committerGitHub <noreply@github.com>2024-04-03 11:19:15 -0700
commite0de98e9aabbe118f0eeca7821518c8fb4e1f6c4 (patch)
treea310629cd025372c6d554705ba7f42251f400ac5 /tests
parenta697b2c6707ee699cb734a03fa529dd214ac66cc (diff)
Refactor memory qualifier decorators to be a bit-flag set, resolves #3841 (#3881)
* Refactor memory qualifier decorators to be a bit-flag set. replace GloballyCoherent, ReadOnly, WriteOnly, Volatile, and Restrict memory modifiers and decorations with a bit flag set to more efficiently manage memory qualifiers. added `restrict` modifier to test to ensure the code works when dropping a `restrict` memory qualifier * Refine tests & add SSBO memory qualifer support add CHECK's to tests to ensure memory qualifiers emit as intended added tests and changed code to ensure memory qualifiers work on SSBO objects (SPIR-V & GLSL) * add memory qualifiers & fixes. Add to StructuredBuffer & ByteAddressBuffer `ReadOnly`/NonWritable qualifier. * Memory qualifiers must be decorated on a variable inst. Due to this the qualifier is added after `lowerStructuredBufferType` Fixed an error where ReadOnly->NonReadable & WriteOnly->NonWritable * Adjusted tests accordingly Added back the removed `globallycoherent` memory qualifier emit'ing code in hlsl-emit (was incorrectly removed). undo hlsl.meta changes cleanup
Diffstat (limited to 'tests')
-rw-r--r--tests/glsl-intrinsic/image/imageAsParamWithMemoryQualifiers.slang14
-rw-r--r--tests/glsl/ssboMemberMemoryQualifier.slang63
-rw-r--r--tests/glsl/ssboMemoryQualifier.slang33
-rw-r--r--tests/glsl/ssboStructInsideStructMemoryQualifierError.slang8
-rw-r--r--tests/hlsl-intrinsic/structured-buffer-spirv-memory-qualifier.slang12
5 files changed, 107 insertions, 23 deletions
diff --git a/tests/glsl-intrinsic/image/imageAsParamWithMemoryQualifiers.slang b/tests/glsl-intrinsic/image/imageAsParamWithMemoryQualifiers.slang
index 4766cb66f..e1d521e61 100644
--- a/tests/glsl-intrinsic/image/imageAsParamWithMemoryQualifiers.slang
+++ b/tests/glsl-intrinsic/image/imageAsParamWithMemoryQualifiers.slang
@@ -11,9 +11,20 @@ buffer MyBlockName2
layout(local_size_x = 4) in;
+// The memory qualifier `restrict` is allowed to be dropped
+// when passing a variable into a function as an argument.
+
+//CHECK_SPV: OpEntryPoint
+
+//CHECK_GLSL: {{(restrict|writeonly|readonly)}} {{(restrict|writeonly|readonly)}} {{(restrict|writeonly|readonly)}}
+//CHECK_SPV: OpDecorate %{{.*}} {{(Restrict|NonWritable|NonReadable)}}
+//CHECK_SPV: OpDecorate %{{.*}} {{(Restrict|NonWritable|NonReadable)}}
+//CHECK_SPV: OpDecorate %{{.*}} {{(Restrict|NonWritable|NonReadable)}}
//TEST_INPUT: set someImage = RWTexture2D(format=R16G16B16A16_FLOAT, size=1, content=one, mipMaps = 1)
-uniform layout(binding=0,rgba16f) writeonly readonly image2D someImage;
+uniform layout(binding=0,rgba16f) restrict writeonly readonly image2D someImage;
+//CHECK_GLSL: writeonly
+//CHECK_SPV: OpDecorate {{.*}} {{(Restrict|NonWritable|NonReadable)}}
//TEST_INPUT: set someImage2 = RWTexture2D(format=R16G16B16A16_FLOAT, size=1, content=one, mipMaps = 1)
uniform layout(binding=1,rgba16f) writeonly image2D someImage2;
@@ -31,7 +42,6 @@ bool checkAllImageSizesParamMoreQualifiers(readonly writeonly image2D val)
}
// CHECK_GLSL: void main(
-// CHECK_SPV: OpEntryPoint
void computeMain()
{
outputBuffer.data[0] = true
diff --git a/tests/glsl/ssboMemberMemoryQualifier.slang b/tests/glsl/ssboMemberMemoryQualifier.slang
index 78d029039..903526ff8 100644
--- a/tests/glsl/ssboMemberMemoryQualifier.slang
+++ b/tests/glsl/ssboMemberMemoryQualifier.slang
@@ -1,11 +1,27 @@
-//TEST:SIMPLE(filecheck=CHECK-GLSL): -stage compute -entry computeMain -allow-glsl -target glsl
-//TEST:SIMPLE(filecheck=CHECK-SPV): -stage compute -entry computeMain -allow-glsl -target spirv -emit-spirv-directly
+//TEST:SIMPLE(filecheck=CHECK_GLSL): -stage compute -entry computeMain -allow-glsl -target glsl
+//TEST:SIMPLE(filecheck=CHECK_SPV): -stage compute -entry computeMain -allow-glsl -target spirv -emit-spirv-directly
// due to implementation limitations (slang-check-expr.cpp, `void visitMemberExpr()`) we are unable to
// implement and use .length with glsl vectors to test `readonly writeonly`
//#define TEST_whenVectorLengthIsImplemented
-volatile buffer Block1
+// CHECK_SPV: OpEntryPoint
+
+//CHECK_GLSL: restrict
+//CHECK_GLSL: readonly
+//CHECK_GLSL: {{(writeonly|readonly)}} {{(writeonly|readonly)}}
+//CHECK_GLSL: writeonly
+//CHECK_GLSL: coherent
+//CHECK_GLSL: volatile
+//CHECK_SPV: OpMemberDecorate %{{.*}} 0 Restrict
+//CHECK_SPV: OpMemberDecorate %{{.*}} 1 NonWritable
+//CHECK_SPV: OpMemberDecorate %{{.*}} 2 {{(NonWritable|NonReadable)}}
+//CHECK_SPV: OpMemberDecorate %{{.*}} 2 {{(NonWritable|NonReadable)}}
+//CHECK_SPV: OpMemberDecorate %{{.*}} 3 NonReadable
+//CHECK_SPV: OpMemberDecorate %{{.*}} 4 Coherent
+//CHECK_SPV: OpMemberDecorate %{{.*}} 5 Volatile
+//CHECK_SPV: OpDecorate %{{.*}} {{(Restrict|Volatile)}}
+restrict volatile buffer Block1
{
restrict uint data1;
readonly uint data2;
@@ -15,40 +31,65 @@ volatile buffer Block1
volatile uint data6;
} inputBuffer1;
+//CHECK_GLSL: coherent
+//CHECK_GLSL: readonly
+//CHECK_SPV: OpMemberDecorate %{{.*}} 0 NonWritable
+//CHECK_SPV: OpDecorate %{{.*}} Coherent
coherent buffer Block2 {
readonly vec4 member1;
vec4 member2;
}inputBuffer2;
+//CHECK_GLSL: {{(coherent|readonly)}} {{(coherent|readonly)}}
+//CHECK_GLSL: coherent
+//CHECK_SPV: OpMemberDecorate %{{.*}} 0 {{(Coherent|NonWritable)}}
+//CHECK_SPV: OpMemberDecorate %{{.*}} 0 {{(Coherent|NonWritable)}}
+//CHECK_SPV: OpMemberDecorate %{{.*}} 1 Coherent
+//CHECK_SPV: OpDecorate %{{.*}}
buffer Block3 {
coherent readonly vec4 member1;
coherent vec4 member2;
}inputBuffer3;
+//CHECK_GLSL: {{(coherent|readonly)}} {{(coherent|readonly)}}
+//CHECK_GLSL: coherent
+//CHECK_GLSL: {{(volatile|writeonly)}} {{(volatile|writeonly)}}
+//CHECK_GLSL: readonly
+//CHECK_SPV: OpMemberDecorate %{{.*}} 0 {{(Coherent|NonWritable)}}
+//CHECK_SPV: OpMemberDecorate %{{.*}} 0 {{(Coherent|NonWritable)}}
+//CHECK_SPV: OpMemberDecorate %{{.*}} 1 Coherent
+//CHECK_SPV: OpMemberDecorate %{{.*}} 2 {{(NonReadable|Volatile)}}
+//CHECK_SPV: OpMemberDecorate %{{.*}} 2 {{(NonReadable|Volatile)}}
+//CHECK_SPV: OpMemberDecorate %{{.*}} 3 NonWritable
buffer Block4 {
struct structTmp
{
int val;
};
- readonly structTmp myStruct;
- coherent readonly vec4 member1;
- coherent vec4 member2;
- readonly writeonly vec3 member3;
+ coherent readonly int member1;
+ coherent int member2;
+ volatile writeonly int member3;
+ readonly structTmp member4;
}inputBuffer4;
-// CHECK-GLSL: main
-// CHECK-SPV: OpEntryPoint
+// CHECK_GLSL: main
layout(local_size_x = 1) in;
void computeMain()
{
int v = inputBuffer1.data1;
- v = inputBuffer1.data2;
+ v += inputBuffer1.data2;
inputBuffer1.data4 = 1;
inputBuffer1.data5 = 1;
inputBuffer1.data6 = 1;
inputBuffer2.member2 = inputBuffer2.member1;
inputBuffer3.member2 = inputBuffer3.member1;
+ v += inputBuffer4.member1;
+ v += inputBuffer4.member2;
+ inputBuffer4.member3 = v;
+ v += inputBuffer4.member4.val;
#ifdef TEST_whenVectorLengthIsImplemented
- v = inputBuffer4.member3.length();
+ v += inputBuffer4.member3.length();
#endif
+ // ensure code is not optimized out
+ inputBuffer1.data4 = v;
} \ No newline at end of file
diff --git a/tests/glsl/ssboMemoryQualifier.slang b/tests/glsl/ssboMemoryQualifier.slang
index 67da12e9e..c3367f315 100644
--- a/tests/glsl/ssboMemoryQualifier.slang
+++ b/tests/glsl/ssboMemoryQualifier.slang
@@ -1,39 +1,60 @@
-//TEST:SIMPLE(filecheck=CHECK-GLSL): -stage compute -entry computeMain -allow-glsl -target glsl
-//TEST:SIMPLE(filecheck=CHECK-SPV): -stage compute -entry computeMain -allow-glsl -target spirv -emit-spirv-directly
+//TEST:SIMPLE(filecheck=CHECK_GLSL): -stage compute -entry computeMain -allow-glsl -target glsl
+//TEST:SIMPLE(filecheck=CHECK_SPV): -stage compute -entry computeMain -allow-glsl -target spirv -emit-spirv-directly
+// CHECK_SPV: OpEntryPoint
+
+//CHECK_GLSL: volatile
+//CHECK_SPV: OpDecorate %{{.*}} Volatile
volatile buffer MyBlockName1
{
uint data1;
} inputBuffer1;
+
+//CHECK_GLSL: restrict
+//CHECK_SPV: OpDecorate %{{.*}} Restrict
restrict buffer MyBlockName2
{
uint data1;
} inputBuffer2;
-readonly writeonly buffer MyBlockName3
+
+//CHECK_GLSL: {{(writeonly|volatile)}} {{(writeonly|volatile)}}
+//CHECK_SPV: OpDecorate %{{.*}} {{(NonReadable|Volatile)}}
+//CHECK_SPV: OpDecorate %{{.*}} {{(NonReadable|Volatile)}}
+writeonly volatile buffer MyBlockName3
{
uint data1;
} inputBuffer3;
+
+//CHECK_GLSL: writeonly
+//CHECK_SPV: OpDecorate %{{.*}} NonReadable
writeonly buffer MyBlockName4
{
uint data1;
} inputBuffer4;
+
+//CHECK_GLSL: readonly
+//CHECK_SPV: OpDecorate %{{.*}} NonWritable
readonly buffer MyBlockName5
{
uint data1;
} inputBuffer5;
+
+//CHECK_GLSL: coherent
+//CHECK_SPV: OpDecorate %{{.*}} Coherent
coherent buffer MyBlockName6
{
uint data1;
} inputBuffer6;
-// CHECK-GLSL: main
-// CHECK-SPV: OpEntryPoint
+// CHECK_GLSL: main
layout(local_size_x = 1) in;
void computeMain()
{
inputBuffer1.data1 = 1;
inputBuffer2.data1 = 1;
+ inputBuffer3.data1 = 1;
inputBuffer4.data1 = 1;
int v = inputBuffer5.data1;
- inputBuffer6.data1 = 1;
+ // ensure code is not optimized out
+ inputBuffer6.data1 = v;
} \ No newline at end of file
diff --git a/tests/glsl/ssboStructInsideStructMemoryQualifierError.slang b/tests/glsl/ssboStructInsideStructMemoryQualifierError.slang
index c5376b4a8..82ae9d725 100644
--- a/tests/glsl/ssboStructInsideStructMemoryQualifierError.slang
+++ b/tests/glsl/ssboStructInsideStructMemoryQualifierError.slang
@@ -1,12 +1,12 @@
-//TEST:SIMPLE(filecheck=CHECK-GLSL): -stage compute -entry computeMain -allow-glsl -target glsl
-//TEST:SIMPLE(filecheck=CHECK-SPV): -stage compute -entry computeMain -allow-glsl -target spirv -emit-spirv-directly
+//TEST:SIMPLE(filecheck=CHECK_GLSL): -stage compute -entry computeMain -allow-glsl -target glsl
+//TEST:SIMPLE(filecheck=CHECK_SPV): -stage compute -entry computeMain -allow-glsl -target spirv -emit-spirv-directly
// This code should error since memory qualifiers are only allowed inside:
// Shader storage blocks, variables declared within shader storage blocks
// and variables declared as image types. Named structs inside a Interface
// block violates these rules
-// CHECK-GLSL: error
-// CHECK-SPV: error
+// CHECK_GLSL: error
+// CHECK_SPV: error
buffer Block4 {
struct StructTmp
{
diff --git a/tests/hlsl-intrinsic/structured-buffer-spirv-memory-qualifier.slang b/tests/hlsl-intrinsic/structured-buffer-spirv-memory-qualifier.slang
new file mode 100644
index 000000000..3419c05e7
--- /dev/null
+++ b/tests/hlsl-intrinsic/structured-buffer-spirv-memory-qualifier.slang
@@ -0,0 +1,12 @@
+//TEST:SIMPLE(filecheck=CHECK_SPV):-stage fragment -entry main -target spirv -emit-spirv-directly
+
+// CHECK_SPV: OpDecorate %x NonWritable
+StructuredBuffer<uint> x;
+
+// CHECK_SPV: OpDecorate %y NonWritable
+ByteAddressBuffer y;
+
+float4 main() : SV_Target
+{
+ return x[0] + y.Load<uint>(0);
+} \ No newline at end of file