summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2023-09-12 17:44:34 +0800
committerGitHub <noreply@github.com>2023-09-12 17:44:34 +0800
commit3f4081d854db2d186adea4067da575eca7c7adf1 (patch)
tree67defa47d2640478cfeac952bf42214d37ec3e34
parent09854a4596019ddb3bb315b8836b5c88e718cdc7 (diff)
Correctly identify the number of operands to image sampling operands in SPIR-V (#3200)
* Correctly identify the number of operands to image sampling operands in SPIR-V * Neaten imageoperands warning test * Neaten imageoperands warning test
-rw-r--r--source/compiler-core/slang-spirv-core-grammar.cpp24
-rw-r--r--source/slang/slang-spirv-core-grammar-embed.cpp52
-rw-r--r--tests/expected-failure-github.txt3
-rw-r--r--tests/language-feature/spirv-asm/imageoperands-warning.slang45
4 files changed, 90 insertions, 34 deletions
diff --git a/source/compiler-core/slang-spirv-core-grammar.cpp b/source/compiler-core/slang-spirv-core-grammar.cpp
index 8140d002a..9a4a7e17f 100644
--- a/source/compiler-core/slang-spirv-core-grammar.cpp
+++ b/source/compiler-core/slang-spirv-core-grammar.cpp
@@ -265,7 +265,17 @@ RefPtr<SPIRVCoreGrammarInfo> SPIRVCoreGrammarInfo::loadFromJSON(SourceView& sour
numOperandTypes++;
res->operandTypesStorage.add(*catIndex);
- if(o.quantifier == "")
+ // The number of "ImageOperands" is dependent on the bitmask
+ // operand, for our purposes treat them as unbounded
+ if(o.quantifier == "*" || o.kind == "ImageOperands")
+ {
+ maxOperandCount = 0xffff;
+ }
+ else if(o.quantifier == "?")
+ {
+ maxOperandCount++;
+ }
+ else if(o.quantifier == "")
{
// This catches the case where an "?" or "*" qualified operand
// appears before any unqualified operands
@@ -278,13 +288,13 @@ RefPtr<SPIRVCoreGrammarInfo> SPIRVCoreGrammarInfo::loadFromJSON(SourceView& sour
minOperandCount++;
maxOperandCount++;
}
- else if(o.quantifier == "?")
- {
- maxOperandCount++;
- }
- else if(o.quantifier == "*")
+ else
{
- maxOperandCount = 0xffff;
+ sink.diagnose(
+ SourceLoc{},
+ MiscDiagnostics::spirvCoreGrammarJSONParseFailure,
+ "quantifier wasn't empty, * or ?"
+ );
}
}
diff --git a/source/slang/slang-spirv-core-grammar-embed.cpp b/source/slang/slang-spirv-core-grammar-embed.cpp
index cd5c6ddb7..57ad90108 100644
--- a/source/slang/slang-spirv-core-grammar-embed.cpp
+++ b/source/slang/slang-spirv-core-grammar-embed.cpp
@@ -2601,79 +2601,79 @@ static bool getOpInfo(const SpvOp& k, SPIRVCoreGrammarInfo::OpInfo& v)
case SpvOpImageSampleImplicitLod:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 5, 5, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 0xffff, 5, operandTypes};
return true;
}
case SpvOpImageSampleExplicitLod:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 5, 5, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 0xffff, 5, operandTypes};
return true;
}
case SpvOpImageSampleDrefImplicitLod:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 6, 6, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 0xffff, 6, operandTypes};
return true;
}
case SpvOpImageSampleDrefExplicitLod:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 6, 6, 6, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 0xffff, 6, operandTypes};
return true;
}
case SpvOpImageSampleProjImplicitLod:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 5, 5, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 0xffff, 5, operandTypes};
return true;
}
case SpvOpImageSampleProjExplicitLod:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 5, 5, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 0xffff, 5, operandTypes};
return true;
}
case SpvOpImageSampleProjDrefImplicitLod:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 6, 6, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 0xffff, 6, operandTypes};
return true;
}
case SpvOpImageSampleProjDrefExplicitLod:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 6, 6, 6, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 0xffff, 6, operandTypes};
return true;
}
case SpvOpImageFetch:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 5, 5, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 0xffff, 5, operandTypes};
return true;
}
case SpvOpImageGather:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 6, 6, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 0xffff, 6, operandTypes};
return true;
}
case SpvOpImageDrefGather:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 6, 6, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 0xffff, 6, operandTypes};
return true;
}
case SpvOpImageRead:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 5, 5, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 0xffff, 5, operandTypes};
return true;
}
case SpvOpImageWrite:
{
const static OperandKind operandTypes[] = {{47}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, -1, -1, 3, 4, 4, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, -1, -1, 3, 0xffff, 4, operandTypes};
return true;
}
case SpvOpImage:
@@ -3796,67 +3796,67 @@ static bool getOpInfo(const SpvOp& k, SPIRVCoreGrammarInfo::OpInfo& v)
case SpvOpImageSparseSampleImplicitLod:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 5, 5, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 0xffff, 5, operandTypes};
return true;
}
case SpvOpImageSparseSampleExplicitLod:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 5, 5, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 0xffff, 5, operandTypes};
return true;
}
case SpvOpImageSparseSampleDrefImplicitLod:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 6, 6, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 0xffff, 6, operandTypes};
return true;
}
case SpvOpImageSparseSampleDrefExplicitLod:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 6, 6, 6, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 0xffff, 6, operandTypes};
return true;
}
case SpvOpImageSparseSampleProjImplicitLod:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 5, 5, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 0xffff, 5, operandTypes};
return true;
}
case SpvOpImageSparseSampleProjExplicitLod:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 5, 5, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 0xffff, 5, operandTypes};
return true;
}
case SpvOpImageSparseSampleProjDrefImplicitLod:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 6, 6, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 0xffff, 6, operandTypes};
return true;
}
case SpvOpImageSparseSampleProjDrefExplicitLod:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 6, 6, 6, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 0xffff, 6, operandTypes};
return true;
}
case SpvOpImageSparseFetch:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 5, 5, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 0xffff, 5, operandTypes};
return true;
}
case SpvOpImageSparseGather:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 6, 6, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 0xffff, 6, operandTypes};
return true;
}
case SpvOpImageSparseDrefGather:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 6, 6, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 5, 0xffff, 6, operandTypes};
return true;
}
case SpvOpImageSparseTexelsResident:
@@ -3885,7 +3885,7 @@ static bool getOpInfo(const SpvOp& k, SPIRVCoreGrammarInfo::OpInfo& v)
case SpvOpImageSparseRead:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 5, 5, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 4, 0xffff, 5, operandTypes};
return true;
}
case SpvOpSizeOf:
@@ -4680,7 +4680,7 @@ static bool getOpInfo(const SpvOp& k, SPIRVCoreGrammarInfo::OpInfo& v)
case SpvOpImageSampleFootprintNV:
{
const static OperandKind operandTypes[] = {{43}, {44}, {47}, {47}, {47}, {47}, {0}};
- v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 6, 7, 7, operandTypes};
+ v = {SPIRVCoreGrammarInfo::OpInfo::Other, 0, 1, 6, 0xffff, 7, operandTypes};
return true;
}
case SpvOpEmitMeshTasksEXT:
diff --git a/tests/expected-failure-github.txt b/tests/expected-failure-github.txt
index 2c5295967..48242fa05 100644
--- a/tests/expected-failure-github.txt
+++ b/tests/expected-failure-github.txt
@@ -1 +1,2 @@
-tests/cpu-program/gfx-smoke.slang (cpu) \ No newline at end of file
+tests/cpu-program/gfx-smoke.slang (cpu)
+tests/language-feature/spirv-asm/imageoperands-warning.slang (vk)
diff --git a/tests/language-feature/spirv-asm/imageoperands-warning.slang b/tests/language-feature/spirv-asm/imageoperands-warning.slang
new file mode 100644
index 000000000..fd22e6ae4
--- /dev/null
+++ b/tests/language-feature/spirv-asm/imageoperands-warning.slang
@@ -0,0 +1,45 @@
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -emit-spirv-directly
+//DIAGNOSTIC_TEST:SIMPLE(filecheck=DIAG):
+
+//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+// CHECK: 1
+// CHECK-NEXT: 1
+// CHECK-NEXT: 1
+// CHECK-NEXT: 1
+
+//TEST_INPUT: Texture2D(size=4, content = one):name t2D
+Texture2D<float> t2D;
+//TEST_INPUT: Sampler:name samplerState
+SamplerState samplerState;
+
+//
+// This test tests that we don't emit a warning for the variadic operand list
+// to OpImageSample. The reason to test for this is that "ImageOperands" aren't
+// specified as variadic in the json SPIR-V instruction descriptions.
+//
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int i = dispatchThreadID.x;
+ float2 loc = float2(0.5, 0.5);
+ float lod = 0;
+ float r = spirv_asm
+ {
+ // The type of our sampled image
+ %sampledImageType = OpTypeSampledImage $$Texture2D<float>;
+ // Combine the image with the sampler
+ %sampledImage : %sampledImageType = OpSampledImage $t2D $samplerState;
+ // Perform a sample
+ %sampled : __sampledType(float) = OpImageSampleExplicitLod %sampledImage $loc
+ // Put some sampling operands in here to check that they don't warn
+ // DIAG-NOT: warning{{.*}}too many operands
+ Lod $lod;
+ // Samples in SPIR-V always return a 4-vector of the component type,
+ // the __truncate function will drop elements so it fits into the
+ // desired output type
+ __truncate $$float result __sampledType(float) %sampled;
+ };
+ outputBuffer[i] = int(r);
+}