This commit is contained in:
Pavel 2025-03-16 00:06:33 +03:00
parent bd375e6b51
commit e172746123
18 changed files with 176 additions and 171 deletions

View File

@ -15,7 +15,7 @@ uses
srReg,
srOutput,
srOp,
srOpUtils,
srOpInternal,
emit_fetch;
type
@ -226,7 +226,7 @@ begin
Inc(push_count);
exc:=MakeRead(get_exec0,dtBool); //It means that lane_id=0
node:=AddSpirvOp(OpMakeExp);
node:=AddSpirvOp(srOpInternal.OpMakeExp);
node.AddParam(exc); //<-fetch read
end;

View File

@ -15,6 +15,7 @@ uses
srConst,
srReg,
srOp,
srOpInternal,
srOpUtils,
srLayout,
srVertLayout,
@ -157,8 +158,8 @@ begin
if (pop_1[0]=nil) then Exit;
if (pop_1[1]=nil) then Exit;
if (pop_1[0].OpId<>srOpUtils.OpIAddExt) then Exit;
if (pop_1[1].OpId<>srOpUtils.OpIAddExt) then Exit;
if (pop_1[0].OpId<>srOpInternal.OpIAddExt) then Exit;
if (pop_1[1].OpId<>srOpInternal.OpIAddExt) then Exit;
//S_ADD_U32
imms_p0[0]:=GetRegConst(pop_1[0].ParamNode(0).AsReg); //const

View File

@ -13,6 +13,7 @@ uses
srReg,
srOp,
srCFGLabel,
srOpInternal,
srOpUtils,
srCacheOp,
srInterface;
@ -681,7 +682,7 @@ Var
begin
Assert(rtype.Sign=0);
node:=AddSpirvOp(srOpUtils.OpIAddExt); //need first
node:=AddSpirvOp(srOpInternal.OpIAddExt); //need first
node.AddParam(src0);
node.AddParam(src1);
@ -700,7 +701,7 @@ Var
begin
Assert(dst.dtype.Sign=0);
node:=AddSpirvOp(srOpUtils.OpIAddExt); //need first
node:=AddSpirvOp(srOpInternal.OpIAddExt); //need first
node.AddParam(src0);
node.AddParam(src1);
@ -745,7 +746,7 @@ Var
begin
Assert(rtype.Sign=0);
node:=AddSpirvOp(srOpUtils.OpISubExt); //need first
node:=AddSpirvOp(srOpInternal.OpISubExt); //need first
node.AddParam(src0);
node.AddParam(src1);
@ -761,22 +762,22 @@ end;
function TEmitOp.OpAbsDiff(pLine:TspirvOp;dst,src0,src1:TsrRegNode):TspirvOp;
begin
Result:=_Op2(pLine,srOpUtils.OpAbsDiff,dst,src0,src1);
Result:=_Op2(pLine,srOpInternal.OpAbsDiff,dst,src0,src1);
end;
procedure TEmitOp.OpWQM32(dst:PsrRegSlot;src:TsrRegNode);
begin
Op1(srOpUtils.OpWQM32,dtUnknow,dst,src);
Op1(srOpInternal.OpWQM32,dtUnknow,dst,src);
end;
procedure TEmitOp.OpBFE_32(dst:PsrRegSlot;base,src0,src1:TsrRegNode);
begin
Op3(srOpUtils.OpBFE_32,base.dtype,dst,base,src0,src1);
Op3(srOpInternal.OpBFE_32,base.dtype,dst,base,src0,src1);
end;
procedure TEmitOp.OpBFIB32(dst:PsrRegSlot;bitmsk,src0,src1:TsrRegNode);
begin
Op3(srOpUtils.OpBFIB32,dtUint32,dst,bitmsk,src0,src1);
Op3(srOpInternal.OpBFIB32,dtUint32,dst,bitmsk,src0,src1);
end;
function TEmitOp.OpBFITo(src0,src1,src2,src3:TsrRegNode;ppLine:PPspirvOp=nil):TsrRegNode;
@ -795,7 +796,7 @@ end;
procedure TEmitOp.OpPackAnc(dst:PsrRegSlot;prim,smid,rtid:TsrRegNode);
begin
Op3(srOpUtils.OpPackAnc,dtUint32,dst,prim,smid,rtid);
Op3(srOpInternal.OpPackAnc,dtUint32,dst,prim,smid,rtid);
end;
//
@ -898,11 +899,11 @@ begin
pLine:=GetMaxPlace(pLine,1,@src);
p:=CacheOpList.Fetch(pLine.Parent,srOpUtils.OpPackOfs,rtype,1,@src);
p:=CacheOpList.Fetch(pLine.Parent,srOpInternal.OpPackOfs,rtype,1,@src);
if (p.pDst=nil) then
begin
node:=AddSpirvOp(pLine,srOpUtils.OpPackOfs); //need first
node:=AddSpirvOp(pLine,srOpInternal.OpPackOfs); //need first
dst:=NewReg(rtype);
@ -960,11 +961,11 @@ begin
pLine:=GetMaxPlace(pLine,rtype.Count,src);
p:=CacheOpList.Fetch(pLine.Parent,srOpUtils.OpMakeVec,rtype,rtype.Count,src);
p:=CacheOpList.Fetch(pLine.Parent,srOpInternal.OpMakeVec,rtype,rtype.Count,src);
if (p.pDst=nil) then
begin
node:=AddSpirvOp(pLine,srOpUtils.OpMakeVec); //need first
node:=AddSpirvOp(pLine,srOpInternal.OpMakeVec); //need first
dst:=NewReg(rtype);
@ -995,11 +996,11 @@ begin
pLine:=GetMaxPlace(pLine,rtype.Count,src);
p:=CacheOpList.Fetch(pLine.Parent,srOpUtils.OpMakeCub,rtype,rtype.Count,src);
p:=CacheOpList.Fetch(pLine.Parent,srOpInternal.OpMakeCub,rtype,rtype.Count,src);
if (p.pDst=nil) then
begin
node:=AddSpirvOp(pLine,srOpUtils.OpMakeCub); //need first
node:=AddSpirvOp(pLine,srOpInternal.OpMakeCub); //need first
dst:=NewReg(rtype);

View File

@ -662,7 +662,7 @@ begin
if (node.read_count<>0) then
if not node.is_force then
begin
Assert(false,'Wrong read_count on:'+Op.GetStr(node.OpId));
Assert(false,'Wrong read_count on:'+OpGetStrDebug(node));
end;
//
node.Remove;
@ -1147,8 +1147,6 @@ function TSprvEmit_post.LinkBitcast(pBuffer:TsrBuffer):TsrNode;
var
pLine:TspirvOp;
use:Boolean;
tbuf:TsrBuffer;
tref:TsrNode;
pType:TsrType;

View File

@ -18,6 +18,7 @@ uses
srReg,
srPrivate,
srOp,
srOpInternal,
srOpUtils,
emit_fetch;
@ -95,12 +96,12 @@ begin
Op.OpShiftRightLogical,
Op.OpShiftRightArithmetic:Result:=OnShr1(node);
srOpUtils.OpAbsDiff :Result:=OnAbsDiff1(node);
srOpUtils.OpWQM32 :Result:=OnWQM32__1(node);
srOpUtils.OpPackOfs :Result:=OnPackOfs1(node);
srOpUtils.OpBFE_32 :Result:=OnBFE_32_1(node);
srOpUtils.OpBFIB32 :Result:=OnBFIB32_1(node);
srOpUtils.OpMakeCub :Result:=OnMakeCub1(node);
srOpInternal.OpAbsDiff :Result:=OnAbsDiff1(node);
srOpInternal.OpWQM32 :Result:=OnWQM32__1(node);
srOpInternal.OpPackOfs :Result:=OnPackOfs1(node);
srOpInternal.OpBFE_32 :Result:=OnBFE_32_1(node);
srOpInternal.OpBFIB32 :Result:=OnBFIB32_1(node);
srOpInternal.OpMakeCub :Result:=OnMakeCub1(node);
Op.OpSelect :Result:=OnSelect1(node);
@ -127,11 +128,10 @@ begin
Case node.OpId of
srOpUtils.OpIAddExt:Result:=OnIAddExt2(node);
srOpUtils.OpISubExt:Result:=OnISubExt2(node);
srOpUtils.OpMakeVec:Result:=OnMakeVec2(node);
srOpUtils.OpPackAnc:Result:=OnPackAnc2(node);
srOpInternal.OpIAddExt:Result:=OnIAddExt2(node);
srOpInternal.OpISubExt:Result:=OnISubExt2(node);
srOpInternal.OpMakeVec:Result:=OnMakeVec2(node);
srOpInternal.OpPackAnc:Result:=OnPackAnc2(node);
Op.OpReturn:Result:=OnReturn_2(node);
OpMakeExp :Result:=OnMakeExp2(node);
@ -140,6 +140,8 @@ begin
OpCUBESC:OnCUBESC2(node);
OpCUBETC:OnCUBETC2(node);
OpCUBEMA:OnCUBEMA2(node);
srOpInternal.OpMakeCub:Assert(false,'OpMakeCub');
end;
end;
@ -2039,7 +2041,7 @@ begin
pLine:=node.pWriter.specialize AsType<ntOp>;
if (pLine=nil) then Exit;
if (pLine.OpId<>srOpUtils.OpPackAnc) then Exit;
if (pLine.OpId<>srOpInternal.OpPackAnc) then Exit;
src[0]:=pLine.ParamNode(0).AsReg;
src[1]:=pLine.ParamNode(1).AsReg;
@ -2294,6 +2296,33 @@ begin
Result:=True;
end;
function _GetMadLegacyFma(node:TSpirvOp):TSpirvOp;
var
reg:TsrRegNode;
fma:TSpirvOp;
begin
Result:=node;
if (node=nil) then Exit;
if (node.OpId<>Op.OpSelect) then Exit;
reg:=RegDown(node.ParamNode(1).AsReg);
fma:=reg.pWriter.specialize AsType<ntOp>;
if _IsFma(fma) then
begin
Exit(fma);
end;
reg:=RegDown(node.ParamNode(2).AsReg);
fma:=reg.pWriter.specialize AsType<ntOp>;
if _IsFma(fma) then
begin
Exit(fma);
end;
end;
function _IsOp(node:TSpirvOp;OpId:DWORD):Boolean;
begin
Result:=False;
@ -2480,6 +2509,9 @@ begin
m_y:=RegDown(node.ParamNode(1).AsReg).pWriter.specialize AsType<ntOp>; //param2
m_f:=RegDown(node.ParamNode(2).AsReg).pWriter.specialize AsType<ntOp>; //param3
m_x:=_GetMadLegacyFma(m_x);
m_y:=_GetMadLegacyFma(m_y);
if not _IsFma(m_x) then Exit;
if not _IsFma(m_y) then Exit;
if not _IsOp(m_f,OpCUBEID) then Exit;

View File

@ -13,6 +13,7 @@ uses
srConst,
srVariable,
srOp,
srOpInternal,
srOpUtils,
strutils,
srCapability,
@ -198,10 +199,10 @@ begin
if Info.result then //dst
begin
Assert(node.pDst<>nil,'PrintOp$1');
Write(PadRight(GetNodeStr(node.pDst),PadAssign),' = ',Op.GetStr(node.OpId));
Write(PadRight(GetNodeStr(node.pDst),PadAssign),' = ',OpGetStrInternal(node.OpId));
end else
begin //no dst
Write(Op.GetStr(node.OpId));
Write(OpGetStrInternal(node.OpId));
if (node.pDst<>nil) then
begin
Write(' ',GetNodeStr(node.pDst));

View File

@ -14,7 +14,6 @@ uses
srLayout,
srConfig,
emit_fetch,
srop,
srVBufInfo;
type

View File

@ -10,7 +10,7 @@ uses
spirv,
srType,
srReg,
srOpUtils,
srOpInternal,
emit_fetch;
type
@ -1466,10 +1466,10 @@ begin
V_MED3_U32: emit_V_MED3_U32;
V_FMA_F32 : emit_V_FMA_F32;
V_CUBEID_F32:emit_V_CUBE(OpCUBEID);
V_CUBESC_F32:emit_V_CUBE(OpCUBESC);
V_CUBETC_F32:emit_V_CUBE(OpCUBETC);
V_CUBEMA_F32:emit_V_CUBE(OpCUBEMA);
V_CUBEID_F32:emit_V_CUBE(srOpInternal.OpCUBEID);
V_CUBESC_F32:emit_V_CUBE(srOpInternal.OpCUBESC);
V_CUBETC_F32:emit_V_CUBE(srOpInternal.OpCUBETC);
V_CUBEMA_F32:emit_V_CUBE(srOpInternal.OpCUBEMA);
//VOP1 analog

View File

@ -25,7 +25,7 @@
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units Count="63">
<Units Count="64">
<Unit0>
<Filename Value="pssl-spirv.lpr"/>
<IsPartOfProject Value="True"/>
@ -294,6 +294,10 @@
<IsPartOfProject Value="True"/>
<UnitName Value="emit_DS"/>
</Unit62>
<Unit63>
<Filename Value="srOpInternal.pas"/>
<IsPartOfProject Value="True"/>
</Unit63>
</Units>
</ProjectOptions>
<CompilerOptions>

View File

@ -11,7 +11,6 @@ uses
srNode,
srType,
srTypes,
srVariable,
srLayout,
srDecorate,
srConfig;
@ -836,6 +835,7 @@ function TsrBuffer.chain_read:DWORD;
var
node:TsrBuffer;
begin
Result:=0;
if Flags.Bitcast then
begin
node:=Self;
@ -870,6 +870,7 @@ function TsrBuffer.chain_write:DWORD;
var
node:TsrBuffer;
begin
Result:=0;
if Flags.Bitcast then
begin
node:=Self;

View File

@ -694,8 +694,6 @@ begin
end;
procedure TsrCFGParser.Print();
const
print_block_id=False;
var
prefix:RawByteString;
node,next:TsrCFGBlock;

View File

@ -1100,11 +1100,6 @@ begin
end;
Procedure TsrChain.SetRegType(rtype:TsrDataType);
var
pTypeList:PsrTypeList;
FType:TsrType;
node:TDependenceNode;
pLine:TSpirvOp;
begin
if (Fdtype=rtype) then Exit;
@ -1112,51 +1107,7 @@ begin
Fdtype:=rtype;
pTypeList:=Emit.GetTypeList;
FType:=pTypeList^.Fetch(rtype);
UpdateRegType;
{
node:=FList.pHead;
While (node<>nil) do
begin
pLine:=node.pNode;
Case pLine.OpId of
Op.OpLoad:
begin
pLine.pDst.PrepType(ord(rtype));
pLine.pType:=Ftype;
end;
Op.OpStore,
Op.OpAtomicStore,
Op.OpAtomicExchange,
Op.OpAtomicCompareExchange,
Op.OpAtomicCompareExchangeWeak,
Op.OpAtomicIIncrement,
Op.OpAtomicIDecrement,
Op.OpAtomicIAdd,
Op.OpAtomicISub,
Op.OpAtomicSMin,
Op.OpAtomicUMin,
Op.OpAtomicSMax,
Op.OpAtomicUMax,
Op.OpAtomicAnd,
Op.OpAtomicOr,
Op.OpAtomicXor:
begin
pLine.ParamNode(1).Value.PrepType(ord(rtype));
end;
else;
end;
node:=node.pNext;
end;
}
end;
Procedure TsrChain.SetIndex(t:TsrRegNode);

View File

@ -7,6 +7,7 @@ interface
uses
sysutils,
spirv,
srOpInternal,
ginodes,
srNode,
srCFGLabel,
@ -227,6 +228,7 @@ type
end;
Function classif_rw_op(OpId:DWORD):Byte;
function OpGetStrDebug(pLine:TSpirvOp):RawByteString;
operator := (i:TsrNode):TspirvOp; inline;
operator := (i:TsrNode):TsrOpBlock; inline;
@ -268,6 +270,28 @@ end;
//
function OpGetStrDebug(pLine:TSpirvOp):RawByteString;
var
V:PtrUint;
begin
Result:='';
if (pLine=nil) then Exit;
if (pLine.OpId=Op.OpExtInst) then
begin
V:=0;
if pLine.ParamNode(1).TryGetValue(V) then
begin
Result:=GlslOp.GetStr(V);
end;
end else
begin
Result:=OpGetStrInternal(pLine.OpId);
end;
end;
//
Procedure TspirvOp._zero_read;
begin
UnClear;
@ -548,7 +572,7 @@ begin
if not is_force then
begin
can_clear;
Assert(false,'Wrong read_count on:'+Op.GetStr(OpId));
Assert(false,'Wrong read_count on:'+OpGetStrDebug(Self));
end;
FType.mark_unread(Self);

63
spirv/srOpInternal.pas Normal file
View File

@ -0,0 +1,63 @@
unit srOpInternal;
{$mode ObjFPC}{$H+}
interface
uses
spirv;
const
OpIAddExt=DWORD(-1);
OpISubExt=DWORD(-2);
OpAbsDiff=DWORD(-3);
OpWQM32 =DWORD(-4);
OpBFE_32 =DWORD(-5);
OpBFIB32 =DWORD(-6);
OpPackAnc=DWORD(-7);
OpPackOfs=DWORD(-8);
OpMakeExp=DWORD(-9);
OpMakeVec=DWORD(-10);
OpMakeCub=DWORD(-11);
OpCUBEID =DWORD(-12);
OpCUBESC =DWORD(-13);
OpCUBETC =DWORD(-14);
OpCUBEMA =DWORD(-15);
function OpGetStrInternal(OpId:DWORD):RawByteString;
implementation
function OpGetStrInternal(OpId:DWORD):RawByteString;
begin
case OpId of
OpIAddExt:Result:='[OpIAddExt]';
OpISubExt:Result:='[OpISubExt]';
OpAbsDiff:Result:='[OpAbsDiff]';
OpWQM32 :Result:='[OpWQM32]';
OpBFE_32 :Result:='[OpBFE_32]';
OpBFIB32 :Result:='[OpBFIB32]';
OpPackAnc:Result:='[OpPackAnc]';
OpPackOfs:Result:='[OpPackOfs]';
OpMakeExp:Result:='[OpMakeExp]';
OpMakeVec:Result:='[OpMakeVec]';
OpMakeCub:Result:='[OpMakeCub]';
OpCUBEID :Result:='[OpCUBEID]';
OpCUBESC :Result:='[OpCUBESC]';
OpCUBETC :Result:='[OpCUBETC]';
OpCUBEMA :Result:='[OpCUBEMA]';
else
Result:=Op.GetStr(OpId);
end;
end;
end.

View File

@ -13,26 +13,6 @@ uses
srVariable,
srCFGLabel;
const
OpIAddExt=DWORD(-1);
OpISubExt=DWORD(-2);
OpAbsDiff=DWORD(-3);
OpWQM32 =DWORD(-4);
OpBFE_32 =DWORD(-5);
OpBFIB32 =DWORD(-6);
OpPackAnc=DWORD(-7);
OpPackOfs=DWORD(-8);
OpMakeExp=DWORD(-9);
OpMakeVec=DWORD(-10);
OpMakeCub=DWORD(-11);
OpCUBEID =DWORD(-12);
OpCUBESC =DWORD(-13);
OpCUBETC =DWORD(-14);
OpCUBEMA =DWORD(-15);
function InsSpirvOp(pLine,pNew:TSpirvOp):TSpirvOp;
Function get_inverse_left_cmp_op(OpId:DWORD):DWORD;
Function get_inverse_not_cmp_op(OpId:DWORD):DWORD;
@ -61,56 +41,11 @@ function flow_down_next_up(pLine:TSpirvOp):TSpirvOp;
function flow_down_prev_up(pLine:TSpirvOp):TSpirvOp;
function flow_prev_up(pLine:TSpirvOp):TSpirvOp;
function OpGetStr(pLine:TSpirvOp):RawByteString;
implementation
uses
srPrivate;
function OpGetStr(pLine:TSpirvOp):RawByteString;
var
V:PtrUint;
begin
Result:='';
if (pLine=nil) then Exit;
case pLine.OpId of
OpIAddExt:Result:='OpIAddExt';
OpISubExt:Result:='OpISubExt';
OpAbsDiff:Result:='OpAbsDiff';
OpWQM32 :Result:='OpWQM32';
OpBFE_32 :Result:='OpBFE_32';
OpBFIB32 :Result:='OpBFIB32';
OpPackAnc:Result:='OpPackAnc';
OpPackOfs:Result:='OpPackOfs';
OpMakeExp:Result:='OpMakeExp';
OpMakeVec:Result:='OpMakeVec';
OpMakeCub:Result:='OpMakeCub';
OpCUBEID :Result:='OpCUBEID';
OpCUBESC :Result:='OpCUBESC';
OpCUBETC :Result:='OpCUBETC';
OpCUBEMA :Result:='OpCUBEMA';
Op.OpExtInst:
begin
V:=0;
if pLine.ParamNode(1).TryGetValue(V) then
begin
Result:=GlslOp.GetStr(V);
end;
end;
else
begin
Result:=Op.GetStr(pLine.OpId);
end;
end;
end;
//--
function flow_down_next_up(pLine:TSpirvOp):TSpirvOp;

View File

@ -7,7 +7,6 @@ interface
uses
typinfo,
spirv,
ginodes,
srNode,
srType,
srOp,

View File

@ -298,8 +298,6 @@ end;
Procedure TsrPrivate.SetRegType(rtype:TsrDataType);
var
pTypeList:PsrTypeList;
node:TDependenceNode;
pLine:TspirvOp;
begin
pTypeList:=Emit.GetTypeList;
Ftype:=pTypeList^.Fetch(rtype);

View File

@ -25,10 +25,10 @@ type
SLC :Byte; //Volatile
function GetResultType:TsrDataType;
function GetElemType:TsrDataType;
function GetElemCount:Byte; inline;
function GetElemSize:Byte; inline;
function GetSizeFormat:Byte; inline;
function GetAlignSize:Byte; inline;
function GetElemCount:Byte;
function GetElemSize:Byte;
function GetSizeFormat:Byte;
function GetAlignSize:Byte;
function IsComp:Boolean;
function IsExtFormat:Boolean;
function GetImageFormat:Byte;
@ -191,17 +191,17 @@ begin
Result:=DFMT_ELEM_COUNT[DFMT];
end;
function TBuf_info.GetElemCount:Byte; inline;
function TBuf_info.GetElemCount:Byte;
begin
Result:=DFMT_ELEM_COUNT[DFMT];
end;
function TBuf_info.GetElemSize:Byte; inline;
function TBuf_info.GetElemSize:Byte;
begin
Result:=DFMT_ELEM_SIZE[DFMT];
end;
function TBuf_info.GetSizeFormat:Byte; inline;
function TBuf_info.GetSizeFormat:Byte;
begin
Result:=DFMT_SIZE[DFMT];
end;
@ -211,7 +211,7 @@ begin
if (a<b) then Result:=a else Result:=b;
end;
function TBuf_info.GetAlignSize:Byte; inline;
function TBuf_info.GetAlignSize:Byte;
begin
Result:=Min(4,GetSizeFormat);
end;