From 7a26c176cecdb900926613fdb2c1ec1ba6a3568f Mon Sep 17 00:00:00 2001 From: Rex Xu Date: Tue, 8 Dec 2015 17:12:09 +0800 Subject: [PATCH] SPV: Implement GLSL interpolation built-in functions. --- SPIRV/GlslangToSpv.cpp | 19 +++- Test/baseResults/spv.interpOps.frag.out | 141 ++++++++++++++++++++++++ Test/spv.interpOps.frag | 32 ++++++ Test/test-spirv-list | 1 + 4 files changed, 190 insertions(+), 3 deletions(-) create mode 100644 Test/baseResults/spv.interpOps.frag.out create mode 100644 Test/spv.interpOps.frag diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 0fff30e9..4ed3af77 100755 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -822,7 +822,8 @@ bool TGlslangToSpvTraverser::visitUnary(glslang::TVisit /* visit */, glslang::TI if (node->getOp() == glslang::EOpAtomicCounterIncrement || node->getOp() == glslang::EOpAtomicCounterDecrement || - node->getOp() == glslang::EOpAtomicCounter) + node->getOp() == glslang::EOpAtomicCounter || + node->getOp() == glslang::EOpInterpolateAtCentroid) operand = builder.accessChainGetLValue(); // Special case l-value operands else operand = builder.accessChainLoad(convertGlslangToSpvType(node->getOperand()->getType())); @@ -1174,6 +1175,11 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt if (arg == 1) lvalue = true; break; + case glslang::EOpInterpolateAtSample: + case glslang::EOpInterpolateAtOffset: + if (arg == 0) + lvalue = true; + break; case glslang::EOpAtomicAdd: case glslang::EOpAtomicMin: case glslang::EOpAtomicMax: @@ -2508,7 +2514,9 @@ spv::Id TGlslangToSpvTraverser::createUnaryOperation(glslang::TOperator op, spv: case glslang::EOpFwidthCoarse: unaryOp = spv::OpFwidthCoarse; break; - + case glslang::EOpInterpolateAtCentroid: + libCall = spv::GLSLstd450InterpolateAtCentroid; + break; case glslang::EOpAny: unaryOp = spv::OpAny; break; @@ -2840,7 +2848,12 @@ spv::Id TGlslangToSpvTraverser::createMiscOperation(glslang::TOperator op, spv:: case glslang::EOpRefract: libCall = spv::GLSLstd450Refract; break; - + case glslang::EOpInterpolateAtSample: + libCall = spv::GLSLstd450InterpolateAtSample; + break; + case glslang::EOpInterpolateAtOffset: + libCall = spv::GLSLstd450InterpolateAtOffset; + break; case glslang::EOpAddCarry: opCode = spv::OpIAddCarry; typeId = builder.makeStructResultType(typeId0, typeId0); diff --git a/Test/baseResults/spv.interpOps.frag.out b/Test/baseResults/spv.interpOps.frag.out new file mode 100644 index 00000000..d23891b9 --- /dev/null +++ b/Test/baseResults/spv.interpOps.frag.out @@ -0,0 +1,141 @@ +spv.interpOps.frag +Warning, version 450 is not yet complete; most version-specific features are present, but some are missing. + + +Linked fragment stage: + + +// Module Version 10000 +// Generated by (magic number): 80001 +// Id's are bound by 101 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Fragment 4 "main" 13 24 33 41 99 + ExecutionMode 4 OriginLowerLeft + Source GLSL 450 + Name 4 "main" + Name 9 "f4" + Name 13 "if1" + Name 24 "if2" + Name 33 "if3" + Name 41 "if4" + Name 47 "samp" + Name 73 "offset" + Name 99 "fragColor" + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeFloat 32 + 7: TypeVector 6(float) 4 + 8: TypePointer Function 7(fvec4) + 10: 6(float) Constant 0 + 11: 7(fvec4) ConstantComposite 10 10 10 10 + 12: TypePointer Input 6(float) + 13(if1): 12(ptr) Variable Input + 15: TypeInt 32 0 + 16: 15(int) Constant 0 + 17: TypePointer Function 6(float) + 22: TypeVector 6(float) 2 + 23: TypePointer Input 22(fvec2) + 24(if2): 23(ptr) Variable Input + 31: TypeVector 6(float) 3 + 32: TypePointer Input 31(fvec3) + 33(if3): 32(ptr) Variable Input + 40: TypePointer Input 7(fvec4) + 41(if4): 40(ptr) Variable Input + 45: TypeInt 32 1 + 46: TypePointer UniformConstant 45(int) + 47(samp): 46(ptr) Variable UniformConstant + 72: TypePointer UniformConstant 22(fvec2) + 73(offset): 72(ptr) Variable UniformConstant + 98: TypePointer Output 7(fvec4) + 99(fragColor): 98(ptr) Variable Output + 4(main): 2 Function None 3 + 5: Label + 9(f4): 8(ptr) Variable Function + Store 9(f4) 11 + 14: 6(float) ExtInst 1(GLSL.std.450) 76(InterpolateAtCentroid) 13(if1) + 18: 17(ptr) AccessChain 9(f4) 16 + 19: 6(float) Load 18 + 20: 6(float) FAdd 19 14 + 21: 17(ptr) AccessChain 9(f4) 16 + Store 21 20 + 25: 22(fvec2) ExtInst 1(GLSL.std.450) 76(InterpolateAtCentroid) 24(if2) + 26: 7(fvec4) Load 9(f4) + 27: 22(fvec2) VectorShuffle 26 26 0 1 + 28: 22(fvec2) FAdd 27 25 + 29: 7(fvec4) Load 9(f4) + 30: 7(fvec4) VectorShuffle 29 28 4 5 2 3 + Store 9(f4) 30 + 34: 31(fvec3) ExtInst 1(GLSL.std.450) 76(InterpolateAtCentroid) 33(if3) + 35: 7(fvec4) Load 9(f4) + 36: 31(fvec3) VectorShuffle 35 35 0 1 2 + 37: 31(fvec3) FAdd 36 34 + 38: 7(fvec4) Load 9(f4) + 39: 7(fvec4) VectorShuffle 38 37 4 5 6 3 + Store 9(f4) 39 + 42: 7(fvec4) ExtInst 1(GLSL.std.450) 76(InterpolateAtCentroid) 41(if4) + 43: 7(fvec4) Load 9(f4) + 44: 7(fvec4) FAdd 43 42 + Store 9(f4) 44 + 48: 45(int) Load 47(samp) + 49: 6(float) ExtInst 1(GLSL.std.450) 77(InterpolateAtSample) 13(if1) 48 + 50: 17(ptr) AccessChain 9(f4) 16 + 51: 6(float) Load 50 + 52: 6(float) FAdd 51 49 + 53: 17(ptr) AccessChain 9(f4) 16 + Store 53 52 + 54: 45(int) Load 47(samp) + 55: 22(fvec2) ExtInst 1(GLSL.std.450) 77(InterpolateAtSample) 24(if2) 54 + 56: 7(fvec4) Load 9(f4) + 57: 22(fvec2) VectorShuffle 56 56 0 1 + 58: 22(fvec2) FAdd 57 55 + 59: 7(fvec4) Load 9(f4) + 60: 7(fvec4) VectorShuffle 59 58 4 5 2 3 + Store 9(f4) 60 + 61: 45(int) Load 47(samp) + 62: 31(fvec3) ExtInst 1(GLSL.std.450) 77(InterpolateAtSample) 33(if3) 61 + 63: 7(fvec4) Load 9(f4) + 64: 31(fvec3) VectorShuffle 63 63 0 1 2 + 65: 31(fvec3) FAdd 64 62 + 66: 7(fvec4) Load 9(f4) + 67: 7(fvec4) VectorShuffle 66 65 4 5 6 3 + Store 9(f4) 67 + 68: 45(int) Load 47(samp) + 69: 7(fvec4) ExtInst 1(GLSL.std.450) 77(InterpolateAtSample) 41(if4) 68 + 70: 7(fvec4) Load 9(f4) + 71: 7(fvec4) FAdd 70 69 + Store 9(f4) 71 + 74: 22(fvec2) Load 73(offset) + 75: 6(float) ExtInst 1(GLSL.std.450) 78(InterpolateAtOffset) 13(if1) 74 + 76: 17(ptr) AccessChain 9(f4) 16 + 77: 6(float) Load 76 + 78: 6(float) FAdd 77 75 + 79: 17(ptr) AccessChain 9(f4) 16 + Store 79 78 + 80: 22(fvec2) Load 73(offset) + 81: 22(fvec2) ExtInst 1(GLSL.std.450) 78(InterpolateAtOffset) 24(if2) 80 + 82: 7(fvec4) Load 9(f4) + 83: 22(fvec2) VectorShuffle 82 82 0 1 + 84: 22(fvec2) FAdd 83 81 + 85: 7(fvec4) Load 9(f4) + 86: 7(fvec4) VectorShuffle 85 84 4 5 2 3 + Store 9(f4) 86 + 87: 22(fvec2) Load 73(offset) + 88: 31(fvec3) ExtInst 1(GLSL.std.450) 78(InterpolateAtOffset) 33(if3) 87 + 89: 7(fvec4) Load 9(f4) + 90: 31(fvec3) VectorShuffle 89 89 0 1 2 + 91: 31(fvec3) FAdd 90 88 + 92: 7(fvec4) Load 9(f4) + 93: 7(fvec4) VectorShuffle 92 91 4 5 6 3 + Store 9(f4) 93 + 94: 22(fvec2) Load 73(offset) + 95: 7(fvec4) ExtInst 1(GLSL.std.450) 78(InterpolateAtOffset) 41(if4) 94 + 96: 7(fvec4) Load 9(f4) + 97: 7(fvec4) FAdd 96 95 + Store 9(f4) 97 + 100: 7(fvec4) Load 9(f4) + Store 99(fragColor) 100 + Return + FunctionEnd diff --git a/Test/spv.interpOps.frag b/Test/spv.interpOps.frag new file mode 100644 index 00000000..fccf304a --- /dev/null +++ b/Test/spv.interpOps.frag @@ -0,0 +1,32 @@ +#version 450 + +in float if1; +in vec2 if2; +in vec3 if3; +in vec4 if4; + +uniform int samp; +uniform vec2 offset; + +out vec4 fragColor; + +void main() +{ + vec4 f4 = vec4(0.0); + f4.x += interpolateAtCentroid(if1); + f4.xy += interpolateAtCentroid(if2); + f4.xyz += interpolateAtCentroid(if3); + f4 += interpolateAtCentroid(if4); + + f4.x += interpolateAtSample(if1, samp); + f4.xy += interpolateAtSample(if2, samp); + f4.xyz += interpolateAtSample(if3, samp); + f4 += interpolateAtSample(if4, samp); + + f4.x += interpolateAtOffset(if1, offset); + f4.xy += interpolateAtOffset(if2, offset); + f4.xyz += interpolateAtOffset(if3, offset); + f4 += interpolateAtOffset(if4, offset); + + fragColor = f4; +} diff --git a/Test/test-spirv-list b/Test/test-spirv-list index 1efcfcb3..136a9a67 100644 --- a/Test/test-spirv-list +++ b/Test/test-spirv-list @@ -45,6 +45,7 @@ spv.forLoop.frag spv.forwardFun.frag spv.functionCall.frag spv.functionSemantics.frag +spv.interpOps.frag spv.length.frag spv.localAggregates.frag spv.loops.frag