From 5298ccf7da486d0010c6157974d5dd9a5556f265 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 5 Apr 2018 16:15:45 -0700 Subject: Falcor fixes (#479) * Don't emit interpolation modifiers on GLSL fields The previous change that started passing through interpolation modifiers didn't account for the fact that the GLSL grammar doesn't allow interpolation modifiers on `struct` fields, so we shouldn't emit them in that case (and our legalization strategy for GLSL guarantees that varying input will never use a `struct` type anyway). * Try to handle SV_Position semantic on GS input HLSL allows `SV` semantics to be used for ordinary inter-stage dataflow in some cases (e.g., a VS can output `SV_Position` and it can then be read from a GS). GLSL allows similar things with `gl_Position`, but there are some wrinkles. One fix here is to correctly identify that `gl_FragCoord` should only be used as the translation of `SV_Position` for a fragment shader input (and not in the general case of *any* input). The other "fix" here is a kludge to handle the fact that the right translation for a GS input is not to an array called `gl_Position`, but to the syntax `gl_in[index].gl_Position` (array-of-structs style). I am doing this by attaching a custom decoration to the global variable we create for `gl_Position` and then intercepting it during code emit. I'm not proud of this, and would like to do something better given time. * Fix GLSL output for matrix-scalar multiplication The output logic was assuming that any use of `operator*` in the input code that yields a value of matrix type must be translated to a `matrixCompMult()` call in GLSL, but this should really only apply if both of the *operands* are matrices (not just based on the result type). As a result matrix-times-scalar operations were emitting a call to `matrixCompMult()` and GLSL was complaining because it won't implicitly promote scalars to matrices. --- source/slang/emit.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'source/slang/emit.cpp') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 22b503b59..15f295740 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -3073,9 +3073,10 @@ struct EmitVisitor // because GLSL uses infix `*` to express inner product // when working with matrices. case kIROp_Mul: - // Are we targetting GLSL, and is this a matrix product? + // Are we targetting GLSL, and are both operands matrices? if(getTarget(ctx) == CodeGenTarget::GLSL - && inst->type->As()) + && inst->getOperand(0)->type->As() + && inst->getOperand(1)->type->As()) { emit("matrixCompMult("); emitIROperand(ctx, inst->getOperand(0), mode); @@ -3182,6 +3183,17 @@ struct EmitVisitor case kIROp_getElement: case kIROp_getElementPtr: + // HACK: deal with translation of GLSL geometry shader input arrays. + if(auto decoration = inst->getOperand(0)->findDecoration()) + { + emit(decoration->outerArrayName); + emit("["); + emitIROperand(ctx, inst->getOperand(1), mode); + emit("]."); + emitIROperand(ctx, inst->getOperand(0), mode); + break; + } + emitIROperand(ctx, inst->getOperand(0), mode); emit("["); emitIROperand(ctx, inst->getOperand(1), mode); @@ -5331,7 +5343,11 @@ struct EmitVisitor if(fieldType->Equals(getSession()->getVoidType())) continue; - emitInterpolationModifiers(ctx, ff.getDecl(), fieldType); + // Note: GLSL doesn't support interpolation modifiers on `struct` fields + if( ctx->shared->target != CodeGenTarget::GLSL ) + { + emitInterpolationModifiers(ctx, ff.getDecl(), fieldType); + } emitIRType(ctx, fieldType, getIRName(ff)); EmitSemantics(ff.getDecl()); -- cgit v1.2.3