unit srFragLayout; {$mode ObjFPC}{$H+} interface uses typinfo, sysutils, spirv, ginodes, srNode, srType, srReg, srOp, srLayout, srVariable, srInput, srCapability, srDecorate; type //itPerspSample, //Sample //itPerspCenter, //itPerspCentroid, //Centroid //itLinearSample, //NoPerspective Sample //itLinearCenter, //NoPerspective //itLinearCentroid, //NoPerspective Centroid ntFragLayout=class(ntDescriptor) class function GetStorageName(node:PsrNode):RawByteString; override; end; PsrFragLayout=^TsrFragLayout; TsrFragLayout=object(TsrDescriptor) private pLeft,pRight:PsrFragLayout; //---- itype:TpsslInputType; function c(n1,n2:PsrFragLayout):Integer; static; public pReg:PsrRegNode; Procedure Init; inline; function GetStorageName:RawByteString; end; PsrFragLayoutList=^TsrFragLayoutList; TsrFragLayoutList=object type TNodeFetch=specialize TNodeFetch; var FEmit:TCustomEmit; FNTree:TNodeFetch; procedure Init(Emit:TCustomEmit); inline; function Fetch(itype:TpsslInputType;location:DWORD;rtype:TsrDataType):PsrFragLayout; Function First:PsrFragLayout; Function Next(node:PsrFragLayout):PsrFragLayout; procedure AllocBinding; procedure AllocEntryPoint(EntryPoint:PSpirvOp); end; implementation class function ntFragLayout.GetStorageName(node:PsrNode):RawByteString; begin Result:=PsrFragLayout(node)^.GetStorageName; end; // function TsrFragLayout.c(n1,n2:PsrFragLayout):Integer; begin //first itype Result:=Integer(n1^.itype>n2^.itype)-Integer(n1^.itype0) then Exit; //second location Result:=Integer(n1^.FBinding>n2^.FBinding)-Integer(n1^.FBindingnil) do begin pVar:=node^.pVar; if (pVar<>nil) and node^.IsUsed then begin pDecorateList^.OpDecorate(pVar,Decoration.Location,node^.FBinding); case node^.itype of itPerspSample: //Sample begin pCapabilityList^.Add(Capability.SampleRateShading); pDecorateList^.OpDecorate(pVar,Decoration.Sample,0); end; itPerspCenter:; //default itPerspCentroid: //Centroid begin pDecorateList^.OpDecorate(pVar,Decoration.Centroid,0); end; itLinearSample: //NoPerspective Sample begin pDecorateList^.OpDecorate(pVar,Decoration.NoPerspective,0); pDecorateList^.OpDecorate(pVar,Decoration.Sample,0); end; itLinearCenter: //NoPerspective begin pDecorateList^.OpDecorate(pVar,Decoration.NoPerspective,0); end; itLinearCentroid: //NoPerspective Centroid begin pDecorateList^.OpDecorate(pVar,Decoration.NoPerspective,0); pDecorateList^.OpDecorate(pVar,Decoration.Centroid,0); end; itFlat: begin pDecorateList^.OpDecorate(pVar,Decoration.Flat,0); end; else Assert(false,'AllocBinding:'+GetEnumName(TypeInfo(TpsslInputType),ord(node^.itype))); end; end; node:=Next(node); end; end; procedure TsrFragLayoutList.AllocEntryPoint(EntryPoint:PSpirvOp); var node:PsrFragLayout; pVar:PsrVariable; begin if (EntryPoint=nil) then Exit; node:=First; While (node<>nil) do begin pVar:=node^.pVar; if (pVar<>nil) and node^.IsUsed then begin EntryPoint^.AddParam(pVar); end; node:=Next(node); end; end; end.