summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2019-01-28 10:47:48 -0800
committerGitHub <noreply@github.com>2019-01-28 10:47:48 -0800
commit016f38981a52dd31aa4d3d35272c37f992a07862 (patch)
treed11ff742f08a25469fa1a86c8b4d0061853fb63d
parentdf9dc5710725d00630831b77ca7005e390383aa6 (diff)
parent962f265df9e1b8549202a9b9543e1bead190638d (diff)
Merge pull request #805 from csyonghe/yong-fix
More fixes to empty-struct parameters
-rw-r--r--source/slang/emit.cpp63
-rw-r--r--source/slang/ir-glsl-legalize.cpp18
-rw-r--r--tests/cross-compile/glsl-generic-in.slang33
-rw-r--r--tests/cross-compile/glsl-generic-in.slang.glsl69
4 files changed, 147 insertions, 36 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index 71b961616..dd6feb50d 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -3585,6 +3585,9 @@ struct EmitVisitor
UInt argCount = inst->getOperandCount();
for( UInt aa = 1; aa < argCount; ++aa )
{
+ auto operand = inst->getOperand(aa);
+ if (as<IRVoidType>(operand->getDataType()))
+ continue;
if(aa != 1) emit(", ");
emitIROperand(ctx, inst->getOperand(aa), mode, kEOp_General);
}
@@ -6100,6 +6103,8 @@ struct EmitVisitor
{
varType = outType->getValueType();
}
+ if (as<IRVoidType>(varType))
+ return;
// When a global shader parameter represents a "parameter group"
// (either a constant buffer or a parameter block with non-resource
@@ -6653,36 +6658,6 @@ String emitEntryPoint(
// un-specialized IR.
dumpIRIfEnabled(compileRequest, irModule);
-
-
- // For GLSL only, we will need to perform "legalization" of
- // the entry point and any entry-point parameters.
- //
- // TODO: We should consider moving this legalization work
- // as late as possible, so that it doesn't affect how other
- // optimization passes need to work.
- //
- switch (target)
- {
- case CodeGenTarget::GLSL:
- {
- legalizeEntryPointForGLSL(
- session,
- irModule,
- irEntryPoint,
- &compileRequest->mSink,
- &sharedContext.extensionUsageTracker);
- }
- break;
-
- default:
- break;
- }
-#if 0
- dumpIRIfEnabled(compileRequest, irModule, "GLSL LEGALIZED");
-#endif
- validateIRModuleIfEnabled(compileRequest, irModule);
-
// Desguar any union types, since these will be illegal on
// various targets.
//
@@ -6778,6 +6753,34 @@ String emitEntryPoint(
#endif
validateIRModuleIfEnabled(compileRequest, irModule);
+ // For GLSL only, we will need to perform "legalization" of
+ // the entry point and any entry-point parameters.
+ //
+ // TODO: We should consider moving this legalization work
+ // as late as possible, so that it doesn't affect how other
+ // optimization passes need to work.
+ //
+ switch (target)
+ {
+ case CodeGenTarget::GLSL:
+ {
+ legalizeEntryPointForGLSL(
+ session,
+ irModule,
+ irEntryPoint,
+ &compileRequest->mSink,
+ &sharedContext.extensionUsageTracker);
+ }
+ break;
+
+ default:
+ break;
+ }
+#if 0
+ dumpIRIfEnabled(compileRequest, irModule, "GLSL LEGALIZED");
+#endif
+ validateIRModuleIfEnabled(compileRequest, irModule);
+
// The resource-based specialization pass above
// may create specialized versions of functions, but
// it does not try to completely eliminate the original
diff --git a/source/slang/ir-glsl-legalize.cpp b/source/slang/ir-glsl-legalize.cpp
index 9c4210be0..d2b696c5b 100644
--- a/source/slang/ir-glsl-legalize.cpp
+++ b/source/slang/ir-glsl-legalize.cpp
@@ -567,7 +567,11 @@ ScalarizedVal createGLSLGlobalVaryingsImpl(
UInt bindingIndex,
GlobalVaryingDeclarator* declarator)
{
- if( as<IRBasicType>(type) )
+ if (as<IRVoidType>(type))
+ {
+ return ScalarizedVal();
+ }
+ else if( as<IRBasicType>(type) )
{
return createSimpleGLSLGlobalVarying(
context,
@@ -675,12 +679,14 @@ ScalarizedVal createGLSLGlobalVaryingsImpl(
stage,
fieldBindingIndex,
declarator);
+ if (fieldVal.flavor != ScalarizedVal::Flavor::none)
+ {
+ ScalarizedTupleValImpl::Element element;
+ element.val = fieldVal;
+ element.key = field->getKey();
- ScalarizedTupleValImpl::Element element;
- element.val = fieldVal;
- element.key = field->getKey();
-
- tupleValImpl->elements.Add(element);
+ tupleValImpl->elements.Add(element);
+ }
}
return ScalarizedVal::tuple(tupleValImpl);
diff --git a/tests/cross-compile/glsl-generic-in.slang b/tests/cross-compile/glsl-generic-in.slang
new file mode 100644
index 000000000..90fe387ba
--- /dev/null
+++ b/tests/cross-compile/glsl-generic-in.slang
@@ -0,0 +1,33 @@
+//TEST:CROSS_COMPILE:-target spirv-assembly -entry main -profile vs_5_0
+interface IField
+{
+ float get();
+};
+struct GIn<TField : IField, TEmptyField>
+{
+ float3 p0;
+ TField field;
+ TEmptyField e;
+};
+struct F : IField
+{
+ float4 v0;
+ float2 v1;
+ float get() { return v0.x + v1.x; }
+};
+struct E
+{
+ float get() {return 1.0;}
+};
+
+struct VOut
+{
+ float4 projPos : SV_POSITION;
+};
+
+VOut main(GIn<F, E> vIn)
+{
+ VOut vout;
+ vout.projPos = float4(vIn.p0, vIn.field.get() + vIn.e.get());
+ return vout;
+} \ 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
new file mode 100644
index 000000000..7dbe7feca
--- /dev/null
+++ b/tests/cross-compile/glsl-generic-in.slang.glsl
@@ -0,0 +1,69 @@
+#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;
+
+layout(location = 1)
+in vec4 _S2;
+
+layout(location = 2)
+in vec2 _S3;
+
+struct GIn_0
+{
+ vec3 p0_0;
+ F_0 field_0;
+};
+
+struct VOut_0
+{
+ vec4 projPos_0;
+};
+
+
+
+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;
+} \ No newline at end of file