summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2019-01-27 00:08:17 -0800
committerYong He <yonghe@google.com>2019-01-28 10:50:05 -0800
commit9812963c52eb6312546f600804bb642a38dcfe64 (patch)
tree589be4c5b1f9e74da86caa6bd5be6a4f13083b15
parentf2579a60a3de45d5f48f1e1433ba736647988e8e (diff)
Fix type legalization to correctly handle empty struct fields.
-rw-r--r--source/slang/legalize-types.cpp41
-rw-r--r--tests/cross-compile/glsl-empty-struct-param-field.slang17
-rw-r--r--tests/cross-compile/glsl-empty-struct-param-field.slang.glsl26
-rw-r--r--tests/cross-compile/glsl-generic-in.slang.glsl1
4 files changed, 57 insertions, 28 deletions
diff --git a/source/slang/legalize-types.cpp b/source/slang/legalize-types.cpp
index 858dbd95c..30590c02d 100644
--- a/source/slang/legalize-types.cpp
+++ b/source/slang/legalize-types.cpp
@@ -785,17 +785,15 @@ LegalType legalizeTypeImpl(
auto legalElementType = legalizeType(context,
uniformBufferType->getElementType());
- switch (legalElementType.flavor)
- {
- case LegalType::Flavor::simple:
- return LegalType::simple(type);
-
- default:
- return createLegalUniformBufferType(
+ // Note that even when legalElementType.flavor == Simple
+ // we still need to create a new uniform buffer type
+ // from `legalElementType` instead of `type`
+ // because the `legalElementType` may still differ from `type`
+ // if `type` contains empty structs.
+ return createLegalUniformBufferType(
context,
uniformBufferType,
legalElementType);
- }
}
else if (isResourceType(type))
@@ -898,27 +896,14 @@ LegalType legalizeTypeImpl(
context,
arrayType->getElementType());
- switch (legalElementType.flavor)
- {
- case LegalType::Flavor::simple:
- // Element type didn't need to be legalized, so
- // we can just use this type as-is.
- return LegalType::simple(type);
-
- default:
- {
- ArrayLegalTypeWrapper wrapper;
- wrapper.arrayType = arrayType;
-
- return wrapLegalType(
- context,
- legalElementType,
- &wrapper,
- &wrapper);
- }
- break;
- }
+ ArrayLegalTypeWrapper wrapper;
+ wrapper.arrayType = arrayType;
+ return wrapLegalType(
+ context,
+ legalElementType,
+ &wrapper,
+ &wrapper);
}
return LegalType::simple(type);
diff --git a/tests/cross-compile/glsl-empty-struct-param-field.slang b/tests/cross-compile/glsl-empty-struct-param-field.slang
new file mode 100644
index 000000000..21b67e325
--- /dev/null
+++ b/tests/cross-compile/glsl-empty-struct-param-field.slang
@@ -0,0 +1,17 @@
+//TEST:CROSS_COMPILE:-target spirv-assembly -entry main -profile ps_5_0
+
+struct E
+{
+};
+
+struct P
+{
+ E em;
+ float4 param;
+};
+ParameterBlock<P> pblock;
+
+float4 main(float4 pos : SV_POSITION)
+{
+ return pblock.param;
+} \ No newline at end of file
diff --git a/tests/cross-compile/glsl-empty-struct-param-field.slang.glsl b/tests/cross-compile/glsl-empty-struct-param-field.slang.glsl
new file mode 100644
index 000000000..0f5d53a2c
--- /dev/null
+++ b/tests/cross-compile/glsl-empty-struct-param-field.slang.glsl
@@ -0,0 +1,26 @@
+//TEST_IGNORE_FILE:
+#version 450
+layout(row_major) uniform;
+layout(row_major) buffer;
+
+#line 14 0
+struct P_0
+{
+ vec4 param_0;
+};
+
+layout(binding = 0)
+layout(std140) uniform _S1
+{
+ P_0 _data;
+} pblock_0;
+layout(location = 0)
+out vec4 _S2;
+
+
+#line 14
+void main()
+{
+ _S2 = pblock_0._data.param_0;
+ return;
+} \ No newline at end of file
diff --git a/tests/cross-compile/glsl-generic-in.slang.glsl b/tests/cross-compile/glsl-generic-in.slang.glsl
index 7dbe7feca..ee686b833 100644
--- a/tests/cross-compile/glsl-generic-in.slang.glsl
+++ b/tests/cross-compile/glsl-generic-in.slang.glsl
@@ -1,3 +1,4 @@
+//TEST_IGNORE_FILE:
#version 450
layout(row_major) uniform;
layout(row_major) buffer;