From a38490d7716ef6cbf9cbb992b880b9bbc9c1ac93 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 25 Jan 2019 11:28:46 -0800 Subject: Move glsl entry point legalization to later stage of compilation. This allows generic types to be used in entry point parameters. --- source/slang/emit.cpp | 58 ++++++++++++------------ tests/cross-compile/glsl-generic-in.slang | 28 ++++++++++++ tests/cross-compile/glsl-generic-in.slang.glsl | 61 ++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 30 deletions(-) create mode 100644 tests/cross-compile/glsl-generic-in.slang create mode 100644 tests/cross-compile/glsl-generic-in.slang.glsl diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 914aea7fd..c3e1b2d08 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -6640,36 +6640,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. // @@ -6765,6 +6735,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/tests/cross-compile/glsl-generic-in.slang b/tests/cross-compile/glsl-generic-in.slang new file mode 100644 index 000000000..e9b9a5a91 --- /dev/null +++ b/tests/cross-compile/glsl-generic-in.slang @@ -0,0 +1,28 @@ +//TEST:CROSS_COMPILE:-target spirv-assembly -entry main -profile vs_5_0 +interface IField +{ + float get(); +}; +struct GIn +{ + float3 p0; + TField field; +}; +struct F : IField +{ + float4 v0; + float2 v1; + float get() { return v0.x + v1.x; } +}; + +struct VOut +{ + float4 projPos : SV_POSITION; +}; + +VOut main(GIn vIn) +{ + VOut vout; + vout.projPos = float4(vIn.p0, vIn.field.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..66d7546ff --- /dev/null +++ b/tests/cross-compile/glsl-generic-in.slang.glsl @@ -0,0 +1,61 @@ +//TEST_IGNORE_FILE +#version 450 +layout(row_major) uniform; +layout(row_major) buffer; + +#line 11 0 +struct F_0 +{ + vec4 v0_0; + vec2 v1_0; +}; + + +#line 15 +float F_get_0(F_0 this_0) +{ + +#line 15 + return this_0.v0_0.x + this_0.v1_0.x; +} + + +#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; +}; + + +#line 23 +void main() +{ + GIn_0 _S4 = GIn_0(_S1, F_0(_S2, _S3)); + +#line 25 + VOut_0 vout_0; + vec3 _S5 = _S4.p0_0; + +#line 26 + float _S6 = F_get_0(_S4.field_0); + +#line 26 + vout_0.projPos_0 = vec4(_S5, _S6); + gl_Position = vout_0.projPos_0; + return; +} \ No newline at end of file -- cgit v1.2.3 From 864c38ee72991f414f2478ccacb462bfb11b4bca Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 25 Jan 2019 17:45:42 -0800 Subject: fix up empty-struct-parameters --- source/slang/emit.cpp | 5 +++++ source/slang/ir-glsl-legalize.cpp | 18 ++++++++++++------ tests/cross-compile/glsl-generic-in.slang | 11 ++++++++--- tests/cross-compile/glsl-generic-in.slang.glsl | 26 +++++++++++++++++--------- 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index c3e1b2d08..536c72e11 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -3572,6 +3572,9 @@ struct EmitVisitor UInt argCount = inst->getOperandCount(); for( UInt aa = 1; aa < argCount; ++aa ) { + auto operand = inst->getOperand(aa); + if (as(operand->getDataType())) + continue; if(aa != 1) emit(", "); emitIROperand(ctx, inst->getOperand(aa), mode, kEOp_General); } @@ -6087,6 +6090,8 @@ struct EmitVisitor { varType = outType->getValueType(); } + if (as(varType)) + return; // When a global shader parameter represents a "parameter group" // (either a constant buffer or a parameter block with non-resource 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(type) ) + if (as(type)) + { + return ScalarizedVal(); + } + else if( as(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 index e9b9a5a91..90fe387ba 100644 --- a/tests/cross-compile/glsl-generic-in.slang +++ b/tests/cross-compile/glsl-generic-in.slang @@ -3,10 +3,11 @@ interface IField { float get(); }; -struct GIn +struct GIn { float3 p0; TField field; + TEmptyField e; }; struct F : IField { @@ -14,15 +15,19 @@ struct F : IField 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 vIn) +VOut main(GIn vIn) { VOut vout; - vout.projPos = float4(vIn.p0, vIn.field.get()); + 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 index 66d7546ff..7dbe7feca 100644 --- a/tests/cross-compile/glsl-generic-in.slang.glsl +++ b/tests/cross-compile/glsl-generic-in.slang.glsl @@ -1,9 +1,8 @@ -//TEST_IGNORE_FILE #version 450 layout(row_major) uniform; layout(row_major) buffer; -#line 11 0 +#line 12 0 struct F_0 { vec4 v0_0; @@ -11,15 +10,23 @@ struct F_0 }; -#line 15 +#line 16 float F_get_0(F_0 this_0) { -#line 15 +#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; @@ -42,20 +49,21 @@ struct VOut_0 }; -#line 23 + void main() { GIn_0 _S4 = GIn_0(_S1, F_0(_S2, _S3)); -#line 25 +#line 30 VOut_0 vout_0; vec3 _S5 = _S4.p0_0; -#line 26 +#line 31 float _S6 = F_get_0(_S4.field_0); + float _S7 = E_get_0(); -#line 26 - vout_0.projPos_0 = vec4(_S5, _S6); +#line 31 + vout_0.projPos_0 = vec4(_S5, _S6 + _S7); gl_Position = vout_0.projPos_0; return; } \ No newline at end of file -- cgit v1.2.3