diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-07-18 07:49:33 -0700 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-07-18 12:58:48 -0700 |
| commit | 1c022e2c3654de868c45658683f9e04cf4d68cc0 (patch) | |
| tree | d4a5f0cefd50c96aaf22921f9fef715b6359c0c5 /source/slang/emit.cpp | |
| parent | 361e29572ff8e2cdd1e4ffe2cb62599e9ef06461 (diff) | |
Support scalarization of varying input/output for GLSL
GLSL technically supports varying (`in`, `out`) parameters of `struct` type, but there are some annoying constraints (not allowed for VS input), and it doesn't work with how an HLSL user would usually put "system-value" inputs/outputs into a `struct` together with ordinary inputs/outputs.
To work around this, this change adds support for using an imported Slang `struct` type for an `in` or `out` parameter, in which case it will (1) be scalarized and (2) will have system-value semantics mapped appropriately, just as for an entry-point parameter when cross-compiling an HLSL-style `main()`.
Changes:
- Add a notion of a `VaryingTupleExpr` and `VaryingTupleVarDecl`, similar to those for the resources-in-structs case
- Trigger use of these when we have a global-scope varying in/out using an imported `struct` type
- Also use these in the cross-compilation case for ordinary varying input/output (since this approach seems like it should be more general, and can hopefully handle stuff like GS input/output some day)
- When generating parameter binding information, special case global-scope input/output, and treat it the same as entry-point-parameter input/output
- Revamp how used resource ranges are computed so that we can eventually make this specific to an entry point
- Actually implement first signs of life for `maybeMoveTemp` so that assignments to the tuple-ified outputs will work better
- Add first test case that actually seems to work
- Add diagnostics for conflicting explicit bindings on a parameter
- Add diagnostic for different parameters with overlapping bindings
- Make global-scope varying input/output use a tracking data structure specific to the translation unit for computing locations (so that they are independent of other TUs)
Diffstat (limited to 'source/slang/emit.cpp')
| -rw-r--r-- | source/slang/emit.cpp | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index ef922c418..76dc9c75f 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -1991,7 +1991,25 @@ struct EmitVisitor emitSimpleCallExpr(callExpr, outerPrec); } + void visitAggTypeCtorExpr(AggTypeCtorExpr* expr, ExprEmitArg const& arg) + { + auto prec = kEOp_Postfix; + auto outerPrec = arg.outerPrec; + bool needClose = MaybeEmitParens(outerPrec, prec); + emitTypeExp(expr->base); + Emit("("); + bool first = true; + for (auto aa : expr->Arguments) + { + if (!first) Emit(", "); + EmitExpr(aa); + first = false; + } + Emit(")"); + + if(needClose) Emit(")"); + } void visitMemberExpressionSyntaxNode(MemberExpressionSyntaxNode* memberExpr, ExprEmitArg const& arg) { @@ -3245,17 +3263,23 @@ struct EmitVisitor auto declRefType = dataType->As<DeclRefType>(); assert(declRefType); - // We expect to always have layout information - assert(layout); + // We expect the layout, if present, to be for a structured type... + RefPtr<StructTypeLayout> structTypeLayout; + if (layout) + { - // We expect the layout to be for a structured type... - RefPtr<ParameterBlockTypeLayout> bufferLayout = layout->typeLayout.As<ParameterBlockTypeLayout>(); - assert(bufferLayout); + auto typeLayout = layout->typeLayout; + if (auto bufferLayout = typeLayout.As<ParameterBlockTypeLayout>()) + { + typeLayout = bufferLayout->elementTypeLayout; + } - RefPtr<StructTypeLayout> structTypeLayout = bufferLayout->elementTypeLayout.As<StructTypeLayout>(); - assert(structTypeLayout); + structTypeLayout = typeLayout.As<StructTypeLayout>(); + assert(structTypeLayout); + + emitGLSLLayoutQualifiers(layout); + } - emitGLSLLayoutQualifiers(layout); EmitModifiers(varDecl); @@ -3293,13 +3317,16 @@ struct EmitVisitor { for (auto field : getMembersOfType<StructField>(structRef)) { - RefPtr<VarLayout> fieldLayout; - structTypeLayout->mapVarToLayout.TryGetValue(field.getDecl(), fieldLayout); - // assert(fieldLayout); + if (structTypeLayout) + { + RefPtr<VarLayout> fieldLayout; + structTypeLayout->mapVarToLayout.TryGetValue(field.getDecl(), fieldLayout); + // assert(fieldLayout); - // TODO(tfoley): We may want to emit *some* of these, - // some of the time... - // emitGLSLLayoutQualifiers(fieldLayout); + // TODO(tfoley): We may want to emit *some* of these, + // some of the time... + // emitGLSLLayoutQualifiers(fieldLayout); + } EmitVarDeclCommon(field); |
