fpPS4/spirv/srVariable.pas

242 lines
5.0 KiB
ObjectPascal
Raw Normal View History

2022-05-31 07:17:14 +00:00
unit srVariable;
{$mode ObjFPC}{$H+}
interface
uses
2022-09-05 13:30:24 +00:00
sysutils,
ginodes,
srNode,
srTypes,
srRefId,
srDecorate;
2022-05-31 07:17:14 +00:00
type
2022-09-05 13:30:24 +00:00
ntVariable=class(TsrNodeVmt)
class Procedure zero_read (node:PsrNode); override;
class Procedure zero_unread (node:PsrNode); override;
class Function pwrite_count (node:PsrNode):PDWORD; override;
class Function GetStorageClass(node:PsrNode):DWORD; override;
class function GetStorageName (node:PsrNode):RawByteString; override;
class function Down (node:PsrNode):Pointer; override;
class function Next (node:PsrNode):Pointer; override;
class function Prev (node:PsrNode):Pointer; override;
class Procedure PrepType (node:PPrepTypeNode); override;
class Function GetPtype (node:PsrNode):PsrNode; override;
class function GetPrintName (node:PsrNode):RawByteString; override;
class function GetRef (node:PsrNode):Pointer; override;
end;
2022-05-31 07:17:14 +00:00
2022-09-05 13:30:24 +00:00
PsrVariable=^TsrVariable;
TsrVariable=packed object(TsrNode)
private
pPrev,pNext:PsrVariable;
//
fwrite_count:DWORD;
ID:TsrRefId; //post id
FType:PsrType;
FSource:PsrNode; //ntInput,ntVertLayout,ntFragLayout,ntUniform,ntBuffer,ntOutput
procedure SetType(t:PsrType);
procedure SetSource(t:PsrNode);
public
property pSource:PsrNode read FSource write SetSource;
procedure UpdateType(Emit:TCustomEmit);
Procedure Init; inline;
function GetPrintName:RawByteString;
2022-05-31 07:17:14 +00:00
end;
2022-09-05 13:30:24 +00:00
PsrVariableList=^TsrVariableList;
TsrVariableList=object
type
TNodeList=specialize TNodeList<PsrVariable>;
var
FEmit:TCustomEmit;
FList:TNodeList;
procedure Init(Emit:TCustomEmit); inline;
function Fetch:PsrVariable;
function First:PsrVariable; inline;
procedure AllocName;
end;
2022-05-31 07:17:14 +00:00
implementation
2022-09-05 13:30:24 +00:00
class Procedure ntVariable.zero_read(node:PsrNode);
begin
With PsrVariable(node)^ do
begin
FType^.mark_read(@Self);
end;
end;
class Procedure ntVariable.zero_unread(node:PsrNode);
begin
With PsrVariable(node)^ do
begin
FType^.mark_unread(@Self);
end;
end;
class Function ntVariable.pwrite_count(node:PsrNode):PDWORD;
begin
Result:=@PsrVariable(node)^.fwrite_count;
end;
class Function ntVariable.GetStorageClass(node:PsrNode):DWORD;
begin
Result:=inherited;
With PsrVariable(node)^ do
if (FSource<>nil) then
if (FSource^.ntype<>nil) then
begin
Result:=FSource^.ntype.GetStorageClass(FSource);
end;
end;
class function ntVariable.GetStorageName(node:PsrNode):RawByteString;
begin
Result:=inherited;
With PsrVariable(node)^ do
if (FSource<>nil) then
if (FSource^.ntype<>nil) then
begin
Result:=FSource^.ntype.GetStorageName(FSource);
end;
end;
class function ntVariable.Down(node:PsrNode):Pointer;
begin
Result:=PsrVariable(node)^.FSource;
end;
class function ntVariable.Next(node:PsrNode):Pointer;
begin
Result:=PsrVariable(node)^.pNext;
end;
class function ntVariable.Prev(node:PsrNode):Pointer;
begin
Result:=PsrVariable(node)^.pPrev;
end;
class Procedure ntVariable.PrepType(node:PPrepTypeNode);
begin
node^.dnode:=PsrVariable(node^.dnode)^.FSource;
end;
class Function ntVariable.GetPtype(node:PsrNode):PsrNode;
begin
Result:=PsrVariable(node)^.FType;
end;
class function ntVariable.GetPrintName(node:PsrNode):RawByteString;
begin
Result:=PsrVariable(node)^.GetPrintName;
end;
2022-05-31 07:17:14 +00:00
2022-09-05 13:30:24 +00:00
class function ntVariable.GetRef(node:PsrNode):Pointer;
2022-05-31 07:17:14 +00:00
begin
2022-09-05 13:30:24 +00:00
Result:=@PsrVariable(node)^.ID;
2022-05-31 07:17:14 +00:00
end;
2022-09-05 13:30:24 +00:00
//
Procedure TsrVariable.Init; inline;
2022-05-31 07:17:14 +00:00
begin
2022-09-05 13:30:24 +00:00
fntype:=ntVariable;
2022-05-31 07:17:14 +00:00
end;
2022-09-05 13:30:24 +00:00
procedure TsrVariable.SetType(t:PsrType);
2022-05-31 07:17:14 +00:00
begin
2022-09-05 13:30:24 +00:00
if (FType=t) then Exit;
if IsUsed then
begin
t^.mark_read (@Self);
FType^.mark_unread(@Self);
end;
FType:=t;
2022-05-31 07:17:14 +00:00
end;
2022-09-05 13:30:24 +00:00
procedure TsrVariable.UpdateType(Emit:TCustomEmit);
var
_Type:PsrType;
pTypeList:PsrTypeList;
2022-05-31 07:17:14 +00:00
begin
2022-09-05 13:30:24 +00:00
if (@Self=nil) then Exit;
_Type:=FSource^.pType;
if (_Type=nil) then
begin
SetType(nil);
end else
begin
pTypeList:=Emit.GetTypeList;
_Type:=pTypeList^.FetchPointer(_Type,FSource^.GetStorageClass);
SetType(_Type);
2022-05-31 07:17:14 +00:00
end;
end;
2022-09-05 13:30:24 +00:00
procedure TsrVariable.SetSource(t:PsrNode);
2022-05-31 07:17:14 +00:00
begin
2022-09-05 13:30:24 +00:00
if (FSource=t) then Exit;
if IsUsed then
2022-05-31 07:17:14 +00:00
begin
2022-09-05 13:30:24 +00:00
t^.mark_read (@Self);
FSource^.mark_unread(@Self);
2022-05-31 07:17:14 +00:00
end;
2022-09-05 13:30:24 +00:00
FSource:=t;
end;
function TsrVariable.GetPrintName:RawByteString;
begin
Result:=GetStorageName;
if (Result='') then
2022-05-31 07:17:14 +00:00
begin
2022-09-05 13:30:24 +00:00
Assert(ID.Alloc);
Result:='v'+IntToStr(ID.ID);
2022-05-31 07:17:14 +00:00
end;
end;
2022-09-05 13:30:24 +00:00
//
procedure TsrVariableList.Init(Emit:TCustomEmit); inline;
begin
FEmit:=Emit;
end;
function TsrVariableList.Fetch:PsrVariable;
begin
Result:=FEmit.Alloc(SizeOf(TsrVariable));
Result^.Init;
FList.Push_tail(Result);
end;
function TsrVariableList.First:PsrVariable; inline;
begin
Result:=FList.pHead;
end;
procedure TsrVariableList.AllocName;
var
FDebugInfo:PsrDebugInfoList;
node:PsrVariable;
n:RawByteString;
2022-05-31 07:17:14 +00:00
begin
2022-09-05 13:30:24 +00:00
FDebugInfo:=FEmit.GetDebugInfoList;
node:=First;
While (node<>nil) do
2022-05-31 07:17:14 +00:00
begin
2022-09-05 13:30:24 +00:00
if (node^.pType<>nil) then
begin
n:=node^.GetStorageName;
if (n<>'') then
begin
FDebugInfo^.OpName(node,n);
end;
2022-05-31 07:17:14 +00:00
end;
2022-09-05 13:30:24 +00:00
node:=node^.Next;
2022-05-31 07:17:14 +00:00
end;
end;
end.