mirror of https://github.com/red-prig/fpPS4.git
This commit is contained in:
parent
69f3762607
commit
ea6f59bcd2
|
@ -23,10 +23,6 @@ uses
|
||||||
vShaderExt,
|
vShaderExt,
|
||||||
|
|
||||||
SprvEmit,
|
SprvEmit,
|
||||||
|
|
||||||
emit_post,
|
|
||||||
emit_alloc,
|
|
||||||
emit_print,
|
|
||||||
emit_bin;
|
emit_bin;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -47,7 +43,7 @@ type
|
||||||
|
|
||||||
TShaderCodeCache=class
|
TShaderCodeCache=class
|
||||||
key:TShaderDataKey;
|
key:TShaderDataKey;
|
||||||
FShaders:array of TvShaderExt;
|
FShaderAliases:array of TvShaderExt;
|
||||||
function AddShader(FDescSetId:Integer;Stream:TStream):TvShaderExt;
|
function AddShader(FDescSetId:Integer;Stream:TStream):TvShaderExt;
|
||||||
Destructor Destroy; override;
|
Destructor Destroy; override;
|
||||||
end;
|
end;
|
||||||
|
@ -61,6 +57,24 @@ type
|
||||||
procedure Apply(i:DWORD);
|
procedure Apply(i:DWORD);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{
|
||||||
|
TShaderCacheSet
|
||||||
|
---------------
|
||||||
|
[TShaderCodeCache]
|
||||||
|
(
|
||||||
|
[TShaderDataKey]
|
||||||
|
FShaderAliases [TvShaderExt]
|
||||||
|
---------------
|
||||||
|
|
||||||
|
---------------
|
||||||
|
...............
|
||||||
|
---------------
|
||||||
|
)
|
||||||
|
---------------
|
||||||
|
...............
|
||||||
|
---------------
|
||||||
|
}
|
||||||
|
|
||||||
function FetchShader(FStage:TvShaderStage;FDescSetId:Integer;var GPU_REGS:TGPU_REGS;pc:PPushConstAllocator):TvShaderExt;
|
function FetchShader(FStage:TvShaderStage;FDescSetId:Integer;var GPU_REGS:TGPU_REGS;pc:PPushConstAllocator):TvShaderExt;
|
||||||
function FetchShaderGroup(F:PvShadersKey):TvShaderGroup;
|
function FetchShaderGroup(F:PvShadersKey):TvShaderGroup;
|
||||||
|
|
||||||
|
@ -147,9 +161,9 @@ begin
|
||||||
Result.FDescSetId:=FDescSetId;
|
Result.FDescSetId:=FDescSetId;
|
||||||
Result.LoadFromStream(Stream);
|
Result.LoadFromStream(Stream);
|
||||||
|
|
||||||
i:=Length(FShaders);
|
i:=Length(FShaderAliases);
|
||||||
SetLength(FShaders,i+1);
|
SetLength(FShaderAliases,i+1);
|
||||||
FShaders[i]:=Result;
|
FShaderAliases[i]:=Result;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Destructor TShaderCodeCache.Destroy;
|
Destructor TShaderCodeCache.Destroy;
|
||||||
|
@ -334,6 +348,25 @@ begin
|
||||||
//DumpSpv(FStage,Result);
|
//DumpSpv(FStage,Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function test_unif(FShader:TvShaderExt;FDescSetId:Integer;pUserData:Pointer):Boolean;
|
||||||
|
var
|
||||||
|
ch:TvBufOffsetChecker;
|
||||||
|
begin
|
||||||
|
if (FShader.FDescSetId<>FDescSetId) then Exit(False);
|
||||||
|
ch.FResult:=True;
|
||||||
|
FShader.EnumUnifLayout(@ch.AddAttr,FDescSetId,pUserData);
|
||||||
|
Result:=ch.FResult;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function test_push_const(FShader:TvShaderExt;pc_offset,pc_size:DWORD):Boolean;
|
||||||
|
begin
|
||||||
|
with FShader.FPushConst do
|
||||||
|
begin
|
||||||
|
Result:=(offset >=pc_offset) and //Checking offsets push constant
|
||||||
|
((offset+size)<=pc_size); //Is the remaining size sufficient?
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function _FetchShader(FStage:TvShaderStage;pData:PDWORD;FDescSetId:Integer;var GPU_REGS:TGPU_REGS;pc:PPushConstAllocator):TvShaderExt;
|
function _FetchShader(FStage:TvShaderStage;pData:PDWORD;FDescSetId:Integer;var GPU_REGS:TGPU_REGS;pc:PPushConstAllocator):TvShaderExt;
|
||||||
var
|
var
|
||||||
F:TShaderDataKey;
|
F:TShaderDataKey;
|
||||||
|
@ -345,87 +378,58 @@ var
|
||||||
M:TMemoryStream;
|
M:TMemoryStream;
|
||||||
|
|
||||||
pUserData:Pointer;
|
pUserData:Pointer;
|
||||||
ch:TvBufOffsetChecker;
|
|
||||||
|
|
||||||
|
|
||||||
|
pc_offset,pc_size,pc_diff:DWORD;
|
||||||
begin
|
begin
|
||||||
F:=Default(TShaderDataKey);
|
F:=Default(TShaderDataKey);
|
||||||
F.FStage:=FStage;
|
F.FStage:=FStage;
|
||||||
F.pData :=pData;
|
F.pData :=pData;
|
||||||
|
|
||||||
|
{
|
||||||
|
...start <-\
|
||||||
|
|
|
||||||
|
...offset |
|
||||||
|
|
|
||||||
|
...size --/
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pc<>nil) then //push const allocator used?
|
||||||
|
begin
|
||||||
|
pc_offset:=pc^.offset;
|
||||||
|
pc_size :=pc^.GetAvailable;
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
pc_offset:=0;
|
||||||
|
pc_size :=0;
|
||||||
|
end;
|
||||||
|
|
||||||
t:=_FetchShaderCodeCache(F);
|
t:=_FetchShaderCodeCache(F);
|
||||||
|
|
||||||
if (Length(t.FShaders)<>0) then
|
FShader:=nil;
|
||||||
|
|
||||||
|
if (Length(t.FShaderAliases)<>0) then
|
||||||
begin
|
begin
|
||||||
|
|
||||||
pUserData:=GPU_REGS.get_user_data(FStage);
|
pUserData:=GPU_REGS.get_user_data(FStage);
|
||||||
|
|
||||||
FShader:=nil;
|
For i:=0 to High(t.FShaderAliases) do
|
||||||
For i:=0 to High(t.FShaders) do
|
|
||||||
begin
|
begin
|
||||||
FShader:=t.FShaders[i];
|
FShader:=t.FShaderAliases[i];
|
||||||
ch.FResult:=True;
|
|
||||||
FShader.EnumUnifLayout(@ch.AddAttr,FDescSetId,pUserData);
|
if test_unif(FShader,FDescSetId,pUserData) then //Checking offsets within a shader
|
||||||
if ch.FResult then //Checking offsets within a shader
|
if test_push_const(FShader,pc_offset,pc_size) then
|
||||||
begin
|
begin
|
||||||
|
Break; //found
|
||||||
if (pc<>nil) then //push const allocator used?
|
|
||||||
begin
|
|
||||||
if (FShader.FPushConst.size<>0) then //push const used?
|
|
||||||
begin
|
|
||||||
if (FShader.FPushConst.offset=pc^.offset) and //Checking offsets push constant
|
|
||||||
(FShader.FPushConst.size<=pc^.GetAvailable) then //Is the remaining size sufficient?
|
|
||||||
begin
|
|
||||||
//found and apply with allocator
|
|
||||||
pc^.Apply(FShader.FPushConst.size);
|
|
||||||
Break;
|
|
||||||
end else
|
|
||||||
begin
|
|
||||||
FShader:=nil; //reset with not found
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end else
|
|
||||||
begin //push const allocator not used
|
|
||||||
if (FShader.FPushConst.size<>0) then
|
|
||||||
begin
|
|
||||||
FShader:=nil; //reset with not found
|
|
||||||
end else
|
|
||||||
begin
|
|
||||||
//found with no push const
|
|
||||||
Break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
end else
|
|
||||||
begin
|
|
||||||
FShader:=nil; //reset with not found
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
if (FShader=nil) then //Rebuild with different parameters
|
|
||||||
begin
|
|
||||||
|
|
||||||
M:=ParseShader(FStage,pData,GPU_REGS,pc);
|
|
||||||
Assert(M<>nil);
|
|
||||||
|
|
||||||
FShader:=t.AddShader(FDescSetId,M);
|
|
||||||
|
|
||||||
M.Free;
|
|
||||||
|
|
||||||
if (FShader.FPushConst.size<>0) and (pc<>nil) then //push const used?
|
|
||||||
begin
|
|
||||||
FShader.FPushConst.offset:=pc^.offset; //Save offset
|
|
||||||
Dec(FShader.FPushConst.size,pc^.offset); //Move up size
|
|
||||||
pc^.Apply(FShader.FPushConst.size); //apply with allocator
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
FShader:=nil; //reset with not found
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end else
|
end;
|
||||||
|
|
||||||
|
if (FShader=nil) then //Rebuild with different parameters
|
||||||
begin
|
begin
|
||||||
|
|
||||||
//first parse
|
|
||||||
|
|
||||||
M:=ParseShader(FStage,pData,GPU_REGS,pc);
|
M:=ParseShader(FStage,pData,GPU_REGS,pc);
|
||||||
Assert(M<>nil);
|
Assert(M<>nil);
|
||||||
|
|
||||||
|
@ -435,13 +439,26 @@ begin
|
||||||
|
|
||||||
if (FShader.FPushConst.size<>0) and (pc<>nil) then //push const used?
|
if (FShader.FPushConst.size<>0) and (pc<>nil) then //push const used?
|
||||||
begin
|
begin
|
||||||
FShader.FPushConst.offset:=pc^.offset; //Save offset
|
FShader.FPushConst.offset:=pc_offset; //Save offset
|
||||||
Dec(FShader.FPushConst.size,pc^.offset); //Move up size
|
Dec(FShader.FPushConst.size,pc_offset); //Move up size
|
||||||
pc^.Apply(FShader.FPushConst.size); //apply with allocator
|
|
||||||
|
{
|
||||||
|
...start
|
||||||
|
|
||||||
|
...offset<-\
|
||||||
|
|
|
||||||
|
...size --/
|
||||||
|
}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if (FShader.FPushConst.size<>0) and (pc<>nil) then //push const used?
|
||||||
|
begin
|
||||||
|
pc_diff:=FShader.FPushConst.offset-pc_offset; //get diff offset
|
||||||
|
pc^.Apply(pc_diff+FShader.FPushConst.size); //apply with allocator
|
||||||
|
end;
|
||||||
|
|
||||||
Result:=FShader;
|
Result:=FShader;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue