This commit is contained in:
Pavel 2024-12-05 21:43:30 +03:00
parent 58b6906155
commit db52f2d427
29 changed files with 524 additions and 362 deletions

View File

@ -22,7 +22,7 @@ uses
type
TEmit_DS=class(TEmitFetch)
procedure emit_DS;
procedure _emit_DS_SWIZZLE_B32;
procedure emit_DS_SWIZZLE_B32;
function fetch_ds_chain (vbindex:TsrRegNode;rtype,atomic:TsrDataType;offset:Word):TsrChain;
procedure emit_DS_WRITE (rtype:TsrDataType);
procedure emit_DS_WRITE2 (rtype:TsrDataType);
@ -38,14 +38,17 @@ const
QdMode =1;
type
tds_lanes=bitpacked record
lane0:bit2;
lane1:bit2;
lane2:bit2;
lane3:bit2;
end;
tds_pattern=packed record
Case Byte of
0:(qd:bitpacked record
lanes:bit8;
//lane0:bit2;
//lane1:bit2;
//lane2:bit2;
//lane3:bit2;
lanes:tds_lanes;
align:bit7;
mode :bit1;
end);
@ -57,89 +60,66 @@ type
end);
end;
procedure TEmit_DS._emit_DS_SWIZZLE_B32; //TODO: DS_SWIZZLE_B32
procedure TEmit_DS.emit_DS_SWIZZLE_B32;
Var
dst:PsrRegSlot;
src:TsrRegNode;
inv:TsrRegNode;
ofs:TsrRegNode;
cm4:TsrRegNode;
cm3:TsrRegNode;
cm1:TsrRegNode;
elm:TsrRegNode;
tmp:TsrRegNode;
lof:TsrRegNode;
lob:TsrRegNode;
lid:TsrRegNode;
dst :PsrRegSlot;
src :TsrRegNode;
lane_id :TsrRegNode;
id_in_group:TsrRegNode;
lanes :TsrRegNode;
base :TsrRegNode;
index :TsrRegNode;
pat:tds_pattern;
begin
{
Word(pat):=PWORD(@FSPI.DS.OFFSET0)^;
Word(pat):=PWORD(@FSPI.DS.OFFSET)^;
AddCap(Capability.GroupNonUniformShuffle);
dst:=FRegsStory.get_vdst8(FSPI.DS.VDST);
dst:=get_vdst8 (FSPI.DS.VDST);
src:=fetch_vsrc8(FSPI.DS.ADDR,dtUnknow);
inv:=AddInput(@FRegsStory.FUnattach,dtUint32,itSubgroupLocalInvocationId);
case src.dtype of
dtFloat32:; //allow
dtInt32 :; //allow
dtUint32 :; //allow
else
begin
//retype
src:=fetch_vsrc8(FSPI.DS.ADDR,dtUint32);
end;
end;
Case pat.qd.mode of
QdMode:
begin
ofs:=FetchReg(FConsts.Fetch(dtUint32,pat.qd.lanes));
if (pat.qd.lanes.lane0=pat.qd.lanes.lane1) and
(pat.qd.lanes.lane0=pat.qd.lanes.lane2) and
(pat.qd.lanes.lane0=pat.qd.lanes.lane3) then
begin
index:=NewImm_i(dtUint32,pat.qd.lanes.lane0);
cm4:=FetchReg(FConsts.Fetch(dtUint32,4));
cm3:=FetchReg(FConsts.Fetch(dtUint32,3));
cm1:=FetchReg(FConsts.Fetch(dtUint32,1));
Op3(Op.OpGroupNonUniformQuadBroadcast,src.dtype,dst,NewImm_i(dtUint32,Scope.Subgroup),src,index);
end else
begin
lanes:=NewImm_i(dtUint32,Byte(pat.qd.lanes));
inv^.mark_read;
elm:=NewReg(dtUint32);
_emit_Op2(line,Op.OpUMod,elm,inv,cm4);
lane_id:=AddInput(@RegsStory.FUnattach,dtUint32,itSubgroupLocalInvocationId);
tmp:=NewReg(dtUint32);
elm^.mark_read;
_emit_OpShr(line,tmp,elm,cm1);
elm:=tmp;
tmp:=NewReg(dtUint32);
elm^.mark_read;
_emit_OpShr(line,tmp,ofs,elm);
elm:=tmp;
tmp:=NewReg(dtUint32);
elm^.mark_read;
_emit_Op2(line,Op.OpBitwiseAnd,tmp,elm,cm3);
lof:=tmp; //laneOffset
lob:=NewReg(dtUint32);
cm4^.mark_read;
_emit_Op2(line,Op.OpUDiv,lob,inv,cm4); //laneBase
lid:=NewReg(dtUint32);
lob^.mark_read;
lof^.mark_read;
_emit_OpIAdd(line,lid,lob,lof); //laneIndex
id_in_group:=OpAndTo(lane_id,3);
id_in_group.PrepType(ord(dtUint32));
base :=OpShlTo (id_in_group,1);
index:=OpBFUETo(lanes,base,NewImm_i(dtUint32,2));
Op3(Op.OpGroupNonUniformQuadBroadcast,src.dtype,dst,NewImm_i(dtUint32,Scope.Subgroup),src,index);
end;
end;
BitMode:
begin
Assert(false,'TODO');
Assert(false,'TODO: DS_SWIZZLE_B32: BitMode');
end;
end;
dst:=FRegsStory.get_vdst8(FSPI.DS.VDST);
SetConst(dst,dtFloat32,0);
}
end;
{
@ -501,12 +481,7 @@ begin
DS_OR_RTN_B32 :emit_DS_ATOMIC_OP(dtUint32,Op.OpAtomicOr ,True);
DS_XOR_RTN_B32:emit_DS_ATOMIC_OP(dtUint32,Op.OpAtomicXor,True);
//DS_SWIZZLE_B32 v4 v3 v0 v0 OFFSET:0x80AA GDS:0
//DS_SWIZZLE_B32: //TODO
// begin;
// _emit_DS_SWIZZLE_B32;
// end;
DS_SWIZZLE_B32:emit_DS_SWIZZLE_B32;
else
Assert(false,'DS?'+IntToStr(FSPI.DS.OP)+' '+get_str_spi(FSPI));

View File

@ -177,7 +177,7 @@ begin
begin
case dst_sel[i] of
0:dst[i]:=NewReg_i(rtype.Child,0);
0:dst[i]:=NewImm_i(rtype.Child,0);
//1?
4:dst[i]:=src[0];
@ -222,7 +222,7 @@ begin
parent:=AllocBlockOp;
parent.SetInfo(btOther,Cursor.Adr,Cursor.Adr);
PushBlockOp(line,parent,nil);
PushBlockOp(line,parent);
Inc(push_count);
exc:=MakeRead(get_exec0,dtBool); //It means that lane_id=0
@ -248,7 +248,7 @@ begin
pOpBlock:=AllocBlockOp; //down
pOpBlock.SetInfo(btOther,Cursor.Adr,Cursor.Adr);
PushBlockOp(line,pOpBlock,nil);
PushBlockOp(line,pOpBlock);
Inc(push_count);
if (parent<>nil) then

View File

@ -280,7 +280,7 @@ begin
if is_const_ssrc8(SOFFSET) then
begin
pConst:=ConstList.Fetch_ssrc8_const(SOFFSET,0,rtype);
Result:=NewReg(pConst);
Result:=NewImm(pConst);
end else
begin
src:=RegsStory.get_ssrc8(SOFFSET);
@ -297,7 +297,7 @@ begin
if is_const_ssrc9(SSRC) then
begin
pConst:=ConstList.Fetch_ssrc9_const(SSRC,FSPI.INLINE32,rtype);
Result:=NewReg(pConst);
Result:=NewImm(pConst);
end else
begin
src:=RegsStory.get_ssrc9(SSRC);
@ -312,8 +312,8 @@ Var
begin
if is_const_ssrc9(SSRC) then
begin
src[0]:=NewReg(ConstList.Fetch_ssrc9_const(SSRC,FSPI.INLINE32,rtype));
src[1]:=NewReg(ConstList.Fetch(rtype,0));
src[0]:=NewImm(ConstList.Fetch_ssrc9_const(SSRC,FSPI.INLINE32,rtype));
src[1]:=NewImm(ConstList.Fetch(rtype,0));
Result:=True;
end else
begin
@ -385,8 +385,8 @@ var
begin
dst:=BitcastList.FetchRead(dtVec2u,src);
node[0]:=dst0^.New(line,dtUint32);
node[1]:=dst1^.New(line,dtUint32);
node[0]:=dst0^.New(dtUint32,line);
node[1]:=dst1^.New(dtUint32,line);
OpExtract(line,node[0],dst,0);
OpExtract(line,node[1],dst,1);
@ -419,7 +419,7 @@ begin
rsl[0]:=OpFToF(src0,dtHalf16);
rsl[1]:=OpFToF(src1,dtHalf16);
dst^.New(line,dtVec2h);
dst^.New(dtVec2h);
OpMakeCon(line,dst^.current,@rsl);
end;
@ -439,7 +439,7 @@ begin
if (r=nil) then
begin
r:=dst^.New(line,rtype);
r:=dst^.New(rtype);
i.pReg :=r;
OpLoad(init_line,r,v); //one in any scope
end else
@ -473,7 +473,7 @@ function TEmitFetch.AddAncillary(dst:PsrRegSlot):TsrRegNode;
var
src:array[0..2] of TsrRegNode;
begin
src[0]:=NewReg_q(dtUInt32,0); //vPrimType
src[0]:=NewImm_q(dtUInt32,0); //vPrimType
src[1]:=AddInput(@RegsStory.FUnattach,dtUInt32,itSampleId);
src[2]:=AddInput(@RegsStory.FUnattach,dtUInt32,itLayer);
@ -582,10 +582,10 @@ begin
pChain.AddLine(pLine); //<-back link
//scope
pLine.AddParam(NewReg_i(dtInt32,iScope));
pLine.AddParam(NewImm_i(dtInt32,iScope));
//MemorySemantics
pLine.AddParam(NewReg_i(dtInt32,iMemorySemantics));
pLine.AddParam(NewImm_i(dtInt32,iMemorySemantics));
//val
pLine.AddParam(src);
@ -632,7 +632,7 @@ var
rsl:TsrRegNode;
begin
rsl:=AddInput(@RegsStory.FUnattach,vtype,itype,0);
OpExtract(init_line,dst^.New(line,rtype),rsl,id);
OpExtract(init_line,dst^.New(rtype),rsl,id);
end;
function TEmitFetch.AddPositionsInput(count:Byte):TsrVariable;

View File

@ -594,7 +594,7 @@ begin
begin
if (i<max) then
begin
OpExtract(line,pSlot^.New(line,dtype),dst,i);
OpExtract(line,pSlot^.New(dtype),dst,i);
end else
begin
SetConst_i(pSlot,dtype,0);
@ -621,7 +621,7 @@ begin
Inc(d);
end else
begin
src[i]:=NewReg_i(info^.dtype,0);
src[i]:=NewImm_i(info^.dtype,0);
end;
end;
@ -663,7 +663,7 @@ begin
if (info^.tinfo.Arrayed<>0) then //is array
begin
Inc(count);
src[3]:=NewReg_s(dtFloat32,0);
src[3]:=NewImm_s(dtFloat32,0);
end;
end;
@ -683,7 +683,7 @@ begin
i:=count;
Inc(count);
src[i]:=NewReg_s(dtFloat32,0);
src[i]:=NewImm_s(dtFloat32,0);
end;
if (count=1) then
@ -728,7 +728,7 @@ begin
if (info^.tinfo.Arrayed<>0) then //is array
begin
Inc(count);
src[3]:=NewReg_i(dtInt32,0);
src[3]:=NewImm_i(dtInt32,0);
end;
end;
@ -748,7 +748,7 @@ begin
i:=count;
Inc(count);
src[i]:=NewReg_i(dtInt32,0);
src[i]:=NewImm_i(dtInt32,0);
end;
if (count=1) then
@ -828,7 +828,7 @@ begin
end else
if (imZeroLod in p.mods) then
begin
p.lod:=NewReg_s(dtFloat32,0);
p.lod:=NewImm_s(dtFloat32,0);
p.img_op:=p.img_op or ImageOperands.Lod;
end;

View File

@ -54,7 +54,7 @@ procedure TEmit_MUBUF.make_load_comp(dst:PsrRegSlot;dtype:TsrDataType;rsl:TsrReg
begin
if rsl.dtype.isVector then
begin
dst^.New(line,dtype);
dst^.New(dtype);
OpExtract(line,dst^.current,rsl,i);
end else
begin

View File

@ -88,7 +88,8 @@ type
procedure OpBFE_32(dst:PsrRegSlot;base,src0,src1:TsrRegNode);
procedure OpBFIB32(dst:PsrRegSlot;bitmsk,src0,src1:TsrRegNode);
//
function OpBFITo(src0,src1,src2,src3:TsrRegNode;ppLine:PPspirvOp=nil):TsrRegNode;
function OpBFITo (src0,src1,src2,src3:TsrRegNode;ppLine:PPspirvOp=nil):TsrRegNode;
function OpBFUETo(src0,src1,src2:TsrRegNode;ppLine:PPspirvOp=nil):TsrRegNode;
//
procedure OpPackAnc(dst:PsrRegSlot;prim,smid,rtid:TsrRegNode);
//
@ -294,37 +295,37 @@ end;
function TEmitOp.Op1(OpId:DWORD;rtype:TsrDataType;dst:PsrRegSlot;src:TsrRegNode):TspirvOp;
begin
Result:=_Op1(line,OpId,dst^.New(line,rtype),src);
Result:=_Op1(line,OpId,dst^.New(rtype),src);
end;
function TEmitOp.Op2(OpId:DWORD;rtype:TsrDataType;dst:PsrRegSlot;src0,src1:TsrRegNode):TspirvOp;
begin
Result:=_Op2(line,OpId,dst^.New(line,rtype),src0,src1);
Result:=_Op2(line,OpId,dst^.New(rtype),src0,src1);
end;
function TEmitOp.Op3(OpId:DWORD;rtype:TsrDataType;dst:PsrRegSlot;src0,src1,src2:TsrRegNode):TspirvOp;
begin
Result:=_Op3(line,OpId,dst^.New(line,rtype),src0,src1,src2);
Result:=_Op3(line,OpId,dst^.New(rtype),src0,src1,src2);
end;
function TEmitOp.Op4(OpId:DWORD;rtype:TsrDataType;dst:PsrRegSlot;src0,src1,src2,src3:TsrRegNode):TspirvOp;
begin
Result:=_Op4(line,OpId,dst^.New(line,rtype),src0,src1,src2,src3);
Result:=_Op4(line,OpId,dst^.New(rtype),src0,src1,src2,src3);
end;
function TEmitOp.OpGlsl1(OpId:DWORD;rtype:TsrDataType;dst:PsrRegSlot;src:TsrRegNode):TspirvOp;
begin
Result:=_OpGlsl1(line,OpId,dst^.New(line,rtype),src);
Result:=_OpGlsl1(line,OpId,dst^.New(rtype),src);
end;
function TEmitOp.OpGlsl2(OpId:DWORD;rtype:TsrDataType;dst:PsrRegSlot;src0,src1:TsrRegNode):TspirvOp;
begin
Result:=_OpGlsl2(line,OpId,dst^.New(line,rtype),src0,src1)
Result:=_OpGlsl2(line,OpId,dst^.New(rtype),src0,src1)
end;
function TEmitOp.OpGlsl3(OpId:DWORD;rtype:TsrDataType;dst:PsrRegSlot;src0,src1,src2:TsrRegNode):TspirvOp;
begin
Result:=_OpGlsl3(line,OpId,dst^.New(line,rtype),src0,src1,src2);
Result:=_OpGlsl3(line,OpId,dst^.New(rtype),src0,src1,src2);
end;
function TEmitOp.OpBitcast(pLine:TspirvOp;dst,src:TsrRegNode):TspirvOp;
@ -347,8 +348,8 @@ function TEmitOp.OpBoolToInt(pLine:TspirvOp;dst,src:TsrRegNode):TspirvOp;
Var
src0,src1:TsrRegNode;
begin
src0:=NewReg_q(dst.dtype,0,@pLine);
src1:=NewReg_q(dst.dtype,1,@pLine);
src0:=NewImm_q(dst.dtype,0,pLine);
src1:=NewImm_q(dst.dtype,1,pLine);
Result:=_Op3(pLine,Op.OpSelect,dst,src,src1,src0);
end;
@ -357,7 +358,7 @@ function TEmitOp.OpIntToBool(pLine:TspirvOp;dst,src:TsrRegNode):TspirvOp;
Var
src0:TsrRegNode;
begin
src0:=NewReg_q(src.dtype,0,@pLine);
src0:=NewImm_q(src.dtype,0,pLine);
Result:=_Op2(pLine,Op.OpINotEqual,dst,src,src0);
end;
@ -378,8 +379,8 @@ begin
rsrc :=src.specialize AsType<ntReg>;
Assert(pLine<>nil);
Assert(dst<>nil);
Assert(src<>nil);
Assert(rdst<>nil);
Assert(rsrc<>nil);
if (rsrc.dtype=dtBool) then
begin
@ -613,7 +614,7 @@ var
begin
//vdst = vsrc0.i * vsrc1.i + vdst.i
mul:=NewReg(dtInt32);
sum:=dst^.New(line,dtInt32);
sum:=dst^.New(dtInt32);
_Op2(line,Op.OpIMul,mul,src0,src1);
_Op2(line,Op.OpIAdd,sum,mul,src2);
@ -625,7 +626,7 @@ var
begin
//vdst = vsrc0.u * vsrc1.u + vdst.u
mul:=NewReg(dtUInt32);
sum:=dst^.New(line,dtUInt32);
sum:=dst^.New(dtUInt32);
_Op2(line,Op.OpIMul,mul,src0,src1);
_Op2(line,Op.OpIAdd,sum,mul,src2);
@ -686,8 +687,8 @@ begin
rsl.pWriter:=node;
node.pDst:=rsl;
rsl.pDst0:=dst^.New(line,rtype); //dtUint32,dtUint64
rsl.pDst1:=car^.New(line,rtype); //dtUint32,dtUint64
rsl.pDst0:=dst^.New(rtype); //dtUint32,dtUint64
rsl.pDst1:=car^.New(rtype); //dtUint32,dtUint64
end;
procedure TEmitOp.OpIAddExt(dst,car,src0,src1:TsrRegNode);
@ -750,8 +751,8 @@ begin
rsl.pWriter:=node;
node.pDst:=rsl;
rsl.pDst0:=dst^.New(line,rtype); //dtUint32,dtUint64
rsl.pDst1:=bor^.New(line,rtype); //dtUint32,dtUint64
rsl.pDst0:=dst^.New(rtype); //dtUint32,dtUint64
rsl.pDst1:=bor^.New(rtype); //dtUint32,dtUint64
end;
//
@ -782,6 +783,12 @@ begin
_set_line(ppLine,_Op4(_get_line(ppLine),Op.OpBitFieldInsert,Result,src0,src1,src2,src3));
end;
function TEmitOp.OpBFUETo(src0,src1,src2:TsrRegNode;ppLine:PPspirvOp=nil):TsrRegNode;
begin
Result:=NewReg(src0.dtype);
_set_line(ppLine,_Op3(_get_line(ppLine),Op.OpBitFieldUExtract,Result,src0,src1,src2));
end;
//
procedure TEmitOp.OpPackAnc(dst:PsrRegSlot;prim,smid,rtid:TsrRegNode);
@ -1132,7 +1139,7 @@ end;
function TEmitOp.OpShlTo(src0:TsrRegNode;src1:QWORD;ppLine:PPspirvOp=nil):TsrRegNode;
begin
if (src0=nil) or (src1=0) then Exit(src0);
Result:=OpShlTo(src0,NewReg_q(src0.dtype,src1,ppLine),ppLine);
Result:=OpShlTo(src0,NewImm_q(src0.dtype,src1,_get_line(ppLine)),ppLine);
end;
function TEmitOp.OpShrTo(src0,src1:TsrRegNode;ppLine:PPspirvOp=nil):TsrRegNode;
@ -1152,7 +1159,7 @@ end;
function TEmitOp.OpShrTo(src0:TsrRegNode;src1:QWORD;ppLine:PPspirvOp=nil):TsrRegNode;
begin
if (src0=nil) or (src1=0) then Exit(src0);
Result:=OpShrTo(src0,NewReg_q(src0.dtype,src1,ppLine),ppLine);
Result:=OpShrTo(src0,NewImm_q(src0.dtype,src1,_get_line(ppLine)),ppLine);
end;
//
@ -1170,7 +1177,7 @@ end;
function TEmitOp.OpIAddTo(src0:TsrRegNode;src1:QWORD;ppLine:PPspirvOp=nil):TsrRegNode;
begin
if (src0=nil) or (src1=0) then Exit(src0);
Result:=OpIAddTo(src0,NewReg_q(src0.dtype,src1,ppLine),ppLine);
Result:=OpIAddTo(src0,NewImm_q(src0.dtype,src1,_get_line(ppLine)),ppLine);
end;
function TEmitOp.OpISubTo(src0,src1:TsrRegNode;ppLine:PPspirvOp=nil):TsrRegNode;
@ -1186,7 +1193,7 @@ end;
function TEmitOp.OpISubTo(src0:TsrRegNode;src1:QWORD;ppLine:PPspirvOp=nil):TsrRegNode;
begin
if (src0=nil) or (src1=0) then Exit(src0);
Result:=OpISubTo(src0,NewReg_q(src0.dtype,src1,ppLine),ppLine);
Result:=OpISubTo(src0,NewImm_q(src0.dtype,src1,_get_line(ppLine)),ppLine);
end;
function TEmitOp.OpIMulTo(src0,src1:TsrRegNode;ppLine:PPspirvOp=nil):TsrRegNode;
@ -1209,7 +1216,7 @@ begin
Result:=OpShlTo (src0,src1,ppLine);
end else
begin
Result:=OpIMulTo(src0,NewReg_q(src0.dtype,src1,ppLine),ppLine);
Result:=OpIMulTo(src0,NewImm_q(src0.dtype,src1,_get_line(ppLine)),ppLine);
end;
end;
@ -1237,7 +1244,7 @@ begin
Result:=OpShrTo (src0,src1,ppLine);
end else
begin
Result:=OpIDivTo(src0,NewReg_q(src0.dtype,src1,ppLine),ppLine);
Result:=OpIDivTo(src0,NewImm_q(src0.dtype,src1,_get_line(ppLine)),ppLine);
end;
end;
@ -1297,13 +1304,13 @@ end;
function TEmitOp.OpFAddToS(src0:TsrRegNode;src1:Single;ppLine:PPspirvOp=nil):TsrRegNode;
begin
if (src0=nil) or (src1=0) then Exit(src0);
Result:=OpFAddTo(src0,NewReg_s(src0.dtype,src1,ppLine),ppLine);
Result:=OpFAddTo(src0,NewImm_s(src0.dtype,src1,_get_line(ppLine)),ppLine);
end;
function TEmitOp.OpFMulToS(src0:TsrRegNode;src1:Single;ppLine:PPspirvOp=nil):TsrRegNode;
begin
if (src0=nil) or (src1=0) or (src1=1) then Exit(src0);
Result:=OpFMulTo(src0,NewReg_s(src0.dtype,src1,ppLine),ppLine);
Result:=OpFMulTo(src0,NewImm_s(src0.dtype,src1,_get_line(ppLine)),ppLine);
end;
//
@ -1440,7 +1447,7 @@ end;
function TEmitOp.OpAndTo(src0:TsrRegNode;src1:QWORD;ppLine:PPspirvOp=nil):TsrRegNode;
begin
if (src0=nil) then Exit(src0);
Result:=OpAndTo(src0,NewReg_q(src0.dtype,src1,ppLine),ppLine);
Result:=OpAndTo(src0,NewImm_q(src0.dtype,src1,_get_line(ppLine)),ppLine);
end;
//
@ -1450,7 +1457,7 @@ var
zero:TsrRegNode;
begin
Result:=NewReg(dtBool);
zero :=NewReg_i(src.dtype,0,ppLine);
zero :=NewImm_i(src.dtype,0,_get_line(ppLine));
_set_line(ppLine,_Op2(_get_line(ppLine),Op.OpSLessThan,Result,src,zero)); //(x<0)
end;
@ -1562,7 +1569,7 @@ begin
Assert(False,'unknow id');
end;
comp:=NewReg_i(dtUint32,id);
comp:=NewImm_i(dtUint32,id);
node:=AddSpirvOp(pLine,Op.OpImageGather); //need first

View File

@ -218,7 +218,7 @@ begin
Invert:=Invert xor pCond.Cond.FNormalOrder;
node:=NewReg_q(old.dtype,ord(Invert),@pLine);
node:=NewImm_q(old.dtype,ord(Invert),pLine);
if (pIf<>nil) then
begin
@ -434,6 +434,7 @@ begin
end else
begin //bitcast
node:=BitcastList.FetchCast(old.dtype,node);
Inc(Result);
end;
end else
@ -676,6 +677,8 @@ begin
end;
function TSprvEmit_post.OnDecorate(node:TspirvOp):Integer;
var
r:TsrRegNode;
begin
Result:=0;
@ -695,6 +698,29 @@ begin
begin
AddCapability(Capability.ImageQuery);
end;
Op.OpGroupNonUniformQuadBroadcast:
begin
r:=node.ParamNode(2).Value;
r:=RegDown(r);
//
if r.is_const then
begin
//upgrade version to 1.3
if (Config.SpvVersion<$10300) then
begin
Config.SpvVersion:=$10300;
end;
end else
begin
//upgrade version to 1.5
if (Config.SpvVersion<$10500) then
begin
Config.SpvVersion:=$10500;
end;
end;
//
AddCapability(Capability.GroupNonUniformQuad);
end;
else;
end;
@ -874,7 +900,7 @@ begin
end else
begin
pLine :=init_line;
pIndex:=NewReg_q(dtUint32,_count,@pLine);
pIndex:=NewImm_q(dtUint32,_count,pLine);
end;
pChain.pIndex:=pIndex;
pChain.stride:=_stride;
@ -1225,7 +1251,7 @@ begin
Case Parent.Fdtype of
dtTypeStruct:
begin
pReg:=NewReg_i(dtUint32,pField.FID,@pLine);
pReg:=NewImm_i(dtUint32,pField.FID,pLine);
pLine.AddParamAfter(pParam,pReg);
end;
dtTypeArray,
@ -1233,7 +1259,7 @@ begin
begin
if not Parent.IsStructNotUsed then
begin
pReg:=NewReg_i(dtUint32,pField.FID,@pLine);
pReg:=NewImm_i(dtUint32,pField.FID,pLine);
pLine.AddParamAfter(pParam,pReg);
end;
Assert(pIndex<>nil);
@ -1242,7 +1268,7 @@ begin
else
if Parent.Fdtype.isVector then
begin
pReg:=NewReg_i(dtUint32,pField.FID,@pLine);
pReg:=NewImm_i(dtUint32,pField.FID,pLine);
pLine.AddParamAfter(pParam,pReg);
end;
end;

View File

@ -184,7 +184,7 @@ var
procedure _SetConst(dtype:TsrDataType;value:QWORD);
begin
dst.pWriter:=NewReg_q(dtype,value,@node);
dst.pWriter:=NewImm_q(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -334,7 +334,7 @@ var
procedure _SetConst(dtype:TsrDataType;value:QWORD);
begin
dst.pWriter:=NewReg_q(dtype,value,@node);
dst.pWriter:=NewImm_q(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -470,7 +470,7 @@ var
procedure _SetConst(dtype:TsrDataType;value:QWORD);
begin
dst.pWriter:=NewReg_q(dtype,value,@node);
dst.pWriter:=NewImm_q(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -571,7 +571,7 @@ begin
data[1]:=src[1].AsConst.GetData;
dtype:=LazyType3(dst.dtype,src[0].dtype,src[1].dtype);
src[1]:=NewReg_q(dtype,data[0] or data[1],@Node);
src[1]:=NewImm_q(dtype,data[0] or data[1],node);
src[0]:=_Fetch_BitwiseOr_Value(src[0]);
Assert(src[0]<>nil);
@ -589,7 +589,7 @@ begin
data[1]:= pConst.GetData;
dtype:=LazyType3(dst.dtype,src[0].dtype,src[1].dtype);
src[0]:=NewReg_q(dtype,data[0] or data[1],@Node);
src[0]:=NewImm_q(dtype,data[0] or data[1],node);
src[1]:=_Fetch_BitwiseOr_Value(src[1]);
Assert(src[1]<>nil);
@ -634,7 +634,7 @@ var
procedure _SetConst(dtype:TsrDataType;value:QWORD);
begin
dst.pWriter:=NewReg_q(dtype,value,@node);
dst.pWriter:=NewImm_q(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -698,7 +698,7 @@ var
procedure _SetConst(dtype:TsrDataType;value:QWORD);
begin
dst.pWriter:=NewReg_q(dtype,value,@node);
dst.pWriter:=NewImm_q(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -980,7 +980,7 @@ var
procedure _SetConst(dtype:TsrDataType;value:QWORD);
begin
dst.pWriter:=NewReg_q(dtype,value,@node);
dst.pWriter:=NewImm_q(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -1027,7 +1027,7 @@ var
procedure _SetConst(dtype:TsrDataType;value:QWORD);
begin
dst.pWriter:=NewReg_q(dtype,value,@node);
dst.pWriter:=NewImm_q(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -1064,7 +1064,7 @@ var
procedure _SetConst(dtype:TsrDataType;value:QWORD);
begin
dst.pWriter:=NewReg_q(dtype,value,@node);
dst.pWriter:=NewImm_q(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -1073,7 +1073,7 @@ var
procedure _SetConst_s(dtype:TsrDataType;value:Single);
begin
Assert(dtype=dtFloat32);
dst.pWriter:=NewReg_s(dtype,value,@node);
dst.pWriter:=NewImm_s(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -1283,7 +1283,7 @@ var
procedure _SetConst(dtype:TsrDataType;value:QWORD);
begin
dst.pWriter:=NewReg_q(dtype,value,@node);
dst.pWriter:=NewImm_q(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -1370,7 +1370,7 @@ var
procedure _SetConst_s(dtype:TsrDataType;value:Single);
begin
Assert(dtype=dtFloat32);
dst.pWriter:=NewReg_s(dtype,value,@node);
dst.pWriter:=NewImm_s(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -1411,7 +1411,7 @@ var
procedure _SetConst(dtype:TsrDataType;value:QWORD);
begin
dst.pWriter:=NewReg_q(dtype,value,@node);
dst.pWriter:=NewImm_q(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -1465,7 +1465,7 @@ var
procedure _SetConst(dtype:TsrDataType;value:QWORD);
begin
dst.pWriter:=NewReg_q(dtype,value,@node);
dst.pWriter:=NewImm_q(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -1497,7 +1497,7 @@ var
procedure _SetConst(dtype:TsrDataType;value:QWORD);
begin
dst.pWriter:=NewReg_q(dtype,value,@node);
dst.pWriter:=NewImm_q(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -1573,7 +1573,7 @@ var
procedure _SetConst(dtype:TsrDataType;value:QWORD);
begin
dst.pWriter:=NewReg_q(dtype,value,@node);
dst.pWriter:=NewImm_q(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -1773,7 +1773,7 @@ var
procedure _SetConst(dtype:TsrDataType;value:QWORD);
begin
dst.pWriter:=NewReg_q(dtype,value,@node);
dst.pWriter:=NewImm_q(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -1862,7 +1862,7 @@ var
procedure _SetConst(dtype:TsrDataType;value:QWORD);
begin
dst.pWriter:=NewReg_q(dtype,value,@node);
dst.pWriter:=NewImm_q(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -2018,7 +2018,7 @@ begin
if (count=0) then
begin
Result:=NewReg_q(node.dtype,0);
Result:=NewImm_q(node.dtype,0,node);
end else
if (count=1) then
begin
@ -2040,6 +2040,7 @@ end;
function TEmitPostOp.OnBFE_32_1(node:TSpirvOp):Integer;
var
pLine:TSpirvOp;
dst:TsrRegNode;
rBase,rIndex,rCount:TsrRegNode;
rsl:TsrRegNode;
@ -2061,8 +2062,8 @@ begin
dtype:=rBase.dtype;
//else
node.mark_not_used;
node.pDst:=nil;
pLine:=node;
if (rIndex.is_const) and (rCount.is_const) then
begin
@ -2077,6 +2078,8 @@ begin
if (rsl<>nil) then
begin
pLine:=rsl.pLine;
rBase:=RegDown(rsl);
if (rBase.is_const) then
begin
@ -2086,22 +2089,24 @@ begin
//
if (data[0]<>rBase.AsConst.GetData) then
begin
rsl:=NewReg_q(dtUInt32,data[0],@Node);
rsl:=NewImm_q(dtUInt32,data[0],pLine);
end;
end else
begin
data[1]:=(1 shl count)-1;
num_31:=NewReg_q(dtUInt32,data[1],@Node);
num_31:=NewImm_q(dtUInt32,data[1],pLine);
//
PrepTypeNode(rsl,dtype);
rsl:=OpAndTo(rsl,num_31,@node);
rsl:=OpAndTo(rsl,num_31,@pLine);
rsl.PrepType(ord(dtype));
end;
dst.pWriter:=rsl;
dst.pLine :=rsl.pLine;
node.mark_not_used;
node.pDst:=nil;
Exit;
end;
@ -2118,20 +2123,20 @@ begin
//
if (data[0]<>rIndex.AsConst.GetData) then
begin
rIndex:=NewReg_q(dtUInt32,data[0],@Node);
rIndex:=NewImm_q(dtUInt32,data[0],pLine);
end else
begin
rIndex:=node.ParamNode(1).AsReg; //orig
end;
end else
begin
num_31:=NewReg_q(dtUInt32,31,@Node);
num_31:=NewImm_q(dtUInt32,31,pLine);
//
rIndex:=node.ParamNode(1).AsReg; //orig
PrepTypeNode(rIndex,dtUInt32);
rIndex:=OpAndTo(rIndex,num_31,@node);
rIndex:=OpAndTo(rIndex,num_31,@pLine);
end;
//
@ -2142,7 +2147,7 @@ begin
//
if (data[1]<>rCount.AsConst.GetData) then
begin
rCount:=NewReg_q(dtUInt32,data[1],@Node);
rCount:=NewImm_q(dtUInt32,data[1],pLine);
end else
begin
rCount:=node.ParamNode(2).AsReg; //orig
@ -2151,30 +2156,33 @@ begin
begin
if (num_31<>nil) then
begin
num_31:=NewReg_q(dtUInt32,31,@Node);
num_31:=NewImm_q(dtUInt32,31,pLine);
end;
//
rCount:=node.ParamNode(2).AsReg; //orig
PrepTypeNode(rCount,dtUInt32);
rCount:=OpAndTo(rCount,num_31,@node);
rCount:=OpAndTo(rCount,num_31,@pLine);
end;
PrepTypeNode(rIndex,dtUInt32);
PrepTypeNode(rCount,dtUInt32);
case dtype of
dtUint32:_Op3(node,Op.OpBitFieldUExtract,dst,rBase,rIndex,rCount);
dtInt32 :_Op3(node,Op.OpBitFieldSExtract,dst,rBase,rIndex,rCount);
dtUint32:_Op3(pLine,Op.OpBitFieldUExtract,dst,rBase,rIndex,rCount);
dtInt32 :_Op3(pLine,Op.OpBitFieldSExtract,dst,rBase,rIndex,rCount);
else
Assert(False);
end;
node.mark_not_used;
node.pDst:=nil;
end;
function TEmitPostOp.OnBFIB32_1(node:TSpirvOp):Integer;
var
pLine:TSpirvOp;
dst:TsrRegNode;
bitmsk:TsrRegNode;
src:array[0..1] of TsrRegNode;
@ -2186,9 +2194,12 @@ begin
dst:=node.pDst.specialize AsType<ntReg>;
if (dst=nil) then Exit;
pLine:=node;
bitmsk:=RegDown(node.ParamNode(0).AsReg);
src[0]:=RegDown(node.ParamNode(1).AsReg);
src[1]:=RegDown(node.ParamNode(2).AsReg);
src[0]:=node.ParamNode(1).AsReg;
src[1]:=node.ParamNode(2).AsReg;
if (bitmsk=nil) or (src[0]=nil) or (src[1]=nil) then Exit;
@ -2203,39 +2214,34 @@ begin
if (data[0]=data[1]) then
begin
rIndex:=NewImm_q(dtUint32,index,pLine);
rCount:=NewImm_q(dtUint32,count,pLine);
_Op4(pLine,Op.OpBitFieldInsert,dst,src[1],src[0],rIndex,rCount);
node.mark_not_used;
node.pDst:=nil;
rIndex:=NewReg_q(dtUint32,index,@Node);
rCount:=NewReg_q(dtUint32,count,@Node);
src[0]:=node.ParamNode(1).AsReg;
src[1]:=node.ParamNode(2).AsReg;
_Op4(node,Op.OpBitFieldInsert,dst,src[1],src[0],rIndex,rCount);
Exit;
end;
end;
//else
node.mark_not_used;
node.pDst:=nil;
src[0]:=node.ParamNode(1).AsReg;
src[1]:=node.ParamNode(2).AsReg;
src[0]:=OpAndTo(src[0],bitmsk,@node);
src[0]:=OpAndTo(src[0],bitmsk,@pLine);
src[0].PrepType(ord(dtUInt32));
bitmsk:=OpNotTo(bitmsk,@node);
bitmsk:=OpNotTo(bitmsk,@pLine);
bitmsk.PrepType(ord(dtUInt32));
src[1]:=OpAndTo(src[1],bitmsk,@node);
src[1]:=OpAndTo(src[1],bitmsk,@pLine);
src[1].PrepType(ord(dtUInt32));
_Op2(node,Op.OpBitwiseOr,dst,src[0],src[1]);
_Op2(pLine,Op.OpBitwiseOr,dst,src[0],src[1]);
node.mark_not_used;
node.pDst:=nil;
end;
function _IsFma(node:TSpirvOp):Boolean;
@ -2580,7 +2586,7 @@ var
procedure _SetConst_s(dtype:TsrDataType;value:Single);
begin
Assert(dtype=dtFloat32);
dst.pWriter:=NewReg_s(dtype,value,@node);
dst.pWriter:=NewImm_s(dtype,value,node);
node.mark_not_used;
node.pDst:=nil;
Inc(Result);
@ -2918,26 +2924,25 @@ begin
dst:=node.pDst.specialize AsType<ntReg>;
if (dst=nil) then Exit;
src[0]:=node.ParamNode(0).AsReg;
src[1]:=node.ParamNode(1).AsReg;
src[2]:=node.ParamNode(2).AsReg;
src[0]:=node.ParamNode(0).AsReg; //prim
src[1]:=node.ParamNode(1).AsReg; //smid
src[2]:=node.ParamNode(2).AsReg; //rtid
if (src[0]=nil) or (src[0]=nil) or (src[1]=nil) then Exit;
node.mark_not_used;
node.pDst:=nil;
num4 :=NewReg_q(dtUint32, 4);
num8 :=NewReg_q(dtUint32, 8);
num11:=NewReg_q(dtUint32,11);
num16:=NewReg_q(dtUint32,16);
num4 :=NewImm_q(dtUint32, 4,node);
num8 :=NewImm_q(dtUint32, 8,node);
num11:=NewImm_q(dtUint32,11,node);
num16:=NewImm_q(dtUint32,16,node);
//Base,Insert,Offset,Count
src[0]:=OpBFITo(src[0],src[1],num8 ,num4 ,@node);
src[0]:=OpBFITo(src[0],src[2],num16,num11,@node);
dst.pWriter:=src[0];
dst.pLine :=src[0].pLine;
end;
//

View File

@ -474,7 +474,7 @@ begin
src[0].PrepType(ord(dtUInt32));
src[1].PrepType(ord(dtUInt32));
one:=NewReg_q(dtUInt32,1);
one:=NewImm_q(dtUInt32,1);
src[0]:=OpShrTo(one,src[0]); //(1 << src0)
src[0]:=OpISubTo(src[0],1); //-1

View File

@ -51,7 +51,7 @@ begin
i:=SignExtend16(FSPI.SOPK.SIMM);
src:=fetch_ssrc8(FSPI.SOPK.SDST,dtInt32);
imm:=NewReg_i(dtInt32,i);
imm:=NewImm_i(dtInt32,i);
//Force type
src:=BitcastList.FetchRead(dtInt32,src);
@ -88,7 +88,7 @@ begin
i:=SignExtend16(FSPI.SOPK.SIMM);
src:=fetch_ssrc8(FSPI.SOPK.SDST,dtInt32);
imm:=NewReg_i(dtInt32,i);
imm:=NewImm_i(dtInt32,i);
//Force type
src:=BitcastList.FetchRead(dtInt32,src);
@ -105,7 +105,7 @@ begin
dst:=get_scc;
src:=fetch_ssrc8(FSPI.SOPK.SDST,dtInt32);
imm:=NewReg_i(dtInt32,SignExtend16(FSPI.SOPK.SIMM));
imm:=NewImm_i(dtInt32,SignExtend16(FSPI.SOPK.SIMM));
OpCmpS(OpId,dst,src,imm);
end;
@ -119,7 +119,7 @@ begin
dst:=get_scc;
src:=fetch_ssrc8(FSPI.SOPK.SDST,dtUint32);
imm:=NewReg_i(dtUint32,FSPI.SOPK.SIMM);
imm:=NewImm_i(dtUint32,FSPI.SOPK.SIMM);
OpCmpS(OpId,dst,src,imm);
end;

View File

@ -208,7 +208,7 @@ begin
//down group
pOpChild:=AllocBlockOp;
pOpChild.SetInfo(Info);
PushBlockOp(line,pOpChild,nil);
PushBlockOp(line,pOpChild);
set_code_ptr(adr.get_code_ptr,btInline);
end;

View File

@ -159,7 +159,7 @@ begin
if (adr.idx=nil) then
begin
sum_d:=NewReg_q(dtUint32,foffset);
sum_d:=NewImm_q(dtUint32,foffset);
end else
begin
idx_m:=OpIMulTo(adr.idx,adr.stride div adr.align); //idx*(stride/Align)
@ -183,7 +183,7 @@ begin
if (adr.idx=nil) then
begin
sum_d:=NewReg_q(dtUint32,foffset);
sum_d:=NewImm_q(dtUint32,foffset);
end else
begin
idx_m:=OpIMulTo(adr.idx,adr.stride div adr.fsize); //idx*(stride/size)

View File

@ -211,7 +211,7 @@ begin
if (lc.elm[i]=nil) then
begin
lc.dst^.New(line,lc.elem_resl);
lc.dst^.New(lc.elem_resl);
OpExtract(line,lc.dst^.current,rsl,i);
lc.elm[i]:=lc.dst^.current;
@ -238,7 +238,7 @@ begin
sum_d:=OpIAddTo(idx,i);
end;
rsl:=lc.dst^.New(line,lc.elem_resl);
rsl:=lc.dst^.New(lc.elem_resl);
OpImageRead(line,TsrNode(lc.v.data[0]),rsl,sum_d);

View File

@ -65,17 +65,17 @@ end;
function TEmit_vbuf_store.fetch_zero(var lc:Tstore_cache):TsrRegNode;
begin
Result:=NewReg_q(lc.elem_resl,0);
Result:=NewImm_q(lc.elem_resl,0);
end;
function TEmit_vbuf_store.fetch_one(var lc:Tstore_cache):TsrRegNode;
begin
if (lc.elem_resl=dtFloat32) then
begin
Result:=NewReg_s(lc.elem_resl,1);
Result:=NewImm_s(lc.elem_resl,1);
end else
begin
Result:=NewReg_i(lc.elem_resl,1);
Result:=NewImm_i(lc.elem_resl,1);
end;
end;

View File

@ -50,7 +50,7 @@ var
if InputCntl^.USE_DEFAULT then
begin
elm:=NewReg_s(dtFloat32,DEFAULT_VAL[InputCntl^.DEFAULT_VAL][FSPI.VINTRP.ATTRCHAN]);
elm:=NewImm_s(dtFloat32,DEFAULT_VAL[InputCntl^.DEFAULT_VAL][FSPI.VINTRP.ATTRCHAN]);
MakeCopy(dst,elm);
end else
@ -64,7 +64,7 @@ var
//remap id
rsl:=AddFragLayout(itype,dtVec4f,InputCntl^.OFFSET);
elm:=dst^.New(line,dtFloat32);
elm:=dst^.New(dtFloat32);
OpExtract(line,elm,rsl,FSPI.VINTRP.ATTRCHAN);
end;

View File

@ -81,11 +81,11 @@ begin
src[0]:=fetch_ssrc9(FSPI.VOP1.SRC0,dtFloat32);
src[0]:=OpFToF(src[0],dtHalf16);
src[1]:=NewReg_s(dtHalf16,0);
src[1]:=NewImm_s(dtHalf16,0);
dstv:=OpMakeVec(line,dtVec2h,@src);
dst^.New(line,dtVec2h).pWriter:=dstv;
dst^.New(dtVec2h).pWriter:=dstv;
end;
procedure TEmit_VOP1.emit_V_CVT_F32_F16; //vdst.f = ConvertHalfFloatToFloat(vsrc[15:0].hf)
@ -124,7 +124,7 @@ begin
src:=OpSToF(src,dtFloat32);
num_16:=NewReg_s(dtFloat32,16);
num_16:=NewImm_s(dtFloat32,16);
Op2(Op.OpFDiv,dtFloat32,dst,src,num_16);
end;
@ -235,7 +235,7 @@ begin
OpGlsl1(GlslOp.InverseSqrt,dtFloat32,dst,src);
src:=MakeRead(dst,dtFloat32);
flt:=NewReg_s(dtFloat32,FLT_MAX);
flt:=NewImm_s(dtFloat32,FLT_MAX);
OpGlsl2(GlslOp.NMin,dtFloat32,dst,src,flt);
end;
@ -275,7 +275,7 @@ begin
dst:=get_vdst8(FSPI.VOP1.VDST);
src:=fetch_ssrc9(FSPI.VOP1.SRC0,dtFloat32);
one:=NewReg_s(dtFloat32,1);
one:=NewImm_s(dtFloat32,1);
Op2(Op.OpFDiv,dtFloat32,dst,one,src);
end;

View File

@ -231,7 +231,7 @@ begin
src[0]:=fetch_ssrc9(FSPI.VOP2.SRC0 ,dtFloat32);
src[1]:=fetch_vsrc8(FSPI.VOP2.VSRC1,dtFloat32);
zero:=NewReg_s(dtFloat32,0);
zero:=NewImm_s(dtFloat32,0);
cmp:=get_legacy_cmp(src[0],src[1],zero);
//
@ -278,7 +278,7 @@ begin
src[0]:=fetch_ssrc9(FSPI.VOP2.SRC0 ,dtInt32);
src[1]:=fetch_vsrc8(FSPI.VOP2.VSRC1,dtInt32);
bit24:=NewReg_q(dtUInt32,$FFFFFF);
bit24:=NewImm_q(dtUInt32,$FFFFFF);
src[0]:=OpAndTo(src[0],bit24);
src[0].PrepType(ord(dtInt32));
@ -300,7 +300,7 @@ begin
src[0]:=fetch_ssrc9(FSPI.VOP2.SRC0 ,dtUInt32);
src[1]:=fetch_vsrc8(FSPI.VOP2.VSRC1,dtUInt32);
bit24:=NewReg_q(dtUInt32,$FFFFFF);
bit24:=NewImm_q(dtUInt32,$FFFFFF);
src[0]:=OpAndTo(src[0],bit24);
src[0].PrepType(ord(dtUInt32));
@ -339,7 +339,7 @@ begin
src[1]:=fetch_vsrc8(FSPI.VOP2.VSRC1,dtFloat32);
src[2]:=MakeRead(dst,dtFloat32);
zero:=NewReg_s(dtFloat32,0);
zero:=NewImm_s(dtFloat32,0);
cmp:=get_legacy_cmp(src[0],src[1],zero);
//
@ -360,7 +360,7 @@ begin
src[0]:=fetch_ssrc9(FSPI.VOP2.SRC0 ,dtFloat32);
src[1]:=fetch_vsrc8(FSPI.VOP2.VSRC1,dtFloat32);
src[2]:=NewReg_q(dtFloat32,FSPI.INLINE32);
src[2]:=NewImm_q(dtFloat32,FSPI.INLINE32);
OpFmaF32(dst,src[0],src[1],src[2]);
end;
@ -373,7 +373,7 @@ begin
dst:=get_vdst8(FSPI.VOP2.VDST);
src[0]:=fetch_ssrc9(FSPI.VOP2.SRC0 ,dtFloat32);
src[1]:=NewReg_q(dtFloat32,FSPI.INLINE32);
src[1]:=NewImm_q(dtFloat32,FSPI.INLINE32);
src[2]:=fetch_vsrc8(FSPI.VOP2.VSRC1,dtFloat32);
OpFmaF32(dst,src[0],src[1],src[2]);
@ -418,7 +418,7 @@ begin
src[0]:=fetch_ssrc9(FSPI.VOP2.SRC0 ,dtFloat32);
src[1]:=fetch_vsrc8(FSPI.VOP2.VSRC1,dtInt32);
two:=NewReg_s(dtFloat32,2);
two:=NewImm_s(dtFloat32,2);
src[1]:=OpSToF(src[1],dtFloat32);
src[1]:=OpPowTo(two,src[1]);

View File

@ -171,17 +171,17 @@ begin
0:;
1: // *2
begin
tmp:=NewReg_s(dtFloat32,2);
tmp:=NewImm_s(dtFloat32,2);
Op2(Op.OpFMul,dtFloat32,dst,src,tmp);
end;
2: // *4
begin
tmp:=NewReg_s(dtFloat32,4);
tmp:=NewImm_s(dtFloat32,4);
Op2(Op.OpFMul,dtFloat32,dst,src,tmp);
end;
3: // /2
begin
tmp:=NewReg_s(dtFloat32,2);
tmp:=NewImm_s(dtFloat32,2);
Op2(Op.OpFDiv,dtFloat32,dst,src,tmp);
end;
end;
@ -195,8 +195,8 @@ begin
if (FSPI.VOP3a.CLAMP=0) then Exit;
src:=dst^.current;
min:=NewReg_s(dtFloat32,0);
max:=NewReg_s(dtFloat32,1);
min:=NewImm_s(dtFloat32,0);
max:=NewImm_s(dtFloat32,1);
OpGlsl3(GlslOp.FClamp,dtFloat32,dst,src,min,max);
end;
@ -258,7 +258,7 @@ begin
emit_src_abs_bit(@src,2);
emit_src_neg_bit(@src,2);
zero:=NewReg_s(dtFloat32,0);
zero:=NewImm_s(dtFloat32,0);
cmp:=get_legacy_cmp(src[0],src[1],zero);
//
@ -423,7 +423,7 @@ begin
src[0]:=fetch_ssrc9(FSPI.VOP3a.SRC0,dtInt32);
src[1]:=fetch_ssrc9(FSPI.VOP3a.SRC1,dtInt32);
bit24:=NewReg_q(dtUInt32,$FFFFFF);
bit24:=NewImm_q(dtUInt32,$FFFFFF);
src[0]:=OpAndTo(src[0],bit24);
src[0].PrepType(ord(dtInt32));
@ -450,7 +450,7 @@ begin
src[0]:=fetch_ssrc9(FSPI.VOP3a.SRC0,dtUInt32);
src[1]:=fetch_ssrc9(FSPI.VOP3a.SRC1,dtUInt32);
bit24:=NewReg_q(dtUInt32,$FFFFFF);
bit24:=NewImm_q(dtUInt32,$FFFFFF);
src[0]:=OpAndTo(src[0],bit24);
src[0].PrepType(ord(dtUInt32));
@ -491,7 +491,7 @@ begin
_Op2(line,Op.OpSMulExtended,tmp_r,src[0],src[1]);
end;
dst_r:=dst^.New(line,rtype);
dst_r:=dst^.New(rtype);
OpExtract(line,dst_r,tmp_r,1);
end;
@ -530,7 +530,7 @@ begin
emit_src_abs_bit(@src,1);
emit_src_neg_bit(@src,1);
two:=NewReg_s(dtFloat32,2);
two:=NewImm_s(dtFloat32,2);
src[1]:=OpSToF(src[1],dtFloat32);
src[1]:=OpPowTo(two,src[1]);
@ -681,7 +681,7 @@ begin
src[1]:=fetch_ssrc9(FSPI.VOP3a.SRC1,dtFloat32);
src[2]:=fetch_ssrc9(FSPI.VOP3a.SRC2,dtFloat32);
zero:=NewReg_s(dtFloat32,0);
zero:=NewImm_s(dtFloat32,0);
cmp:=get_legacy_cmp(src[0],src[1],zero);
//
@ -717,7 +717,7 @@ begin
src[1]:=fetch_ssrc9(FSPI.VOP3a.SRC1,dtInt32);
src[2]:=fetch_ssrc9(FSPI.VOP3a.SRC2,dtInt32);
bit24:=NewReg_q(dtUInt32,$FFFFFF);
bit24:=NewImm_q(dtUInt32,$FFFFFF);
src[0]:=OpAndTo(src[0],bit24);
src[0].PrepType(ord(dtInt32));
@ -745,7 +745,7 @@ begin
src[1]:=fetch_ssrc9(FSPI.VOP3a.SRC1,dtUInt32);
src[2]:=fetch_ssrc9(FSPI.VOP3a.SRC2,dtUInt32);
bit24:=NewReg_q(dtUInt32,$FFFFFF);
bit24:=NewImm_q(dtUInt32,$FFFFFF);
src[0]:=OpAndTo(src[0],bit24);
src[0].PrepType(ord(dtUInt32));
@ -814,7 +814,7 @@ begin
rdif:=NewReg(dtUInt32);
OpAbsDiff(line,rdif,src[0],src[1]);
bit16:=NewReg_q(dtUInt32,$FFFF);
bit16:=NewImm_q(dtUInt32,$FFFF);
rvac:=OpAndTo(src[2],bit16);
rvac.PrepType(ord(dtUInt32));
@ -1065,7 +1065,7 @@ begin
emit_src_abs_bit(@src,1);
emit_src_neg_bit(@src,1);
one:=NewReg_s(dtFloat32,1);
one:=NewImm_s(dtFloat32,1);
Op2(Op.OpFDiv,dtFloat32,dst,one,src);

View File

@ -25,7 +25,7 @@
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units Count="38">
<Units Count="63">
<Unit0>
<Filename Value="pssl-spirv.lpr"/>
<IsPartOfProject Value="True"/>
@ -190,6 +190,110 @@
<Filename Value="emit_alloc.pas"/>
<IsPartOfProject Value="True"/>
</Unit37>
<Unit38>
<Filename Value="emit_fetch.pas"/>
<IsPartOfProject Value="True"/>
</Unit38>
<Unit39>
<Filename Value="emit_mtbuf.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="emit_MTBUF"/>
</Unit39>
<Unit40>
<Filename Value="emit_post.pas"/>
<IsPartOfProject Value="True"/>
</Unit40>
<Unit41>
<Filename Value="emit_sopk.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="emit_SOPK"/>
</Unit41>
<Unit42>
<Filename Value="emit_vbuf_chain.pas"/>
<IsPartOfProject Value="True"/>
</Unit42>
<Unit43>
<Filename Value="emit_vbuf_load.pas"/>
<IsPartOfProject Value="True"/>
</Unit43>
<Unit44>
<Filename Value="emit_vbuf_store.pas"/>
<IsPartOfProject Value="True"/>
</Unit44>
<Unit45>
<Filename Value="emit_vop3.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="emit_VOP3"/>
</Unit45>
<Unit46>
<Filename Value="ginodes.pas"/>
<IsPartOfProject Value="True"/>
</Unit46>
<Unit47>
<Filename Value="spirv.pas"/>
<IsPartOfProject Value="True"/>
</Unit47>
<Unit48>
<Filename Value="srBitcast.pas"/>
<IsPartOfProject Value="True"/>
</Unit48>
<Unit49>
<Filename Value="srCacheOp.pas"/>
<IsPartOfProject Value="True"/>
</Unit49>
<Unit50>
<Filename Value="srCapability.pas"/>
<IsPartOfProject Value="True"/>
</Unit50>
<Unit51>
<Filename Value="srCFGCursor.pas"/>
<IsPartOfProject Value="True"/>
</Unit51>
<Unit52>
<Filename Value="srCFGLabel.pas"/>
<IsPartOfProject Value="True"/>
</Unit52>
<Unit53>
<Filename Value="srCFGParser.pas"/>
<IsPartOfProject Value="True"/>
</Unit53>
<Unit54>
<Filename Value="srFlow.pas"/>
<IsPartOfProject Value="True"/>
</Unit54>
<Unit55>
<Filename Value="srLiteral.pas"/>
<IsPartOfProject Value="True"/>
</Unit55>
<Unit56>
<Filename Value="srNode.pas"/>
<IsPartOfProject Value="True"/>
</Unit56>
<Unit57>
<Filename Value="srPrivate.pas"/>
<IsPartOfProject Value="True"/>
</Unit57>
<Unit58>
<Filename Value="srType.pas"/>
<IsPartOfProject Value="True"/>
</Unit58>
<Unit59>
<Filename Value="srUniform.pas"/>
<IsPartOfProject Value="True"/>
</Unit59>
<Unit60>
<Filename Value="srVBufInfo.pas"/>
<IsPartOfProject Value="True"/>
</Unit60>
<Unit61>
<Filename Value="..\chip\ps4_pssl.pas"/>
<IsPartOfProject Value="True"/>
</Unit61>
<Unit62>
<Filename Value="emit_ds.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="emit_DS"/>
</Unit62>
</Units>
</ProjectOptions>
<CompilerOptions>

View File

@ -37,6 +37,7 @@ type
function _Find(dtype:TsrDataType;src:TsrRegNode):TsrBitcast;
function Find(dtype:TsrDataType;src:TsrRegNode):TsrRegNode;
Procedure Save(dtype:TsrDataType;src,dst:TsrRegNode);
function CastConst(dtype:TsrDataType;src:TsrRegNode):TsrRegNode;
function FetchRead(dtype:TsrDataType;src:TsrRegNode):TsrRegNode;
function FetchDstr(dtype:TsrDataType;src:TsrRegNode):TsrRegNode;
function FetchCast(dtype:TsrDataType;src:TsrRegNode):TsrRegNode;
@ -92,12 +93,24 @@ begin
FTree.Insert(node);
end;
function TsrBitcastList.FetchRead(dtype:TsrDataType;src:TsrRegNode):TsrRegNode;
function TsrBitcastList.CastConst(dtype:TsrDataType;src:TsrRegNode):TsrRegNode;
var
pConstList:PsrConstList;
dst:TsrRegNode;
pConst:TsrConst;
begin
pConst:=src.AsConst;
pConstList:=rSlot.Emit.GetConstList;
pConst:=pConstList^.Bitcast(dtype,pConst);
Result:=rSlot.New(dtype);
Result.pWriter:=pConst;
Result.CustomLine:=src.CustomLine;
end;
function TsrBitcastList.FetchRead(dtype:TsrDataType;src:TsrRegNode):TsrRegNode;
var
dst:TsrRegNode;
begin
Result:=src;
if (src=nil) then Exit;
@ -110,20 +123,13 @@ begin
//only from consts, first
dst:=Find(dtype,src);
if (dst<>nil) then Exit(dst);
pConst:=src.AsConst;
pConstList:=rSlot.Emit.GetConstList;
pConst:=pConstList^.Bitcast(dtype,pConst);
dst:=rSlot.New(src.pLine,dtype);
dst.pWriter:=pConst;
//
dst:=CastConst(dtype,src);
//
Save(dtype,src,dst);
end else
begin
dst:=rSlot.New(src.pLine,dtype);
dst:=rSlot.New(dtype);
dst.pWriter:=src;
end;
@ -140,7 +146,7 @@ begin
Assert(TryBitcastType(src.dtype,dtype));
dst:=rSlot.New(src.pLine,dtype);
dst:=rSlot.New(dtype);
dst.pWriter:=src.pWriter;
src.pWriter:=dst;
@ -148,14 +154,14 @@ begin
Result:=dst;
end;
//post process
function TsrBitcastList.FetchCast(dtype:TsrDataType;src:TsrRegNode):TsrRegNode;
var
pConstList:PsrConstList;
dst:TsrRegNode;
pConst:TsrConst;
pLine:TsrNode;
prv:TsrRegNode;
begin
Result:=src;
if (src=nil) then Exit;
if (dtype=dtUnknow) or (dtype=src.dtype) then Exit;
@ -167,22 +173,18 @@ begin
dst:=Find(dtype,src);
if (dst<>nil) then Exit(dst);
if src.is_const then
prv:=RegDown(src);
if prv.is_const then
begin
pConst:=src.AsConst;
pConstList:=rSlot.Emit.GetConstList;
pConst:=pConstList^.Bitcast(dtype,pConst);
dst:=rSlot.New(src.pLine,dtype);
dst.pWriter:=pConst;
dst:=CastConst(dtype,prv);
end else
begin
if TryBitcastType(src.dtype,dtype) then
begin
dst:=rSlot.New(src.pLine,dtype);
dst:=rSlot.New(dtype);
pLine:=rSlot.Emit.OpCast(src.pLine,dst,src);
rSlot.Emit.OpCast(prv.pLine,dst,src);
end else
begin
Writeln('bitcast:',src.dtype,'<>',dtype);

View File

@ -26,7 +26,7 @@ type
//
Procedure InitFlow;
procedure mark_end_of(mark:TsrVolMark);
Procedure PushBlockOp(pLine:TspirvOp;pChild:TsrOpBlock;pLBlock:TsrCFGBlock);
Procedure PushBlockOp(pLine:TspirvOp;pChild:TsrOpBlock;pLBlock:TsrCFGBlock=nil);
function PopBlockOp:Boolean;
function ConvertCond(cond:TsrCondition;pLine:TspirvOp):TsrRegNode;
function ConvertStatment(node:TsrStatement;pLine:TspirvOp):TsrNode;
@ -60,7 +60,7 @@ begin
//
InitBlock:=AllocBlockOp;
InitBlock.SetInfo(btOther,Cursor.Adr,Cursor.Adr);
PushBlockOp(line,InitBlock,nil);
PushBlockOp(line,InitBlock);
Main.PopBlock;
end;
@ -87,7 +87,7 @@ begin
end;
end;
Procedure TEmitFlow.PushBlockOp(pLine:TspirvOp;pChild:TsrOpBlock;pLBlock:TsrCFGBlock);
Procedure TEmitFlow.PushBlockOp(pLine:TspirvOp;pChild:TsrOpBlock;pLBlock:TsrCFGBlock=nil);
begin
pChild.FCursor:=Cursor; //prev
pChild.FLBlock:=pLBlock;
@ -228,7 +228,7 @@ var
pOpChild:=AllocBlockOp;
pOpChild.SetInfo(btOther,Cursor.Adr,Cursor.Adr);
PushBlockOp(line,pOpChild,nil);
PushBlockOp(line,pOpChild);
if (pLBlock.pCond<>nil) then
begin
@ -262,7 +262,7 @@ var
pOpChild:=AllocBlockOp;
pOpChild.SetInfo(btOther,Cursor.Adr,Cursor.Adr);
PushBlockOp(line,pOpChild,nil);
PushBlockOp(line,pOpChild);
OpBranch(line,pEndOp); //break
Main.PopBlock;
@ -418,8 +418,8 @@ end;
function TEmitFlow.ConvertCond(cond:TsrCondition;pLine:TspirvOp):TsrRegNode;
begin
case cond of
cFalse :Result:=NewReg_b(False);
cTrue :Result:=NewReg_b(True);
cFalse :Result:=NewImm_b(False,pLine);
cTrue :Result:=NewImm_b(True ,pLine);
cScc0 :Result:=fetch_scc;
cScc1 :Result:=fetch_scc;
cVccz :Result:=fetch_vccz ; //It means that lane_id=0
@ -439,7 +439,7 @@ begin
if Result.is_const then
begin
//early optimization
Result:=NewReg_b(not Result.AsConst.AsBool,@pLine);
Result:=NewImm_b(not Result.AsConst.AsBool,pLine);
end else
begin
Result:=OpLogicalNotTo(Result,@pLine);
@ -873,7 +873,7 @@ begin
pOpBody:=AllocBlockOp;
pOpBody.SetInfo(Info);
Result.pBody:=pOpBody; //save body link
PushBlockOp(line,pOpBody,nil);
PushBlockOp(line,pOpBody);
end;
function TEmitFlow.NewElse(pOpMerge:TsrOpBlock;pLBlock:TsrCFGBlock):TsrOpBlock;
@ -905,7 +905,7 @@ begin
pOpBody:=AllocBlockOp;
pOpBody.SetInfo(Info);
Result.pBody:=pOpBody; //save body link
PushBlockOp(line,pOpBody,nil);
PushBlockOp(line,pOpBody);
end;
function TEmitFlow.NewLoop(pLBlock:TsrCFGBlock):TsrOpBlock;
@ -984,7 +984,7 @@ begin
pOpBody.SetInfo(Info);
Result.pBody:=pOpBody; //save body link
PushBlockOp(line,pOpBody,nil);
PushBlockOp(line,pOpBody);
end;
function TEmitFlow.CheckBlockBeg:Boolean;

View File

@ -209,6 +209,7 @@ var
c:=PsrConstList(FEmit.GetConstList)^.Fetch(node.pReg.dtype,0);
node.pReg.pWriter:=c;
node.pReg.CustomLine:=l;
end;
begin
@ -316,6 +317,11 @@ begin
//
end;
itSubgroupLocalInvocationId:
begin
pDecorateList.OpDecorate(pVar,Decoration.BuiltIn,BuiltIn.SubgroupLocalInvocationId);
end;
itPositions:
begin
pDecorateList.OpDecorate(pVar,Decoration.BuiltIn,BuiltIn.Position);

View File

@ -148,13 +148,13 @@ type
function _get_line(ppLine:PPspirvOp):TspirvOp;
//
Function NewRegPair:TsrRegPair;
Function NewReg(rtype:TsrDataType;ppLine:PPspirvOp=nil):TsrRegNode;
Function NewReg(pConst:TsrConst;ppLine:PPspirvOp=nil):TsrRegNode;
Function NewReg(rtype:TsrDataType):TsrRegNode;
Function NewImm(pConst:TsrConst;pLine:TspirvOp=nil):TsrRegNode;
//
Function NewReg_q(dtype:TsrDataType;value:QWORD;ppLine:PPspirvOp=nil):TsrRegNode;
Function NewReg_b(value:Boolean;ppLine:PPspirvOp=nil):TsrRegNode;
Function NewReg_i(dtype:TsrDataType;value:Integer;ppLine:PPspirvOp=nil):TsrRegNode;
Function NewReg_s(dtype:TsrDataType;value:Single;ppLine:PPspirvOp=nil):TsrRegNode;
Function NewImm_q(dtype:TsrDataType;value:QWORD;pLine:TspirvOp=nil):TsrRegNode;
Function NewImm_b(value:Boolean;pLine:TspirvOp=nil):TsrRegNode;
Function NewImm_i(dtype:TsrDataType;value:Integer;pLine:TspirvOp=nil):TsrRegNode;
Function NewImm_s(dtype:TsrDataType;value:Single;pLine:TspirvOp=nil):TsrRegNode;
//
function NewSpirvOp(OpId:DWORD):TSpirvOp;
function NewLabelOp(sdep:Boolean):TSpirvOp;
@ -353,7 +353,10 @@ end;
function TEmitInterface.init_line:TsrNode;
begin
Assert(InitBlock<>nil);
if (InitBlock=nil) then
begin
Exit(nil);
end;
if (InitBlock.dummy.Parent=nil) then //is not init?
begin
InitBlock.Init();
@ -410,40 +413,41 @@ begin
Result:=specialize New<TsrRegPair>;
end;
Function TEmitInterface.NewReg(rtype:TsrDataType;ppLine:PPspirvOp=nil):TsrRegNode;
Function TEmitInterface.NewReg(rtype:TsrDataType):TsrRegNode;
begin
Result:=RegsStory.FUnattach.New(line,rtype);
Result.pLine:=_get_line(ppLine);
Result:=RegsStory.FUnattach.New(rtype);
end;
Function TEmitInterface.NewReg(pConst:TsrConst;ppLine:PPspirvOp=nil):TsrRegNode;
Function TEmitInterface.NewImm(pConst:TsrConst;pLine:TspirvOp=nil):TsrRegNode;
begin
if (pConst=nil) then Exit(nil);
Result:=NewReg(pConst.dtype);
Result.pWriter:=pConst;
Result.pLine:=_get_line(ppLine);
//
if (pLine=nil) then pLine:=line;
Result.CustomLine:=pLine;
end;
//
Function TEmitInterface.NewReg_q(dtype:TsrDataType;value:QWORD;ppLine:PPspirvOp=nil):TsrRegNode;
Function TEmitInterface.NewImm_q(dtype:TsrDataType;value:QWORD;pLine:TspirvOp=nil):TsrRegNode;
begin
Result:=NewReg(ConstList.Fetch(dtype,value),ppLine);
Result:=NewImm(ConstList.Fetch(dtype,value),pLine);
end;
Function TEmitInterface.NewReg_b(value:Boolean;ppLine:PPspirvOp=nil):TsrRegNode;
Function TEmitInterface.NewImm_b(value:Boolean;pLine:TspirvOp=nil):TsrRegNode;
begin
Result:=NewReg(ConstList.Fetch_b(value),ppLine);
Result:=NewImm(ConstList.Fetch_b(value),pLine);
end;
Function TEmitInterface.NewReg_i(dtype:TsrDataType;value:Integer;ppLine:PPspirvOp=nil):TsrRegNode;
Function TEmitInterface.NewImm_i(dtype:TsrDataType;value:Integer;pLine:TspirvOp=nil):TsrRegNode;
begin
Result:=NewReg(ConstList.Fetch_i(dtype,value),ppLine);
Result:=NewImm(ConstList.Fetch_i(dtype,value),pLine);
end;
Function TEmitInterface.NewReg_s(dtype:TsrDataType;value:Single;ppLine:PPspirvOp=nil):TsrRegNode;
Function TEmitInterface.NewImm_s(dtype:TsrDataType;value:Single;pLine:TspirvOp=nil):TsrRegNode;
begin
Result:=NewReg(ConstList.Fetch_s(dtype,value),ppLine);
Result:=NewImm(ConstList.Fetch_s(dtype,value),pLine);
end;
function TEmitInterface.NewSpirvOp(OpId:DWORD):TSpirvOp;
@ -512,7 +516,7 @@ procedure TEmitInterface.MakeCopy(dst:PsrRegSlot;src:TsrRegNode);
var
node:TsrRegNode;
begin
node:=dst^.New(line,src.dtype);
node:=dst^.New(src.dtype,line);
node.pWriter:=src;
PostLink(line,node); //post processing
@ -522,7 +526,7 @@ Procedure TEmitInterface.SetConst(pSlot:PsrRegSlot;pConst:TsrConst);
var
dst:TsrRegNode;
begin
dst:=pSlot^.New(line,pConst.dtype);
dst:=pSlot^.New(pConst.dtype,line);
dst.pWriter:=pConst;
PostLink(line,dst); //post processing
@ -603,7 +607,7 @@ begin
if (pSlot=nil) then Exit;
if (pSlot^.current=nil) then
begin
pSlot^.New(line,rtype); //Unresolve
pSlot^.New(rtype,line); //Unresolve
Exit;
end;

View File

@ -71,6 +71,7 @@ type
Procedure _SetWriter(w,line:TsrNode); virtual;
Procedure _ResetWriter(w:TsrNode); virtual;
Function _is_used:Boolean virtual;
Function _GetPline:TsrNode; virtual;
Function _GetPtype:TsrNode; virtual;
Function _GetStorageClass:DWORD; virtual;
function _GetStorageName:RawByteString; virtual;
@ -407,6 +408,11 @@ begin
Result:=(read_count<>0) or (write_count<>0);
end;
Function TsrNode._GetPline:TsrNode;
begin
Result:=nil;
end;
function TsrNode._GetPtype:TsrNode;
begin
Result:=nil;

View File

@ -74,6 +74,7 @@ type
//
Procedure _zero_read; override;
Procedure _PrepType(node:PPrepTypeNode); override;
Function _GetPline:TsrNode; override;
Function _GetPtype:TsrNode; override;
function _GetIndexCount:DWORD; override;
//
@ -272,6 +273,11 @@ begin
UnClear;
end;
Function TspirvOp._GetPline:TsrNode;
begin
Result:=Self;
end;
Function TspirvOp._GetPtype:TsrNode;
begin
Result:=FType;

View File

@ -55,6 +55,8 @@ function GetMaxPlace(pLine:TSpirvOp;count:Byte;src:PPsrRegNode):TSpirvOp;
function GetChainRegNode (node:TsrRegNode):TsrChain;
function GetSourceRegNode(node:TsrRegNode):TsrNode;
function RegDownTestError(node:TsrRegNode):TsrRegNode;
function flow_down_next_up(pLine:TSpirvOp):TSpirvOp;
function flow_down_prev_up(pLine:TSpirvOp):TSpirvOp;
function flow_prev_up(pLine:TSpirvOp):TSpirvOp;
@ -634,5 +636,22 @@ begin
Result:=pVar.pSource;
end;
function RegDownTestError(node:TsrRegNode):TsrRegNode;
var
tmp:TsrRegNode;
begin
//backtrace
Result:=nil;
tmp:=node;
while (tmp<>nil) do
begin
if GetGlobalIndex(tmp.pLine)>GetGlobalIndex(node.pLine) then
begin
Exit(tmp);
end;
tmp:=tmp.AsReg; //next
end;
end;
end.

View File

@ -185,6 +185,7 @@ var
node:TDependenceNode;
begin
if (src=nil) then Exit;
Assert(src.pLine<>nil);
node:=NewDependence;
node.pNode:=src;
if FZeroRead then
@ -197,6 +198,7 @@ end;
Procedure TsrVolatile.PushStore(node:TDependenceNode);
begin
if (node=nil) then Exit;
Assert(TsrRegNode(node.pNode).pLine<>nil);
if FZeroRead then
begin
TsrRegNode(node.pNode).mark_read(Self);
@ -741,7 +743,7 @@ begin
pLine:=ctx.after;
//replace next
_next:=pSlot^.New(pLine,rtype);
_next:=pSlot^.New(rtype,pLine);
_next.pWriter:=pVolatile;
ctx.AddVolatile(pVolatile,_next);
@ -838,7 +840,7 @@ begin
pLine:=ctx.after;
//replace next
_next:=pSlot^.New(pLine,rtype);
_next:=pSlot^.New(rtype,pLine);
_next.pWriter:=pVolatile;
ctx.AddVolatile(pVolatile,_next);
@ -957,7 +959,7 @@ begin
if (prev=nil) then
begin
//The input register is not defined, should it be initialized to make_copy_slot?
prev:=pSlot^.New(pLine,rtype);
prev:=pSlot^.New(rtype,pLine);
end;
//set backedge dependence
@ -1065,11 +1067,11 @@ begin
begin
pLine:=FEmit.curr_line;
node:=pSlot^.New(pLine,cur.dtype);
node:=pSlot^.New(cur.dtype,pLine);
node.pWriter:=cur;
FEmit.PostLink(pLine,node); //post processing
node.pLine:=pLine;
node.CustomLine:=pLine;
end;
end;
@ -1182,7 +1184,7 @@ begin
//ntVolatile -> src -> next
//Opload -> new
Result:=src.pSlot^.New(dst,src.dtype);
Result:=src.pSlot^.New(src.dtype,dst);
pPrivate.FetchLoad(dst,Result); //before reg
end;

View File

@ -32,6 +32,7 @@ type
end;
FSlot:PsrRegSlot;
FWriter:TsrNode; //ntReg,ntConst,ntOp,ntVolatile
FCustomLine:TsrNode; //PspirvOp;
function GetDtype:TsrDataType;
Procedure SetDtype(t:TsrDataType);
function GetWeak:Boolean;
@ -39,8 +40,10 @@ type
Procedure SetWriter(t:TsrNode);
Function GetWriter:TsrNode;
public
pLine:TsrNode; //PspirvOp;
function pLine:TsrNode;
property CustomLine:TsrNode read FCustomLine write FCustomLine;
//
Function _GetPline :TsrNode; override;
Procedure _SetWriter (w,line:TsrNode); override;
Procedure _ResetWriter (w:TsrNode); override;
function _Down :TsrNode; override;
@ -79,6 +82,7 @@ type
function _Down:TsrNode; override;
Procedure _SetWriter (w,line:TsrNode); override;
Procedure _ResetWriter(w:TsrNode); override;
Function _GetPline:TsrNode; override;
//
property pLine:TsrNode read FWriter;
property pWriter:TsrNode read FWriter write SetWriter;
@ -105,9 +109,7 @@ type
function first:TsrRegNode;
function last :TsrRegNode;
function isBoolOnly:Boolean;
function New(pLine:TsrNode;rtype:TsrDataType):TsrRegNode;
function NewAfter(rtype:TsrDataType;r:TsrRegNode):TsrRegNode;
function NewBefore(rtype:TsrDataType;r:TsrRegNode):TsrRegNode;
function New(rtype:TsrDataType;pLine:TsrRegNode=nil):TsrRegNode;
procedure Insert(r:TsrRegNode);
procedure Remove(r:TsrRegNode);
end;
@ -221,10 +223,43 @@ end;
//
Function TsrRegNode._GetPline:TsrNode;
var
tmp:TsrRegNode;
begin
Result:=nil;
//
if (FCustomLine<>nil) then
begin
Exit(FCustomLine);
end;
//
tmp:=FWriter;
while (tmp<>nil) do
begin
if tmp.IsType(ntReg) then
begin
if (tmp.FCustomLine<>nil) then
begin
Exit(tmp.FCustomLine);
end;
end else
begin
Exit(tmp._GetPline);
end;
tmp:=tmp._Down;
end;
end;
function TsrRegNode.pLine:TsrNode;
begin
if (Self=nil) then Exit(nil);
Result:=_GetPline;
end;
Procedure TsrRegNode._SetWriter(w,line:TsrNode);
begin
SetWriter(w);
pLine:=line;
end;
Procedure TsrRegNode._ResetWriter(w:TsrNode);
@ -232,7 +267,6 @@ begin
if (FWriter=w) then
begin
SetWriter(nil);
pLine:=nil;
end;
end;
@ -329,6 +363,11 @@ begin
end;
end;
Function TsrRegPair._GetPline:TsrNode;
begin
Result:=FWriter;
end;
//
Procedure TsrRegsStory.Init(Emit:TCustomEmit);
@ -601,14 +640,6 @@ begin
if (Self=nil) then Exit;
if (FWriter=t) then Exit;
{
if t.IsType(ntConst) then
if (dtype<>TsrConst(t).dtype) then
begin
Assert(false);
end;
}
Assert(RegDown(t.specialize AsType<ntReg>)<>Self,'Circular reference');
if isUsed then
@ -617,6 +648,16 @@ begin
FWriter.mark_unread(Self);
end;
FWriter:=t;
//update
if (FWriter=nil) then
begin
FCustomLine:=nil;
end else
if (FWriter._GetPline<>nil) then
begin
FCustomLine:=nil;
end;
end;
Function TsrRegNode.GetWriter:TsrNode;
@ -728,7 +769,7 @@ begin
Result:=(rid='SCC');
end;
function TsrRegSlot.New(pLine:TsrNode;rtype:TsrDataType):TsrRegNode;
function TsrRegSlot.New(rtype:TsrDataType;pLine:TsrRegNode=nil):TsrRegNode;
var
node:TsrRegNode;
begin
@ -739,55 +780,14 @@ begin
node:=FEmit.specialize New<TsrRegNode>;
node.FSlot:=@Self;
node.dtype:=rtype;
node.pLine:=pLine;
node.CustomLine:=pLine;
//
pStory.Push_tail(node);
Result:=node;
//update
current:=pStory.pTail;
end;
function TsrRegSlot.NewAfter(rtype:TsrDataType;r:TsrRegNode):TsrRegNode;
var
node:TsrRegNode;
begin
if isBoolOnly then
begin
rtype:=dtBool;
end;
node:=FEmit.specialize New<TsrRegNode>;
node.FSlot:=@Self;
node.dtype:=rtype;
node.pLine:=r.pLine;
pStory.InsertAfter(r,node);
Result:=node;
//update
if (r=pStory.pTail) then
begin
current:=pStory.pTail;
end;
end;
function TsrRegSlot.NewBefore(rtype:TsrDataType;r:TsrRegNode):TsrRegNode;
var
node:TsrRegNode;
begin
if isBoolOnly then
begin
rtype:=dtBool;
end;
node:=FEmit.specialize New<TsrRegNode>;
node.FSlot:=@Self;
node.dtype:=rtype;
node.pLine:=r.pLine;
pStory.InsertBefore(r,node);
Result:=node;
//update
if (r=pStory.pTail) then
begin
current:=pStory.pTail;
end;
end;
procedure TsrRegSlot.Insert(r:TsrRegNode);
begin
if (r=nil) then Exit;

View File

@ -125,7 +125,7 @@ begin
//gen const id
For i:=0 to 3 do
begin
UintId[i]:=SprvEmit.NewReg_i(dtUint32,i);
UintId[i]:=SprvEmit.NewImm_i(dtUint32,i);
end;
//load positions
@ -156,8 +156,8 @@ begin
SprvEmit._Op2(SprvEmit.line,Op.OpFOrdEqual,CoordEqualY[i],positionsY[i],positionsY[(i + 1) mod 3]);
end;
pOneId :=SprvEmit.NewReg_s(dtFloat32, 1);
pMinusOne:=SprvEmit.NewReg_s(dtFloat32,-1);
pOneId :=SprvEmit.NewImm_s(dtFloat32, 1);
pMinusOne:=SprvEmit.NewImm_s(dtFloat32,-1);
//calc barycentric
For i:=0 to 2 do