Shader recompiler bug fixes

This commit is contained in:
Pavel 2023-01-09 15:16:08 +03:00
parent 34c5f3bdbb
commit 29d0872599
3 changed files with 81 additions and 37 deletions

View File

@ -100,7 +100,7 @@ begin
$4:src[0]:=fetch_vsrc8(FSPI.EXP.VSRC2,dtFloat32);
$8:src[0]:=fetch_vsrc8(FSPI.EXP.VSRC3,dtFloat32);
else
Assert(false);
Assert(false,'FSPI.EXP.COMPR='+HexStr(f,1));
end;
dout:=FetchOutput(TpsslExportType(FSPI.EXP.TGT),dtFloat32); //output in FSPI.EXP.TGT
OpStore(line,dout,src[0]);
@ -112,7 +112,7 @@ begin
3:rtype:=dtVec3f;
4:rtype:=dtVec4f;
else
Assert(false,IntToStr(p));
Assert(false,'FSPI.EXP.COMPR='+HexStr(f,1));
end;
i:=0;
@ -158,13 +158,11 @@ begin
fetch_vsrc8_vec2h(FSPI.EXP.VSRC3,src[2],src[3]);
end;
else
Assert(false);
Assert(false,'FSPI.EXP.COMPR='+HexStr(f,1));
end;
if Config.UseOutput16 then
begin
dst:=OpMakeVec(line,dtVec4h,@src);
rtype:=dtVec4h;
end else
begin

View File

@ -819,6 +819,7 @@ end;
Function ReverseBits(src:QWORD;count:Byte):QWORD;
var
v:QWORD;
i:Byte;
begin
Result:=0;
@ -826,7 +827,8 @@ begin
dec(count);
For i:=0 to count do
begin
Result.Bits[i]:=src.Bits[count-i];
v:=((src shr i) and 1); //get
Result:=Result or (v shl (count-i)); //set
end;
end;
@ -1014,31 +1016,35 @@ end;
function TEmitPostOp.OnCompositeExtract1(node:PSpirvOp):Integer;
var
pc:PsrConst;
dst,src:PsrRegNode;
dst,org,src:PsrRegNode;
pos:PtrUint;
begin
Result:=0;
dst:=node^.pDst^.AsType(ntReg);
src:=RegDown(node^.ParamNode(0)^.AsReg);
org:=node^.ParamNode(0)^.AsReg;
src:=RegDown(org);
if (dst=nil) or (src=nil) then Exit;
pos:=0;
if not node^.ParamNode(1)^.TryGetValue(pos) then Exit;
if src^.is_const then
begin
pc:=src^.AsConst;
if (pos<pc^.ItemCount) then
begin
pc:=pc^.GetConst(pos);
dst^.pWriter:=pc;
if not src^.is_const then Exit;
node^.mark_not_used;
node^.pDst:=nil;
Inc(Result);
end;
end;
pc:=src^.AsConst;
pc:=ConstList.Bitcast(org^.dtype,pc);
if (pos>=pc^.ItemCount) then Exit;
pc:=pc^.GetConst(pos);
if (pc=nil) then Exit;
dst^.pWriter:=pc;
node^.mark_not_used;
node^.pDst:=nil;
Inc(Result);
end;
{

View File

@ -32,7 +32,9 @@ type
FNTree:TNodeFetch;
rSlot:TsrRegSlot;
procedure Init(Emit:TCustomEmit); inline;
function Find(dtype:TsrDataType;src:PsrRegNode):PsrBitcast;
function _Find(dtype:TsrDataType;src:PsrRegNode):PsrBitcast;
function Find(dtype:TsrDataType;src:PsrRegNode):PsrRegNode;
Procedure Save(dtype:TsrDataType;src,dst:PsrRegNode);
function FetchRead(dtype:TsrDataType;src:PsrRegNode):PsrRegNode;
function FetchDstr(dtype:TsrDataType;src:PsrRegNode):PsrRegNode;
function FetchCast(dtype:TsrDataType;src:PsrRegNode):PsrRegNode;
@ -54,7 +56,7 @@ begin
rSlot.Init(Emit,'BCAST');
end;
function TsrBitcastList.Find(dtype:TsrDataType;src:PsrRegNode):PsrBitcast;
function TsrBitcastList._Find(dtype:TsrDataType;src:PsrRegNode):PsrBitcast;
var
node:TsrBitcast;
begin
@ -64,16 +66,62 @@ begin
Result:=FNTree.Find(@node);
end;
function TsrBitcastList.Find(dtype:TsrDataType;src:PsrRegNode):PsrRegNode;
var
node:PsrBitcast;
begin
Result:=nil;
node:=_Find(dtype,src);
if (node<>nil) then
begin
Result:=node^.dst;
end;
end;
Procedure TsrBitcastList.Save(dtype:TsrDataType;src,dst:PsrRegNode);
var
node:PsrBitcast;
begin
node:=rSlot.Emit.Alloc(SizeOf(TsrBitcast));
node^:=Default(TsrBitcast);
node^.key.dtype:=dtype;
node^.key.src:=src;
node^.dst:=dst;
FNTree.Insert(node);
end;
function TsrBitcastList.FetchRead(dtype:TsrDataType;src:PsrRegNode):PsrRegNode;
var
pConstList:PsrConstList;
dst:PsrRegNode;
pConst:PsrConst;
begin
Result:=src;
if (src=nil) then Exit;
if (dtype=dtUnknow) or (dtype=src^.dtype) then Exit;
dst:=rSlot.New(src^.pLine,dtype);
dst^.pWriter:=src;
if src^.is_const then
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;
//
Save(dtype,src,dst);
end else
begin
dst:=rSlot.New(src^.pLine,dtype);
dst^.pWriter:=src;
end;
Result:=dst;
end;
@ -97,7 +145,6 @@ end;
function TsrBitcastList.FetchCast(dtype:TsrDataType;src:PsrRegNode):PsrRegNode;
var
pConstList:PsrConstList;
node:PsrBitcast;
dst:PsrRegNode;
pConst:PsrConst;
@ -108,12 +155,9 @@ begin
dst:=nil;
node:=Find(dtype,src);
if (node<>nil) then
begin
Result:=node^.dst;
Exit;
end;
//
dst:=Find(dtype,src);
if (dst<>nil) then Exit(dst);
if src^.is_const then
begin
@ -137,12 +181,8 @@ begin
end;
end;
node:=rSlot.Emit.Alloc(SizeOf(TsrBitcast));
node^:=Default(TsrBitcast);
node^.key.dtype:=dtype;
node^.key.src:=src;
node^.dst:=dst;
FNTree.Insert(node);
//
Save(dtype,src,dst);
Result:=dst;
end;