summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2019-01-28 16:12:16 -0800
committerGitHub <noreply@github.com>2019-01-28 16:12:16 -0800
commitf8b8ea0055ad877551198e1e295d33860b504672 (patch)
tree1d39bbf22e31dbc0e1d3861258dbcbbeb0dc3bc6
parent3c3513ab501277333d1062ad2737ac4a60dac6f7 (diff)
parentadb3e222393a780de41f258bd273fa3231db10c0 (diff)
Merge pull request #807 from csyonghe/yong-fix2
Fix type legalization to correctly handle nested 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.glsl23
-rw-r--r--tests/cross-compile/glsl-generic-in.slang.glsl13
4 files changed, 54 insertions, 40 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..0ff895179
--- /dev/null
+++ b/tests/cross-compile/glsl-empty-struct-param-field.slang.glsl
@@ -0,0 +1,23 @@
+//TEST_IGNORE_FILE:
+#version 450
+layout(row_major) uniform;
+layout(row_major) buffer;
+
+struct P_0
+{
+ vec4 param_0;
+};
+
+layout(binding = 0)
+layout(std140) uniform _S1
+{
+ P_0 _data;
+} pblock_0;
+layout(location = 0)
+out vec4 _S2;
+
+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..61ce0b71b 100644
--- a/tests/cross-compile/glsl-generic-in.slang.glsl
+++ b/tests/cross-compile/glsl-generic-in.slang.glsl
@@ -1,33 +1,25 @@
+//TEST_IGNORE_FILE:
#version 450
layout(row_major) uniform;
layout(row_major) buffer;
-#line 12 0
struct F_0
{
vec4 v0_0;
vec2 v1_0;
};
-
-#line 16
float F_get_0(F_0 this_0)
{
-
-#line 16
return this_0.v0_0.x + this_0.v1_0.x;
}
float E_get_0()
{
-
-#line 20
return 1.00000000000000000000;
}
-
-#line 6
layout(location = 0)
in vec3 _S1;
@@ -54,15 +46,12 @@ void main()
{
GIn_0 _S4 = GIn_0(_S1, F_0(_S2, _S3));
-#line 30
VOut_0 vout_0;
vec3 _S5 = _S4.p0_0;
-#line 31
float _S6 = F_get_0(_S4.field_0);
float _S7 = E_get_0();
-#line 31
vout_0.projPos_0 = vec4(_S5, _S6 + _S7);
gl_Position = vout_0.projPos_0;
return;