diff options
| -rw-r--r-- | source/slang/emit.cpp | 52 | ||||
| -rw-r--r-- | source/slang/modifier-defs.h | 3 | ||||
| -rw-r--r-- | source/slang/parser.cpp | 1 | ||||
| -rw-r--r-- | tests/render/nointerpolation.hlsl | 77 |
4 files changed, 133 insertions, 0 deletions
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<HLSLNoInterpolationModifier>()) + { + anyModifiers = true; + Emit(isGLSL ? "flat " : "nointerpolation "); + } + else if(decl->FindModifier<HLSLNoPerspectiveModifier>()) + { + anyModifiers = true; + Emit("noperspective "); + } + else if(decl->FindModifier<HLSLLinearModifier>()) + { + anyModifiers = true; + Emit(isGLSL ? "smooth " : "linear "); + } + else if(decl->FindModifier<HLSLSampleModifier>()) + { + anyModifiers = true; + Emit("sample "); + } + else if(decl->FindModifier<HLSLCentroidModifier>()) + { + 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()); diff --git a/source/slang/modifier-defs.h b/source/slang/modifier-defs.h index fdbb05748..baa08a160 100644 --- a/source/slang/modifier-defs.h +++ b/source/slang/modifier-defs.h @@ -258,6 +258,9 @@ END_SYNTAX_CLASS() // HLSL `nointerpolation` modifier SIMPLE_SYNTAX_CLASS(HLSLNoInterpolationModifier, InterpolationModeModifier) +// HLSL `noperspective` modifier +SIMPLE_SYNTAX_CLASS(HLSLNoPerspectiveModifier, InterpolationModeModifier) + // HLSL `linear` modifier SIMPLE_SYNTAX_CLASS(HLSLLinearModifier, InterpolationModeModifier) diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp index a3afbe87a..ea8e567b4 100644 --- a/source/slang/parser.cpp +++ b/source/slang/parser.cpp @@ -4358,6 +4358,7 @@ namespace Slang MODIFIER(column_major, HLSLColumnMajorLayoutModifier); MODIFIER(nointerpolation, HLSLNoInterpolationModifier); + MODIFIER(noperspective, HLSLNoPerspectiveModifier); MODIFIER(linear, HLSLLinearModifier); MODIFIER(sample, HLSLSampleModifier); MODIFIER(centroid, HLSLCentroidModifier); diff --git a/tests/render/nointerpolation.hlsl b/tests/render/nointerpolation.hlsl new file mode 100644 index 000000000..11613b30e --- /dev/null +++ b/tests/render/nointerpolation.hlsl @@ -0,0 +1,77 @@ +//TEST(smoke):COMPARE_HLSL_RENDER: + +// Confirm that the `nointerpolation` modifier +// makes it through Slang codegen with the +// same effect as for HLSL. + +cbuffer Uniforms +{ + float4x4 modelViewProjection; +} + +struct AssembledVertex +{ + float3 position; + float3 color; +}; + +struct CoarseVertex +{ + nointerpolation float3 color; +}; + +struct Fragment +{ + float4 color; +}; + + +// Vertex Shader + +struct VertexStageInput +{ + AssembledVertex assembledVertex : A; +}; + +struct VertexStageOutput +{ + CoarseVertex coarseVertex : CoarseVertex; + float4 sv_position : SV_Position; +}; + +VertexStageOutput vertexMain(VertexStageInput input) +{ + VertexStageOutput output; + + float3 position = input.assembledVertex.position; + float3 color = input.assembledVertex.color; + + output.coarseVertex.color = color; + output.sv_position = mul(modelViewProjection, float4(position, 1.0)); + + return output; +} + +// Fragment Shader + +struct FragmentStageInput +{ + CoarseVertex coarseVertex : CoarseVertex; +}; + +struct FragmentStageOutput +{ + Fragment fragment : SV_Target; +}; + +FragmentStageOutput fragmentMain(FragmentStageInput input) +{ + FragmentStageOutput output; + + float3 color = input.coarseVertex.color; + + output.fragment.color = float4(color, 1.0); + + return output; +} + |
