diff --git a/spirv/emit_post.pas b/spirv/emit_post.pas index ab6a0089..fa7786c1 100644 --- a/spirv/emit_post.pas +++ b/spirv/emit_post.pas @@ -51,7 +51,8 @@ type function OnChainUpdate(node:PsrChain):Integer; - function PostDataLayoutAnalize:Integer; + function PostDataLayoutAnalize1:Integer; + function PostDataLayoutAnalize2:Integer; function FetchField(var pChain:PsrChain;dtype:TsrDataType):PsrField; function OnChainField(node:PsrChain):Integer; function OnChainAlloc(node:PsrChain):Integer; @@ -576,35 +577,35 @@ begin repeat //OnOpStep2 repeat //OnOpStep1 - i:=EnumBlockOpBackward(@OnOpStep1,pFunc^.pTop); + i:=EnumBlockOpBackward(@OnOpStep1,pFunc^.pTop); //OnOpStep1 Reg Collapse if (i=0) then Break; Result:=Result+i; until false; - i:=EnumBlockOpForward(@OnOpStep2,pFunc^.pTop); + i:=EnumBlockOpForward(@OnOpStep2,pFunc^.pTop); //OnOpStep2 PostForward1 if (i=0) then Break; Result:=Result+i; until false; - i:=EnumBlockOpForward(@OnOpStep3,pFunc^.pTop); + i:=EnumBlockOpForward(@OnOpStep3,pFunc^.pTop); //OnOpStep3 PostForward2 if (i=0) then Break; Result:=Result+i; until false; if data_layout then begin - Result:=Result+PostDataLayoutAnalize; + Result:=Result+PostDataLayoutAnalize1; data_layout:=false; end; - repeat //OnOpStep4 + repeat //OnOpStep4 Volatile Reslove i:=EnumBlockOpForward(@OnOpStep4,pFunc^.pTop); if (i=0) then Break; Result:=Result+i; until false; r4:=0; - repeat //OnOpStep5 + repeat //OnOpStep5 Weak Reslove i:=EnumBlockOpBackward(@OnOpStep5,pFunc^.pTop); if (i=0) then Break; r4:=r4+i; @@ -614,17 +615,25 @@ begin Result:=Result+r4; until false; + PrivateList.RemoveAllStore; + + data_layout:=(Main=pFunc); + if data_layout then + begin + Result:=Result+PostDataLayoutAnalize2; + end; + //UpdateRegType OpLoad/OpStore DataLayoutList.EnumChain(@OnChainUpdate); PrivateList.Post; - repeat //OnOpStep6 + repeat //OnOpStep6 Typecast i:=EnumBlockOpBackward(@OnOpStep6,pFunc^.pTop); if (i=0) then Break; Result:=Result+i; until false; - Result:=Result+EnumBlockOpBackward(@OnOpStep7,pFunc^.pTop); + Result:=Result+EnumBlockOpBackward(@OnOpStep7,pFunc^.pTop); //OnOpStep7 Remove Lines pFunc:=pFunc^.Prev; end; @@ -636,13 +645,18 @@ begin node^.UpdateRegType; end; -function TSprvEmit_post.PostDataLayoutAnalize:Integer; +function TSprvEmit_post.PostDataLayoutAnalize1:Integer; begin Result:=0; DataLayoutList.AllocID; Result:=Result+DataLayoutList.EnumChain(@OnChainField); +end; + +function TSprvEmit_post.PostDataLayoutAnalize2:Integer; +begin + Result:=0; BufferList.ApplyBufferType; BufferList.AlignOffset; @@ -773,7 +787,8 @@ begin begin node^.dtype:=pField^.dtype; end; - pField^.pBuffer^.TakeChain(node); + //pField^.pBuffer^.TakeChain(node); + node^.pBuffer:=pField^.pBuffer; end; procedure TSprvEmit_post.OnFieldType(node:PsrField); diff --git a/spirv/emit_sop2.pas b/spirv/emit_sop2.pas index 083720d2..1e71ff1c 100644 --- a/spirv/emit_sop2.pas +++ b/spirv/emit_sop2.pas @@ -25,6 +25,7 @@ type procedure emit_S_AND_B64; procedure emit_S_ANDN2_B64; procedure emit_S_OR_B64; + procedure emit_S_ORN2_B64; procedure emit_S_NOR_B64; procedure emit_S_CSELECT_B32; procedure emit_S_CSELECT_B64; @@ -177,6 +178,28 @@ begin OpLogicalOr(get_scc,src2[0],src2[1]); //implict cast (int != 0) end; +procedure TEmit_SOP2.emit_S_ORN2_B64; //SCC = (sdst[2] != 0) +Var + dst:array[0..1] of PsrRegSlot; + src0,src1,src2:array[0..1] of PsrRegNode; +begin + if not get_sdst7_pair(FSPI.SOP2.SDST,@dst) then Assert(False); + + if not fetch_ssrc9_pair(FSPI.SOP2.SSRC0,@src0,dtUInt32) then Assert(False); + if not fetch_ssrc9_pair(FSPI.SOP2.SSRC1,@src1,dtUInt32) then Assert(False); + + src1[0]:=OpNotTo(src1[0]); + src1[1]:=OpNotTo(src1[1]); + + OpBitwiseOr(dst[0],src0[0],src1[0]); + OpBitwiseOr(dst[1],src0[1],src1[1]); + + src2[0]:=dst[0]^.current; + src2[1]:=dst[1]^.current; + + OpLogicalOr(get_scc,src2[0],src2[1]); //implict cast (int != 0) +end; + procedure TEmit_SOP2.emit_S_NOR_B64; //SCC = (sdst[2] != 0) Var dst:array[0..1] of PsrRegSlot; @@ -270,6 +293,8 @@ begin S_OR_B64: emit_S_OR_B64; + S_ORN2_B64: emit_S_ORN2_B64; + S_NOR_B64: emit_S_NOR_B64; S_CSELECT_B32: emit_S_CSELECT_B32; diff --git a/spirv/srBuffer.pas b/spirv/srBuffer.pas index 3c9e4272..eeac1cb4 100644 --- a/spirv/srBuffer.pas +++ b/spirv/srBuffer.pas @@ -11,6 +11,7 @@ uses srNode, srType, srTypes, + srReg, srVariable, srLayout, srDecorate, @@ -18,6 +19,9 @@ uses type ntBuffer=class(ntDescriptor) + class Procedure add_read (node,src:PsrNode); override; + class Procedure rem_read (node,src:PsrNode); override; + // class Function pwrite_count (node:PsrNode):PDWORD; override; class function GetStorageName(node:PsrNode):RawByteString; override; end; @@ -83,12 +87,11 @@ type pLeft,pRight:PsrBuffer; //---- fwrite_count:DWORD; - fchain_read :DWORD; - fchain_write:DWORD; // align_offset:DWORD; FEmit:TCustomEmit; + FDList:TRegDNodeList; bType:TsrBufferType; @@ -101,12 +104,15 @@ type function c(n1,n2:PsrBuffer):Integer; static; Procedure Init(Emit:TCustomEmit); inline; + Procedure AddDep(t:PsrNode); + Procedure RemDep(t:PsrNode); + function chain_read :DWORD; + function chain_write:DWORD; function GetStorageName:RawByteString; function GetTypeChar:Char; function GetString:RawByteString; function GetStructName:RawByteString; function GetSize:PtrUint; - procedure TakeChain(node:PsrChain); procedure EnumAllField(cb:TFieldEnumCb); procedure ShiftOffset(Offset:PtrUint); end; @@ -142,6 +148,26 @@ type implementation +class Procedure ntBuffer.add_read(node,src:PsrNode); +begin + inherited; + if src^.IsType(ntChain) then + begin + PsrBuffer(node)^.AddDep(src); + end; +end; + +class Procedure ntBuffer.rem_read(node,src:PsrNode); +begin + inherited; + if src^.IsType(ntChain) then + begin + PsrBuffer(node)^.RemDep(src); + end; +end; + +// + class Function ntBuffer.pwrite_count(node:PsrNode):PDWORD; begin Result:=@PsrBuffer(node)^.fwrite_count; @@ -541,6 +567,83 @@ begin FTop.dtype:=dtTypeStruct; end; +Procedure TsrBuffer.AddDep(t:PsrNode); +var + pRegsStory:PsrRegsStory; + node:PRegDNode; +begin + if (t=nil) or (@Self=nil) then Exit; + + pRegsStory:=FEmit.GetRegsStory; + node:=pRegsStory^.AllocDep; + + node^.pNode:=t; + FDList.Push_head(node); +end; + +Procedure TsrBuffer.RemDep(t:PsrNode); +var + pRegsStory:PsrRegsStory; + node,_prev:PRegDNode; +begin + if (t=nil) or (@Self=nil) then Exit; + node:=FDList.pHead; + _prev:=nil; + While (node<>nil) do + begin + if (node^.pNode=t) then + begin + if (_prev=nil) then + begin + FDList.pHead:=node^.pNext; + end else + begin + _prev^.pNext:=node^.pNext; + end; + + pRegsStory:=FEmit.GetRegsStory; + pRegsStory^.FreeDep(node); + + Exit; + end; + _prev:=node; + node:=node^.pNext; + end; + Assert(false,'not found!'); +end; + +function TsrBuffer.chain_read:DWORD; +var + node:PRegDNode; +begin + Result:=0; + node:=FDList.pHead; + While (node<>nil) do + begin + if node^.pNode^.IsType(ntChain) then + begin + Result:=Result+PsrChain(node^.pNode)^.read_count; + end; + node:=node^.pNext; + end; +end; + +function TsrBuffer.chain_write:DWORD; +var + node:PRegDNode; +begin + Result:=0; + node:=FDList.pHead; + While (node<>nil) do + begin + if node^.pNode^.IsType(ntChain) then + begin + Result:=Result+PsrChain(node^.pNode)^.write_count; + end; + node:=node^.pNext; + end; +end; + function TsrBuffer.GetStorageName:RawByteString; begin Result:=''; @@ -587,16 +690,6 @@ begin Result:=FTop.GetSize; end; -procedure TsrBuffer.TakeChain(node:PsrChain); -begin - if (@Self=nil) or (node=nil) then Exit; - - mark_read(node); - - fchain_read :=fchain_read +node^.read_count; - fchain_write:=fchain_write+node^.write_count; -end; - procedure TsrBuffer.EnumAllField(cb:TFieldEnumCb); var curr,node:PsrField; @@ -806,6 +899,7 @@ procedure TsrBufferList.ApplyBufferType; var pConfig:PsrConfig; node:PsrBuffer; + fchain_write:DWORD; begin pConfig:=FEmit.GetConfig; @@ -825,15 +919,17 @@ begin if node^.IsUsed and (node^.bType=btStorageBuffer) then begin + fchain_write:=node^.chain_write; + if (FPushConstant=nil) and - (node^.fchain_write=0) and + (fchain_write=0) and (node^.GetSize<=pConfig^.maxPushConstantsSize) then begin node^.bType :=btPushConstant; node^.FStorage:=StorageClass.PushConstant; FPushConstant :=node; end else - if (node^.fchain_write=0) and + if (fchain_write=0) and (node^.GetSize<=pConfig^.maxUniformBufferRange) then begin node^.bType :=btUniformBuffer; @@ -941,11 +1037,11 @@ begin if node^.IsUsed and (node^.pVar<>nil) then if (node^.bType=btStorageBuffer) then begin - if (node^.fchain_read=0) then + if (node^.chain_read=0) then begin pDecorateList^.OpDecorate(node^.pVar,Decoration.NonReadable,0); end; - if (node^.fchain_write=0) then + if (node^.chain_write=0) then begin pDecorateList^.OpDecorate(node^.pVar,Decoration.NonWritable,0); end; diff --git a/spirv/srLayout.pas b/spirv/srLayout.pas index e0a8ba0c..cc4d6ca6 100644 --- a/spirv/srLayout.pas +++ b/spirv/srLayout.pas @@ -37,6 +37,9 @@ type class Procedure zero_read (node:PsrNode); override; class Procedure zero_unread (node:PsrNode); override; class Function pwrite_count(node:PsrNode):PDWORD; override; + class Procedure SetWriter (node,w,line:PsrNode); override; + class Procedure ResetWriter (node,w:PsrNode); override; + class function Down (node:PsrNode):Pointer; override; class function Next (node:PsrNode):Pointer; override; class function Prev (node:PsrNode):Pointer; override; class function Parent (node:PsrNode):Pointer; override; @@ -81,19 +84,26 @@ type lvl_1:TsrChainLvl_1; lvl_0:TsrChainLvl_0; end; + FBuffer:PsrNode; + FWriter:PsrNode; Fdtype:TsrDataType; FList:TNodeList; function c(n1,n2:PsrChain):Integer; static; + Procedure SetWriter(t:PsrNode); + Function GetWriter:PsrNode; + Procedure SetBuffer(t:PsrNode); + Function GetBuffer:PsrNode; Procedure SetRegType(rtype:TsrDataType); public pField:Pointer; - //pLine:Pointer; property Parent:PsrDataLayout read FParent; property pIndex:PsrRegNode read key.lvl_1.pIndex; property stride:PtrUint read key.lvl_1.stride; property size :PtrUint read key.lvl_0.size; property offset:PtrUint read key.lvl_0.offset; property dtype:TsrDataType read Fdtype write SetRegType; + property pWriter:PsrNode read GetWriter write SetWriter; + property pBuffer:PsrNode read GetBuffer write SetBuffer; Procedure Init(L:PsrDataLayout); function Emit:TCustomEmit; Procedure UpdateRegType; @@ -197,6 +207,7 @@ begin With PsrChain(node)^ do begin key.lvl_1.pIndex^.mark_read(node); + FBuffer^.mark_read(node); end; end; @@ -205,6 +216,7 @@ begin With PsrChain(node)^ do begin key.lvl_1.pIndex^.mark_unread(node); + FBuffer^.mark_unread(node); end; end; @@ -213,6 +225,28 @@ begin Result:=@PsrChain(node)^.fwrite_count; end; +class Procedure ntChain.SetWriter(node,w,line:PsrNode); +begin + With PsrChain(node)^ do + begin + SetWriter(w); + end; +end; + +class Procedure ntChain.ResetWriter(node,w:PsrNode); +begin + With PsrChain(node)^ do + if (FWriter=w) then + begin + SetWriter(nil); + end; +end; + +class function ntChain.Down(node:PsrNode):Pointer; +begin + Result:=PsrChain(node)^.FWriter; +end; + class function ntChain.Next(node:PsrNode):Pointer; begin Result:=PsrChain(node)^.FParent^.NextChain(PsrChain(node)); @@ -620,6 +654,46 @@ begin Result:=FParent^.FEmit; end; +Procedure TsrChain.SetWriter(t:PsrNode); +begin + if (@Self=nil) then Exit; + if (FWriter=t) then Exit; + + if isUsed then + begin + t^.mark_read (@Self); + FWriter^.mark_unread(@Self); + end; + FWriter:=t; +end; + +Function TsrChain.GetWriter:PsrNode; +begin + Result:=nil; + if (@Self=nil) then Exit; + Result:=FWriter; +end; + +Procedure TsrChain.SetBuffer(t:PsrNode); +begin + if (@Self=nil) then Exit; + if (FBuffer=t) then Exit; + + if isUsed then + begin + t^.mark_read (@Self); + FBuffer^.mark_unread(@Self); + end; + FBuffer:=t; +end; + +Function TsrChain.GetBuffer:PsrNode; +begin + Result:=nil; + if (@Self=nil) then Exit; + Result:=FBuffer; +end; + Procedure TsrChain.SetRegType(rtype:TsrDataType); var pTypeList:PsrTypeList; @@ -820,7 +894,8 @@ end; procedure TsrDescriptor.SetType(t:PsrType); begin if (FType=t) then Exit; - if not IsUsed then + + if isUsed then begin t^.mark_read (@Self); FType^.mark_unread(@Self); diff --git a/spirv/srNode.pas b/spirv/srNode.pas index d42e8d9d..ecde8e37 100644 --- a/spirv/srNode.pas +++ b/spirv/srNode.pas @@ -133,7 +133,7 @@ end; class Procedure TsrNodeVmt.rem_read(node,src:PsrNode); begin - Assert(node^.fread_count<>0); + Assert(node^.fread_count<>0,node^.ntype.ClassName); if (node^.fread_count=0) then Exit; Dec(node^.fread_count); end; diff --git a/spirv/srPrivate.pas b/spirv/srPrivate.pas index 0f414244..5cb794fb 100644 --- a/spirv/srPrivate.pas +++ b/spirv/srPrivate.pas @@ -78,7 +78,6 @@ type Procedure SetRegType(rtype:TsrDataType); function GetRegType:TsrDataType; public - //FVolatile:TsrVolatile; property dtype:TsrDataType read GetRegType write SetRegType; property Source:PsrRegSlot read FSource; Procedure Init; inline; @@ -118,6 +117,7 @@ type procedure make_copy_slot(pSlot:PsrRegSlot); procedure make_copy_all; procedure PrepVolatile(dst:PspirvOp;src:PsrRegNode); + Procedure RemoveAllStore; Procedure Post; end; @@ -192,7 +192,8 @@ end; Function TsrVolatile.PopStore:PVNode; begin Result:=FList.Pop_head; - if (Result<>nil) and IsUsed then + if (Result<>nil) then + if IsUsed then begin Result^.pReg^.mark_unread(@Self); end; @@ -554,8 +555,6 @@ begin Result:=FEmit.Alloc(SizeOf(TsrPrivate)); Move(node,Result^,SizeOf(TsrPrivate)); // - //Result^.FVolatile.Init(Result); - // FNTree.Insert(Result); end; end; @@ -605,13 +604,12 @@ begin end; pPrivate :=Fetch(pSlot); - //pVolatile:=@pPrivate^.FVolatile; pVolatile:=pPrivate^.NewVolatile; rtype:=dtUnknow; if (old<>nil) then - //if (old^.pWriter^.AsType(ntVolatile)<>pVolatile) then + //if (pVolatile<>old^.pWriter^.AsType(ntVolatile)) then //if not old^.pWriter^.IsType(ntVolatile) then begin pVolatile^.AddStore(old); @@ -619,7 +617,7 @@ begin end; // if (cur<>nil) then - //if (cur^.pWriter^.AsType(ntVolatile)<>pVolatile) then + //if (pVolatile<>cur^.pWriter^.AsType(ntVolatile)) then //if not cur^.pWriter^.IsType(ntVolatile) then begin pVolatile^.AddStore(cur); @@ -667,7 +665,6 @@ begin end; pPrivate :=Fetch(pSlot); - //pVolatile:=@pPrivate^.FVolatile; pVolatile:=pPrivate^.NewVolatile; //if (pVolatile<>prv^.pWriter^.AsType(ntVolatile)) then @@ -686,6 +683,7 @@ begin end else if (cur<>nil) then begin + //prev is unresolve new:=pSlot^.New(cur^.pLine,cur^.dtype); new^.pWriter:=pVolatile; FEmit.PostLink(FEmit.curr_line,new); //post processing @@ -849,6 +847,18 @@ begin pPrivate^.FetchLoad(pLine,src); //before reg end; +Procedure TsrPrivateList.RemoveAllStore; +var + node:PsrPrivate; +begin + node:=FNTree.Min; + While (node<>nil) do + begin + node^.RemoveAllStore; + node:=FNTree.Next(node); + end; +end; + Procedure TsrPrivateList.Post; var node:PsrPrivate; @@ -858,7 +868,6 @@ begin begin if node^.IsUsed then begin - node^.RemoveAllStore; node^.SortLines; node^.Optimize; node^.UpdateRegType; diff --git a/spirv/srReg.pas b/spirv/srReg.pas index 9818ddea..c2608523 100644 --- a/spirv/srReg.pas +++ b/spirv/srReg.pas @@ -57,7 +57,6 @@ type FSlot:PsrRegSlot; FWriter:PsrNode; //ntReg,ntConst,ntOp,ntVolatile FDList:TRegDNodeList; - FLine:Pointer; Procedure AddDep(t:PsrNode); Procedure RemDep(t:PsrNode); function GetDtype:TsrDataType; @@ -66,9 +65,8 @@ type Procedure SetWeak(t:Boolean); Procedure SetWriter(t:PsrNode); Function GetWriter:PsrNode; - Procedure SetLine(t:Pointer); public - property pLine :Pointer read FLine write SetLine; //PspirvOp; + pLine:Pointer; //PspirvOp; property pSlot :PsrRegSlot read FSlot; property dtype :TsrDataType read GetDtype write SetDtype; property Weak :Boolean read GetWeak write SetWeak; @@ -630,6 +628,7 @@ begin _prev:=node; node:=node^.pNext; end; + Assert(false,'not found!'); end; function TsrRegNode.FirstDep:PRegDNode; @@ -681,17 +680,6 @@ begin Result:=FWriter; end; -Procedure TsrRegNode.SetLine(t:Pointer); -begin - if (@Self=nil) then Exit; - if (FWriter<>nil) then - if (FWriter^.ntype.ClassName='ntOp') then - begin - Assert(FWriter=t); - end; - FLine:=t; -end; - function TsrRegNode.AsConst:PsrConst; begin if (@Self=nil) then Exit(nil); diff --git a/src/ps4_libscedialogs.pas b/src/ps4_libscedialogs.pas index 170bc989..77f54665 100644 --- a/src/ps4_libscedialogs.pas +++ b/src/ps4_libscedialogs.pas @@ -280,6 +280,25 @@ begin Result:=status_msg_dialog; end; +type + pSceMsgDialogResult=^SceMsgDialogResult; + SceMsgDialogResult=packed record + mode:Integer; //SceMsgDialogMode + result:Integer; + buttonId:Integer; //SceMsgDialogButtonId + reserved:array[0..31] of Byte; + end; + +function ps4_sceMsgDialogGetResult(pResult:pSceMsgDialogResult):Integer; SysV_ABI_CDecl; +begin + if (pResult<>nil) then + begin + pResult^.result:=0; + pResult^.buttonId:=1; + end; + Result:=0; +end; + function ps4_sceMsgDialogTerminate():Integer; SysV_ABI_CDecl; begin status_msg_dialog:=SCE_COMMON_DIALOG_STATUS_NONE; @@ -482,6 +501,7 @@ begin lib^.set_proc($1D3ADC0CA9452AE3,@ps4_sceMsgDialogClose); lib^.set_proc($E9F202DD72ADDA4D,@ps4_sceMsgDialogUpdateStatus); lib^.set_proc($096556EFC41CDDF2,@ps4_sceMsgDialogGetStatus); + lib^.set_proc($2EBF28BC71FD97A0,@ps4_sceMsgDialogGetResult); lib^.set_proc($78FC3F92A6667A5A,@ps4_sceMsgDialogTerminate); end;