fpPS4/spirv/srVertLayout.pas

190 lines
3.7 KiB
ObjectPascal
Raw Permalink Normal View History

2022-05-31 07:17:14 +00:00
unit srVertLayout;
{$mode ObjFPC}{$H+}
interface
uses
2022-09-05 13:30:24 +00:00
sysutils,
spirv,
ginodes,
srNode,
srType,
srReg,
srOp,
srVariable,
srLayout,
srDecorate;
2022-05-31 07:17:14 +00:00
type
2022-09-05 13:30:24 +00:00
ntVertLayout=class(ntDescriptor)
class function GetStorageName(node:PsrNode):RawByteString; override;
end;
2022-05-31 07:17:14 +00:00
PsrVertLayout=^TsrVertLayout;
TsrVertLayout=object(TsrDescriptor)
2024-02-27 09:57:19 +00:00
public
2022-09-05 13:30:24 +00:00
pLeft,pRight:PsrVertLayout;
function c(n1,n2:PsrVertLayout):Integer; static;
2024-02-27 09:57:19 +00:00
private
pLayout:PsrDataLayout;
2022-09-05 13:30:24 +00:00
public
pReg:PsrRegNode;
procedure Init(p:PsrDataLayout); inline;
function GetString:RawByteString;
function GetStorageName:RawByteString;
2022-05-31 07:17:14 +00:00
end;
2022-09-05 13:30:24 +00:00
PsrVertLayoutList=^TsrVertLayoutList;
2022-05-31 07:17:14 +00:00
TsrVertLayoutList=object
type
TNodeFetch=specialize TNodeFetch<PsrVertLayout,TsrVertLayout>;
var
2022-09-05 13:30:24 +00:00
FEmit:TCustomEmit;
2022-05-31 07:17:14 +00:00
FNTree:TNodeFetch;
2022-09-05 13:30:24 +00:00
procedure Init(Emit:TCustomEmit); inline;
function Fetch(p:PsrDataLayout;rtype:TsrDataType):PsrVertLayout;
2022-05-31 07:17:14 +00:00
Function First:PsrVertLayout;
Function Next(node:PsrVertLayout):PsrVertLayout;
2022-09-05 13:30:24 +00:00
procedure AllocBinding;
2022-05-31 07:17:14 +00:00
procedure AllocEntryPoint(EntryPoint:PSpirvOp);
2022-09-05 13:30:24 +00:00
procedure AllocSourceExtension;
2022-05-31 07:17:14 +00:00
end;
implementation
2022-09-05 13:30:24 +00:00
class function ntVertLayout.GetStorageName(node:PsrNode):RawByteString;
begin
Result:=PsrVertLayout(node)^.GetStorageName;
end;
//
2022-05-31 07:17:14 +00:00
function TsrVertLayout.c(n1,n2:PsrVertLayout):Integer;
begin
Result:=Integer(n1^.pLayout>n2^.pLayout)-Integer(n1^.pLayout<n2^.pLayout);
2022-09-05 13:30:24 +00:00
end;
procedure TsrVertLayout.Init(p:PsrDataLayout); inline;
begin
fntype :=ntVertLayout;
FStorage:=StorageClass.Input;
FBinding:=-1;
pLayout :=p;
2022-05-31 07:17:14 +00:00
end;
function TsrVertLayout.GetString:RawByteString;
var
PID:DWORD;
begin
PID:=0;
if (pLayout<>nil) then
begin
PID:=pLayout^.FID;
end;
Result:='VA;PID='+HexStr(PID,8)+
';BND='+HexStr(FBinding,8);
end;
2022-09-05 13:30:24 +00:00
function TsrVertLayout.GetStorageName:RawByteString;
2022-05-31 07:17:14 +00:00
begin
Result:='atParam'+IntToStr(FBinding);
end;
2022-09-05 13:30:24 +00:00
procedure TsrVertLayoutList.Init(Emit:TCustomEmit); inline;
2022-05-31 07:17:14 +00:00
begin
2022-09-05 13:30:24 +00:00
FEmit:=Emit;
2022-05-31 07:17:14 +00:00
end;
2022-09-05 13:30:24 +00:00
function TsrVertLayoutList.Fetch(p:PsrDataLayout;rtype:TsrDataType):PsrVertLayout;
2022-05-31 07:17:14 +00:00
var
node:TsrVertLayout;
begin
node:=Default(TsrVertLayout);
2022-09-05 13:30:24 +00:00
node.Init(p);
2022-05-31 07:17:14 +00:00
Result:=FNTree.Find(@node);
if (Result=nil) then
begin
2022-09-05 13:30:24 +00:00
Result:=FEmit.Alloc(SizeOf(TsrVertLayout));
Move(node,Result^,SizeOf(TsrVertLayout));
//
Result^.InitType(rtype,FEmit);
Result^.InitVar(FEmit);
//
2022-05-31 07:17:14 +00:00
FNTree.Insert(Result);
end;
end;
Function TsrVertLayoutList.First:PsrVertLayout;
begin
Result:=FNTree.Min;
end;
Function TsrVertLayoutList.Next(node:PsrVertLayout):PsrVertLayout;
begin
Result:=FNTree.Next(node);
end;
2022-09-05 13:30:24 +00:00
procedure TsrVertLayoutList.AllocBinding;
2022-05-31 07:17:14 +00:00
var
2022-09-05 13:30:24 +00:00
pDecorateList:PsrDecorateList;
2022-05-31 07:17:14 +00:00
node:PsrVertLayout;
pVar:PsrVariable;
FBinding:Integer;
begin
2022-09-05 13:30:24 +00:00
pDecorateList:=FEmit.GetDecorateList;
2022-05-31 07:17:14 +00:00
FBinding:=0;
node:=First;
While (node<>nil) do
begin
pVar:=node^.pVar;
2022-09-05 13:30:24 +00:00
if (pVar<>nil) and node^.IsUsed and (node^.FBinding=-1) then
2022-05-31 07:17:14 +00:00
begin
2022-09-05 13:30:24 +00:00
pDecorateList^.OpDecorate(pVar,Decoration.Location,FBinding);
node^.FBinding:=FBinding;
Inc(FBinding);
2022-05-31 07:17:14 +00:00
end;
node:=Next(node);
end;
end;
procedure TsrVertLayoutList.AllocEntryPoint(EntryPoint:PSpirvOp);
var
node:PsrVertLayout;
pVar:PsrVariable;
begin
if (EntryPoint=nil) then Exit;
node:=First;
While (node<>nil) do
begin
pVar:=node^.pVar;
2022-09-05 13:30:24 +00:00
if (pVar<>nil) and node^.IsUsed then
2022-05-31 07:17:14 +00:00
begin
2022-09-05 13:30:24 +00:00
EntryPoint^.AddParam(pVar);
2022-05-31 07:17:14 +00:00
end;
node:=Next(node);
end;
end;
2022-09-05 13:30:24 +00:00
procedure TsrVertLayoutList.AllocSourceExtension;
2022-05-31 07:17:14 +00:00
var
2022-09-05 13:30:24 +00:00
FDebugInfo:PsrDebugInfoList;
2022-05-31 07:17:14 +00:00
node:PsrVertLayout;
pVar:PsrVariable;
begin
2022-09-05 13:30:24 +00:00
FDebugInfo:=FEmit.GetDebugInfoList;
2022-05-31 07:17:14 +00:00
node:=First;
While (node<>nil) do
begin
pVar:=node^.pVar;
2022-09-05 13:30:24 +00:00
if (pVar<>nil) and node^.IsUsed then
2022-05-31 07:17:14 +00:00
begin
2022-11-15 12:54:47 +00:00
FDebugInfo^.OpSource(node^.GetString);
2022-05-31 07:17:14 +00:00
end;
node:=Next(node);
end;
end;
end.