mirror of https://github.com/red-prig/fpPS4.git
This commit is contained in:
parent
d21e81e41d
commit
6226cceb19
|
@ -1708,6 +1708,8 @@ var
|
||||||
|
|
||||||
Event:TvEvent2;
|
Event:TvEvent2;
|
||||||
|
|
||||||
|
pa:TPushConstAllocator;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=True;
|
Result:=True;
|
||||||
|
|
||||||
|
@ -2016,10 +2018,21 @@ begin
|
||||||
FRenderCmd:=LastRenderCmd;
|
FRenderCmd:=LastRenderCmd;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
pa.Init;
|
||||||
|
//
|
||||||
|
|
||||||
|
{$ifdef ww}Writeln('[FPSShader]');{$endif}
|
||||||
|
FPSShader:=FetchShader(vShaderStagePs,1,GPU_REGS,@pa);
|
||||||
|
//if (FPSShader=nil) then Exit;
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
{$ifdef ww}Writeln('[FVSShader]');{$endif}
|
{$ifdef ww}Writeln('[FVSShader]');{$endif}
|
||||||
FVSShader:=FetchShader(vShaderStageVs,0,GPU_REGS);
|
FVSShader:=FetchShader(vShaderStageVs,0,GPU_REGS,@pa);
|
||||||
if (FVSShader=nil) then Exit(False);
|
if (FVSShader=nil) then Exit(False);
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
FAttrBuilder:=Default(TvAttrBuilder);
|
FAttrBuilder:=Default(TvAttrBuilder);
|
||||||
FVSShader.EnumVertLayout(@FAttrBuilder.AddAttr,FVSShader.FDescSetId,@GPU_REGS.SPI.VS.USER_DATA);
|
FVSShader.EnumVertLayout(@FAttrBuilder.AddAttr,FVSShader.FDescSetId,@GPU_REGS.SPI.VS.USER_DATA);
|
||||||
|
|
||||||
|
@ -2034,9 +2047,7 @@ begin
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{$ifdef ww}Writeln('[FPSShader]');{$endif}
|
//
|
||||||
FPSShader:=FetchShader(vShaderStagePs,1,GPU_REGS);
|
|
||||||
//if (FPSShader=nil) then Exit;
|
|
||||||
|
|
||||||
FShadersKey:=Default(TvShadersKey);
|
FShadersKey:=Default(TvShadersKey);
|
||||||
FShadersKey.SetVSShader(FVSShader);
|
FShadersKey.SetVSShader(FVSShader);
|
||||||
|
@ -2045,6 +2056,8 @@ begin
|
||||||
FShaderGroup:=FetchShaderGroup(@FShadersKey);
|
FShaderGroup:=FetchShaderGroup(@FShadersKey);
|
||||||
Assert(FShaderGroup<>nil);
|
Assert(FShaderGroup<>nil);
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
FRenderCmd.FPipeline.FShaderGroup:=FShaderGroup;
|
FRenderCmd.FPipeline.FShaderGroup:=FShaderGroup;
|
||||||
|
|
||||||
FDescriptorGroup:=FetchDescriptorGroup(GFXRing.CmdBuffer,FShaderGroup.FLayout);
|
FDescriptorGroup:=FetchDescriptorGroup(GFXRing.CmdBuffer,FShaderGroup.FLayout);
|
||||||
|
@ -2119,18 +2132,6 @@ begin
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
if (FVSShader.FPushConst.size<>0) then
|
|
||||||
begin
|
|
||||||
pData:=FVSShader.GetPushConstData(@GPU_REGS.SPI.VS.USER_DATA);
|
|
||||||
|
|
||||||
if (pData<>nil) then
|
|
||||||
GFXRing.CmdBuffer.PushConstant(VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
||||||
ord(VK_SHADER_STAGE_VERTEX_BIT),
|
|
||||||
0,FVSShader.FPushConst.size,
|
|
||||||
pData);
|
|
||||||
|
|
||||||
end;
|
|
||||||
|
|
||||||
if (FPSShader<>nil) then
|
if (FPSShader<>nil) then
|
||||||
if (FPSShader.FPushConst.size<>0) then
|
if (FPSShader.FPushConst.size<>0) then
|
||||||
begin
|
begin
|
||||||
|
@ -2139,10 +2140,22 @@ begin
|
||||||
if (pData<>nil) then
|
if (pData<>nil) then
|
||||||
GFXRing.CmdBuffer.PushConstant(VK_PIPELINE_BIND_POINT_GRAPHICS,
|
GFXRing.CmdBuffer.PushConstant(VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||||
ord(VK_SHADER_STAGE_FRAGMENT_BIT),
|
ord(VK_SHADER_STAGE_FRAGMENT_BIT),
|
||||||
0,FPSShader.FPushConst.size,
|
FPSShader.FPushConst.offset,FPSShader.FPushConst.size,
|
||||||
pData);
|
pData);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if (FVSShader.FPushConst.size<>0) then
|
||||||
|
begin
|
||||||
|
pData:=FVSShader.GetPushConstData(@GPU_REGS.SPI.VS.USER_DATA);
|
||||||
|
|
||||||
|
if (pData<>nil) then
|
||||||
|
GFXRing.CmdBuffer.PushConstant(VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||||
|
ord(VK_SHADER_STAGE_VERTEX_BIT),
|
||||||
|
FVSShader.FPushConst.offset,FVSShader.FPushConst.size,
|
||||||
|
pData);
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
if (Length(FAttrBuilder.FBindExt)<>0) then
|
if (Length(FAttrBuilder.FBindExt)<>0) then
|
||||||
begin
|
begin
|
||||||
For i:=0 to High(FAttrBuilder.FBindExt) do
|
For i:=0 to High(FAttrBuilder.FBindExt) do
|
||||||
|
@ -2248,6 +2261,9 @@ var
|
||||||
FShaderGroup:TvShaderGroup;
|
FShaderGroup:TvShaderGroup;
|
||||||
|
|
||||||
FComputePipeline:TvComputePipeline2;
|
FComputePipeline:TvComputePipeline2;
|
||||||
|
|
||||||
|
pa:TPushConstAllocator;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=False;
|
Result:=False;
|
||||||
|
|
||||||
|
@ -2269,7 +2285,9 @@ begin
|
||||||
GFXRing.AllocCmdBuffer;
|
GFXRing.AllocCmdBuffer;
|
||||||
GFXRing.CmdBuffer.EndRenderPass;
|
GFXRing.CmdBuffer.EndRenderPass;
|
||||||
|
|
||||||
FCSShader:=FetchShader(vShaderStageCs,0,GPU_REGS);
|
pa.Init;
|
||||||
|
|
||||||
|
FCSShader:=FetchShader(vShaderStageCs,0,GPU_REGS,@pa);
|
||||||
if (FCSShader=nil) then Exit;
|
if (FCSShader=nil) then Exit;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -835,6 +835,7 @@ begin
|
||||||
|
|
||||||
B[p]:=Default(TVkPushConstantRange);
|
B[p]:=Default(TVkPushConstantRange);
|
||||||
B[p].stageFlags:=ord(FShaders[i].FStage);
|
B[p].stageFlags:=ord(FShaders[i].FStage);
|
||||||
|
B[p].offset :=FShaders[i].FPushConst.offset;
|
||||||
B[p].size :=FShaders[i].FPushConst.size;
|
B[p].size :=FShaders[i].FPushConst.size;
|
||||||
|
|
||||||
Inc(p);
|
Inc(p);
|
||||||
|
|
|
@ -47,7 +47,16 @@ type
|
||||||
Destructor Destroy; override;
|
Destructor Destroy; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function FetchShader(FStage:TvShaderStage;FDescSetId:Integer;var GPU_REGS:TGPU_REGS):TvShaderExt;
|
PPushConstAllocator=^TPushConstAllocator;
|
||||||
|
TPushConstAllocator=object
|
||||||
|
size:DWORD;
|
||||||
|
offset:DWORD;
|
||||||
|
Procedure Init;
|
||||||
|
function GetAvailable:DWORD;
|
||||||
|
procedure Apply(i:DWORD);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function FetchShader(FStage:TvShaderStage;FDescSetId:Integer;var GPU_REGS:TGPU_REGS;pc:PPushConstAllocator):TvShaderExt;
|
||||||
function FetchShaderGroup(F:PvShadersKey):TvShaderGroup;
|
function FetchShaderGroup(F:PvShadersKey):TvShaderGroup;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
@ -192,7 +201,27 @@ begin
|
||||||
FileClose(F);
|
FileClose(F);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ParseShader(FStage:TvShaderStage;pData:PDWORD;var GPU_REGS:TGPU_REGS):TMemoryStream;
|
procedure TPushConstAllocator.Init;
|
||||||
|
begin
|
||||||
|
Size:=limits.maxPushConstantsSize;
|
||||||
|
offset:=0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TPushConstAllocator.GetAvailable:DWORD;
|
||||||
|
begin
|
||||||
|
Result:=0;
|
||||||
|
if (offset<Size) then
|
||||||
|
begin
|
||||||
|
Result:=Size-offset;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TPushConstAllocator.Apply(i:DWORD);
|
||||||
|
begin
|
||||||
|
offset:=offset+i;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function ParseShader(FStage:TvShaderStage;pData:PDWORD;var GPU_REGS:TGPU_REGS;pc:PPushConstAllocator):TMemoryStream;
|
||||||
var
|
var
|
||||||
SprvEmit:TSprvEmit;
|
SprvEmit:TSprvEmit;
|
||||||
begin
|
begin
|
||||||
|
@ -227,12 +256,16 @@ begin
|
||||||
|
|
||||||
SprvEmit.Config.maxUniformBufferRange :=0; // $FFFF
|
SprvEmit.Config.maxUniformBufferRange :=0; // $FFFF
|
||||||
SprvEmit.Config.PushConstantsOffset :=0; // 0
|
SprvEmit.Config.PushConstantsOffset :=0; // 0
|
||||||
SprvEmit.Config.maxPushConstantsSize :=limits.maxPushConstantsSize; // 128
|
|
||||||
SprvEmit.Config.minStorageBufferOffsetAlignment:=limits.minStorageBufferOffsetAlignment; // $10
|
SprvEmit.Config.minStorageBufferOffsetAlignment:=limits.minStorageBufferOffsetAlignment; // $10
|
||||||
SprvEmit.Config.minUniformBufferOffsetAlignment:=limits.minUniformBufferOffsetAlignment; // $100
|
SprvEmit.Config.minUniformBufferOffsetAlignment:=limits.minUniformBufferOffsetAlignment; // $100
|
||||||
|
|
||||||
SprvEmit.Config.maxPushConstantsSize:=16*4;
|
SprvEmit.Config.maxPushConstantsSize:=0;
|
||||||
SprvEmit.Config.maxPushConstantsSize:=12;
|
if (pc<>nil) then
|
||||||
|
begin
|
||||||
|
SprvEmit.Config.PushConstantsOffset :=pc^.offset;
|
||||||
|
SprvEmit.Config.maxPushConstantsSize:=pc^.GetAvailable;
|
||||||
|
end;
|
||||||
|
|
||||||
//SprvEmit.Config.UseVertexInput:=False;
|
//SprvEmit.Config.UseVertexInput:=False;
|
||||||
|
|
||||||
if (SprvEmit.ParseStage(pData)>1) then
|
if (SprvEmit.ParseStage(pData)>1) then
|
||||||
|
@ -253,7 +286,7 @@ begin
|
||||||
//DumpSpv(FStage,Result);
|
//DumpSpv(FStage,Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function _FetchShader(FStage:TvShaderStage;pData:PDWORD;FDescSetId:Integer;var GPU_REGS:TGPU_REGS):TvShaderExt;
|
function _FetchShader(FStage:TvShaderStage;pData:PDWORD;FDescSetId:Integer;var GPU_REGS:TGPU_REGS;pc:PPushConstAllocator):TvShaderExt;
|
||||||
var
|
var
|
||||||
F:TShaderDataKey;
|
F:TShaderDataKey;
|
||||||
|
|
||||||
|
@ -296,7 +329,20 @@ begin
|
||||||
FShader.EnumUnifLayout(@ch.AddAttr,FDescSetId,pUserData);
|
FShader.EnumUnifLayout(@ch.AddAttr,FDescSetId,pUserData);
|
||||||
if ch.FResult then
|
if ch.FResult then
|
||||||
begin
|
begin
|
||||||
Break;
|
|
||||||
|
if (FShader.FPushConst.size<>0) and (pc<>nil) then
|
||||||
|
begin
|
||||||
|
if (FShader.FPushConst.offset=pc^.offset) then
|
||||||
|
if (FShader.FPushConst.size<=pc^.GetAvailable) then
|
||||||
|
begin
|
||||||
|
pc^.Apply(FShader.FPushConst.size);
|
||||||
|
Break;
|
||||||
|
end;
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
Break;
|
||||||
|
end;
|
||||||
|
|
||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
FShader:=nil;
|
FShader:=nil;
|
||||||
|
@ -306,13 +352,20 @@ begin
|
||||||
if (FShader=nil) then
|
if (FShader=nil) then
|
||||||
begin
|
begin
|
||||||
|
|
||||||
M:=ParseShader(FStage,pData,GPU_REGS);
|
M:=ParseShader(FStage,pData,GPU_REGS,pc);
|
||||||
Assert(M<>nil);
|
Assert(M<>nil);
|
||||||
|
|
||||||
FShader:=TvShaderExt.Create;
|
FShader:=TvShaderExt.Create;
|
||||||
FShader.FDescSetId:=FDescSetId;
|
FShader.FDescSetId:=FDescSetId;
|
||||||
FShader.LoadFromStream(M);
|
FShader.LoadFromStream(M);
|
||||||
|
|
||||||
|
if (FShader.FPushConst.size<>0) and (pc<>nil) then
|
||||||
|
begin
|
||||||
|
FShader.FPushConst.offset:=pc^.offset;
|
||||||
|
Dec(FShader.FPushConst.size,pc^.offset);
|
||||||
|
pc^.Apply(FShader.FPushConst.size);
|
||||||
|
end;
|
||||||
|
|
||||||
M.Free;
|
M.Free;
|
||||||
|
|
||||||
i:=Length(t.FShaders);
|
i:=Length(t.FShaders);
|
||||||
|
@ -350,7 +403,7 @@ begin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
M:=ParseShader(FStage,pData,GPU_REGS);
|
M:=ParseShader(FStage,pData,GPU_REGS,pc);
|
||||||
Assert(M<>nil);
|
Assert(M<>nil);
|
||||||
|
|
||||||
FShader:=TvShaderExt.Create;
|
FShader:=TvShaderExt.Create;
|
||||||
|
@ -359,6 +412,12 @@ begin
|
||||||
|
|
||||||
M.Free;
|
M.Free;
|
||||||
|
|
||||||
|
if (FShader.FPushConst.size<>0) and (pc<>nil) then
|
||||||
|
begin
|
||||||
|
FShader.FPushConst.offset:=pc^.offset;
|
||||||
|
Dec(FShader.FPushConst.size,pc^.offset);
|
||||||
|
pc^.Apply(FShader.FPushConst.size);
|
||||||
|
end;
|
||||||
|
|
||||||
SetLength(t.FShaders,1);
|
SetLength(t.FShaders,1);
|
||||||
t.FShaders[0]:=FShader;
|
t.FShaders[0]:=FShader;
|
||||||
|
@ -369,7 +428,7 @@ begin
|
||||||
Result:=FShader;
|
Result:=FShader;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function FetchShader(FStage:TvShaderStage;FDescSetId:Integer;var GPU_REGS:TGPU_REGS):TvShaderExt;
|
function FetchShader(FStage:TvShaderStage;FDescSetId:Integer;var GPU_REGS:TGPU_REGS;pc:PPushConstAllocator):TvShaderExt;
|
||||||
var
|
var
|
||||||
pData:PDWORD;
|
pData:PDWORD;
|
||||||
begin
|
begin
|
||||||
|
@ -387,7 +446,7 @@ begin
|
||||||
|
|
||||||
FShaderCacheSet.Lock_wr;
|
FShaderCacheSet.Lock_wr;
|
||||||
|
|
||||||
Result:=_FetchShader(FStage,pData,FDescSetId,GPU_REGS);
|
Result:=_FetchShader(FStage,pData,FDescSetId,GPU_REGS,pc);
|
||||||
|
|
||||||
FShaderCacheSet.Unlock;
|
FShaderCacheSet.Unlock;
|
||||||
end;
|
end;
|
||||||
|
|
Loading…
Reference in New Issue