fpPS4/spirv/srDecorate.pas

186 lines
3.7 KiB
ObjectPascal
Raw Normal View History

2022-05-31 07:17:14 +00:00
unit srDecorate;
{$mode ObjFPC}{$H+}
interface
uses
spirv,
2022-11-15 12:54:47 +00:00
ginodes,
2022-09-05 13:30:24 +00:00
srNode,
2022-05-31 07:17:14 +00:00
srOp;
type
2022-09-05 13:30:24 +00:00
PsrHeaderList=^TsrHeaderList;
TsrHeaderList=object(TsrOpBlockCustom)
FGLSL_std_450:PSpirvOp;
function emit_glsl_ext:PSpirvOp;
end;
2022-11-15 12:54:47 +00:00
PsrDecorate=^TsrDecorate;
TsrDecorate=object
private
pLeft,pRight:PsrDecorate;
//----
key:packed record
data:PsrNode;
param:array[0..2] of DWORD;
end;
function c(n1,n2:PsrDecorate):Integer; static;
public
node:PSpirvOp;
end;
2022-05-31 07:17:14 +00:00
PsrDecorateList=^TsrDecorateList;
2022-09-05 13:30:24 +00:00
TsrDecorateList=object(TsrOpBlockCustom)
2022-11-15 12:54:47 +00:00
type
TNodeFetch=specialize TNodeFetch<PsrDecorate,TsrDecorate>;
var
FNTree:TNodeFetch;
function Fetch(data:PsrNode;param1,param2,param3:DWORD):PsrDecorate;
2022-09-05 13:30:24 +00:00
procedure OpDecorate(Data:PsrNode;dec_id,param:DWORD);
2022-11-15 12:54:47 +00:00
procedure OpMember (Data:PsrNode;index,offset:DWORD);
2022-05-31 07:17:14 +00:00
end;
PsrDebugInfoList=^TsrDebugInfoList;
2022-09-05 13:30:24 +00:00
TsrDebugInfoList=object(TsrOpBlockCustom)
2022-11-15 12:54:47 +00:00
procedure OpSource(const n:RawByteString);
procedure OpName (Data:PsrNode;const n:RawByteString);
2022-09-05 13:30:24 +00:00
function OpString(const n:RawByteString):PsrNode;
2022-05-31 07:17:14 +00:00
end;
implementation
2022-11-15 12:54:47 +00:00
//
2022-09-05 13:30:24 +00:00
function TsrHeaderList.emit_glsl_ext:PSpirvOp;
begin
if (FGLSL_std_450=nil) then
begin
FGLSL_std_450:=AddSpirvOp(Op.OpExtInstImport);
FGLSL_std_450^.pDst:=Emit.NewRefNode;
FGLSL_std_450^.AddString('GLSL.std.450');
end;
Result:=FGLSL_std_450;
end;
2022-11-15 12:54:47 +00:00
//
function TsrDecorate.c(n1,n2:PsrDecorate):Integer;
var
i:Byte;
begin
//first data
Result:=Integer(n1^.key.data>n2^.key.data)-Integer(n1^.key.data<n2^.key.data);
if (Result<>0) then Exit;
//param[i]
For i:=0 to 2 do
begin
Result:=Integer(n1^.key.param[i]>n2^.key.param[i])-Integer(n1^.key.param[i]<n2^.key.param[i]);
if (Result<>0) then Exit;
end;
end;
//
function TsrDecorateList.Fetch(data:PsrNode;param1,param2,param3:DWORD):PsrDecorate;
var
node:TsrDecorate;
begin
node:=Default(TsrDecorate);
node.key.data:=data;
node.key.param[0]:=param1;
node.key.param[1]:=param2;
node.key.param[2]:=param3;
Result:=FNTree.Find(@node);
if (Result=nil) then
begin
Result:=Emit.Alloc(SizeOf(TsrDecorate));
Move(node,Result^,SizeOf(TsrDecorate));
FNTree.Insert(Result);
end;
end;
2022-09-05 13:30:24 +00:00
procedure TsrDecorateList.OpDecorate(Data:PsrNode;dec_id,param:DWORD);
2022-05-31 07:17:14 +00:00
var
2022-11-15 12:54:47 +00:00
deco:PsrDecorate;
2022-05-31 07:17:14 +00:00
node:PSpirvOp;
begin
2022-11-15 12:54:47 +00:00
deco:=Fetch(Data,Op.OpDecorate,dec_id,param);
if (deco^.node<>nil) then Exit;
2022-05-31 07:17:14 +00:00
node:=AddSpirvOp(Op.OpDecorate);
2022-09-05 13:30:24 +00:00
node^.AddParam(Data);
2022-05-31 07:17:14 +00:00
node^.AddLiteral(dec_id,Decoration.GetStr(dec_id));
2022-11-15 12:54:47 +00:00
2022-05-31 07:17:14 +00:00
Case dec_id of
Decoration.BuiltIn:
node^.AddLiteral(param,BuiltIn.GetStr(param));
Decoration.ArrayStride,
Decoration.MatrixStride,
Decoration.Location,
Decoration.Index,
Decoration.Binding,
Decoration.DescriptorSet:
node^.AddLiteral(param);
else;
end;
2022-11-15 12:54:47 +00:00
deco^.node:=node;
2022-05-31 07:17:14 +00:00
end;
2022-11-15 12:54:47 +00:00
procedure TsrDecorateList.OpMember(Data:PsrNode;index,offset:DWORD);
2022-05-31 07:17:14 +00:00
var
2022-11-15 12:54:47 +00:00
deco:PsrDecorate;
2022-05-31 07:17:14 +00:00
node:PSpirvOp;
begin
2022-11-15 12:54:47 +00:00
deco:=Fetch(Data,Op.OpMemberDecorate,index,offset);
if (deco^.node<>nil) then Exit;
2022-05-31 07:17:14 +00:00
node:=AddSpirvOp(Op.OpMemberDecorate);
2022-09-05 13:30:24 +00:00
node^.AddParam(Data);
2022-05-31 07:17:14 +00:00
node^.AddLiteral(index);
node^.AddLiteral(Decoration.Offset,Decoration.GetStr(Decoration.Offset));
node^.AddLiteral(offset);
2022-11-15 12:54:47 +00:00
deco^.node:=node;
2022-05-31 07:17:14 +00:00
end;
2022-11-15 12:54:47 +00:00
//
procedure TsrDebugInfoList.OpSource(const n:RawByteString);
2022-05-31 07:17:14 +00:00
var
node:PSpirvOp;
begin
node:=AddSpirvOp(Op.OpSourceExtension);
node^.AddString(n);
end;
2022-09-05 13:30:24 +00:00
procedure TsrDebugInfoList.OpName(Data:PsrNode;const n:RawByteString);
2022-05-31 07:17:14 +00:00
var
node:PSpirvOp;
begin
node:=AddSpirvOp(Op.OpName);
2022-09-05 13:30:24 +00:00
node^.AddParam(Data);
node^.AddString(n);
end;
function TsrDebugInfoList.OpString(const n:RawByteString):PsrNode;
var
node:PSpirvOp;
begin
node:=AddSpirvOp(Op.OpString);
node^.pDst:=Emit.NewRefNode;
2022-05-31 07:17:14 +00:00
node^.AddString(n);
2022-09-05 13:30:24 +00:00
Result:=node^.pDst;
2022-05-31 07:17:14 +00:00
end;
2022-11-15 12:54:47 +00:00
//
2022-05-31 07:17:14 +00:00
end.