FPPS4/spirv/srRefId.pas

87 lines
1.5 KiB
Plaintext
Raw Normal View History

2022-05-31 07:17:14 +00:00
unit srRefId;
{$mode objfpc}{$H+}
interface
2022-09-05 13:30:24 +00:00
uses
sysutils,
srNode;
2022-05-31 07:17:14 +00:00
type
2022-09-05 13:30:24 +00:00
ntRefId=class(TsrNodeVmt)
class function GetPrintName(node:PsrNode):RawByteString; override;
class function GetRef(node:PsrNode):Pointer; override;
end;
2022-05-31 07:17:14 +00:00
PsrRefId=^TsrRefId;
2022-09-05 13:30:24 +00:00
TsrRefId=object
2022-05-31 07:17:14 +00:00
ID:DWORD;
2022-09-05 13:30:24 +00:00
function Alloc:Boolean; inline;
end;
PsrRefNode=^TsrRefNode;
TsrRefNode=object(TsrNode)
ID:TsrRefId;
Procedure Init; inline;
function GetPrintName:RawByteString;
2022-05-31 07:17:14 +00:00
end;
PsrRefIdAlloc=^TsrRefIdAlloc;
TsrRefIdAlloc=object
FSpirvID:DWORD;
function FetchSpirvID:DWORD; inline;
procedure FetchSpirvID(P:PsrRefId);
function GetSpirvIDBound:DWORD; inline;
end;
implementation
2022-09-05 13:30:24 +00:00
class function ntRefId.GetPrintName(node:PsrNode):RawByteString;
begin
Result:=PsrRefNode(node)^.GetPrintName;
end;
class function ntRefId.GetRef(node:PsrNode):Pointer;
begin
Result:=@PsrRefNode(node)^.ID;
end;
Procedure TsrRefNode.Init; inline;
begin
fntype:=ntRefId;
end;
function TsrRefNode.GetPrintName:RawByteString;
begin
Assert(ID.ID<>0);
Result:=IntToStr(ID.ID);
end;
2022-05-31 07:17:14 +00:00
function TsrRefId.Alloc:Boolean; inline;
begin
Result:=(ID<>0);
end;
function TsrRefIdAlloc.FetchSpirvID:DWORD; inline;
begin
Inc(FSpirvID);
Result:=FSpirvID;
end;
procedure TsrRefIdAlloc.FetchSpirvID(P:PsrRefId);
begin
if (P<>nil) and (not P^.Alloc) then
begin
P^.ID:=FetchSpirvID;
end;
end;
function TsrRefIdAlloc.GetSpirvIDBound:DWORD; inline;
begin
Result:=FSpirvID+1;
end;
end.