summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-08-01 10:56:47 -0700
committerGitHub <noreply@github.com>2024-08-01 10:56:47 -0700
commit69dd7f40efd4988ba0fe3d4d5f6fee2d4d5d4a87 (patch)
tree2ab3aee0a8e6fea3223496afe92700d9f95394e5
parent32b843215b2e80c23c1fbcf02150c52a6304a447 (diff)
Perform type legalization on StructuredBuffer element. (#4767)
-rw-r--r--source/slang/slang-legalize-types.cpp26
-rw-r--r--tests/language-feature/interfaces/empty-type-conformance.slang27
2 files changed, 53 insertions, 0 deletions
diff --git a/source/slang/slang-legalize-types.cpp b/source/slang/slang-legalize-types.cpp
index aa69bac79..5e8390cef 100644
--- a/source/slang/slang-legalize-types.cpp
+++ b/source/slang/slang-legalize-types.cpp
@@ -1189,6 +1189,32 @@ LegalType legalizeTypeImpl(
legalElementType);
}
+ else if (auto bufferType = as<IRHLSLStructuredBufferTypeBase>(type))
+ {
+ auto legalElementType = legalizeType(context, bufferType->getElementType());
+ IRInst* newElementType = nullptr;
+ switch (legalElementType.flavor)
+ {
+ case LegalType::Flavor::simple:
+ if (legalElementType.getSimple() == bufferType->getElementType())
+ return LegalType::simple(bufferType);
+ newElementType = legalElementType.getSimple();
+ break;
+ case LegalType::Flavor::none:
+ newElementType = context->getBuilder()->getIntType();
+ break;
+ default:
+ return LegalType::simple(bufferType);
+ }
+ ShortList<IRInst*> operands;
+ for (UInt i = 0; i < bufferType->getOperandCount(); i++)
+ operands.add(bufferType->getOperand(i));
+ operands[0] = newElementType;
+ return LegalType::simple(context->getBuilder()->getType(
+ bufferType->getOp(),
+ bufferType->getOperandCount(),
+ operands.getArrayView().getBuffer()));
+ }
else if (isResourceType(type))
{
// We assume that any resource types not handled above
diff --git a/tests/language-feature/interfaces/empty-type-conformance.slang b/tests/language-feature/interfaces/empty-type-conformance.slang
new file mode 100644
index 000000000..9fee04607
--- /dev/null
+++ b/tests/language-feature/interfaces/empty-type-conformance.slang
@@ -0,0 +1,27 @@
+// Test that we allow empty type conformances.
+
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-dx11 -compute -output-using-type
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -output-using-type
+
+interface TestInterface {
+ float sample();
+}
+struct TestImplementation : TestInterface {
+ float sample() {
+ return 1.0f;
+ }
+};
+
+//TEST_INPUT: set inBuffer = new StructuredBuffer<TestInterface>[new TestImplementation{}];
+StructuredBuffer<TestInterface> inBuffer;
+
+//TEST_INPUT: set outputBuffer = out ubuffer(data=[0 0 0 0], stride=4);
+RWStructuredBuffer<float> outputBuffer;
+
+[shader("compute")]
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
+{
+ // CHECK: 1.0
+ outputBuffer[0] = inBuffer[0].sample();
+} \ No newline at end of file