From 7a8ed51873743e6497db28b5a756e080491d2fa3 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 4 Apr 2018 07:18:33 -0700 Subject: Pass AST interpolation modifiers through to codegen. (#475) This is a short-term fix, because we (1) don't have an IR-level representation of interpolation qualifiers, and (2) can't introduce one until *after* the IR-level type system is introduced (to be able to handle `struct` fields). The approach here is to find the AST-level declaration, either from layout information (in the case of an ordinary variable or function parameter), or from struct field information (because structs are being output from the AST form anyway). I've included a single end-to-end rendering test to confirm that we handle the `nointerpolation` modifier the same as HLSL. I also added the `noperspective` modifier, which seemed to be missing from our implementation. --- source/slang/emit.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'source/slang/emit.cpp') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index f6a87fcfa..22b503b59 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -4574,6 +4574,57 @@ struct EmitVisitor } } + void emitInterpolationModifiers( + EmitContext* ctx, + VarDeclBase* decl, + Type* valueType) + { + bool isGLSL = (ctx->shared->target == CodeGenTarget::GLSL); + bool anyModifiers = false; + + if(decl->FindModifier()) + { + anyModifiers = true; + Emit(isGLSL ? "flat " : "nointerpolation "); + } + else if(decl->FindModifier()) + { + anyModifiers = true; + Emit("noperspective "); + } + else if(decl->FindModifier()) + { + anyModifiers = true; + Emit(isGLSL ? "smooth " : "linear "); + } + else if(decl->FindModifier()) + { + anyModifiers = true; + Emit("sample "); + } + else if(decl->FindModifier()) + { + anyModifiers = true; + Emit("centroid "); + } + + // If the user didn't explicitly qualify a varying + // with integer type, then we need to explicitly + // add the `flat` modifier for GLSL. + if(!anyModifiers && isGLSL) + { + maybeEmitGLSLFlatModifier(ctx, valueType); + } + } + + void emitInterpolationModifiers( + EmitContext* ctx, + VarLayout* layout, + Type* valueType) + { + emitInterpolationModifiers(ctx, layout->varDecl, valueType); + } + void emitIRVarModifiers( EmitContext* ctx, VarLayout* layout, @@ -5280,6 +5331,7 @@ struct EmitVisitor if(fieldType->Equals(getSession()->getVoidType())) continue; + emitInterpolationModifiers(ctx, ff.getDecl(), fieldType); emitIRType(ctx, fieldType, getIRName(ff)); EmitSemantics(ff.getDecl()); -- cgit v1.2.3