This commit is contained in:
Pavel 2022-11-10 14:44:52 +03:00
parent d21e81e41d
commit 6226cceb19
3 changed files with 107 additions and 29 deletions

View File

@ -1708,6 +1708,8 @@ var
Event:TvEvent2;
pa:TPushConstAllocator;
begin
Result:=True;
@ -2016,10 +2018,21 @@ begin
FRenderCmd:=LastRenderCmd;
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}
FVSShader:=FetchShader(vShaderStageVs,0,GPU_REGS);
FVSShader:=FetchShader(vShaderStageVs,0,GPU_REGS,@pa);
if (FVSShader=nil) then Exit(False);
//
FAttrBuilder:=Default(TvAttrBuilder);
FVSShader.EnumVertLayout(@FAttrBuilder.AddAttr,FVSShader.FDescSetId,@GPU_REGS.SPI.VS.USER_DATA);
@ -2034,9 +2047,7 @@ begin
end;
end;
{$ifdef ww}Writeln('[FPSShader]');{$endif}
FPSShader:=FetchShader(vShaderStagePs,1,GPU_REGS);
//if (FPSShader=nil) then Exit;
//
FShadersKey:=Default(TvShadersKey);
FShadersKey.SetVSShader(FVSShader);
@ -2045,6 +2056,8 @@ begin
FShaderGroup:=FetchShaderGroup(@FShadersKey);
Assert(FShaderGroup<>nil);
//
FRenderCmd.FPipeline.FShaderGroup:=FShaderGroup;
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.FPushConst.size<>0) then
begin
@ -2139,10 +2140,22 @@ begin
if (pData<>nil) then
GFXRing.CmdBuffer.PushConstant(VK_PIPELINE_BIND_POINT_GRAPHICS,
ord(VK_SHADER_STAGE_FRAGMENT_BIT),
0,FPSShader.FPushConst.size,
FPSShader.FPushConst.offset,FPSShader.FPushConst.size,
pData);
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
begin
For i:=0 to High(FAttrBuilder.FBindExt) do
@ -2248,6 +2261,9 @@ var
FShaderGroup:TvShaderGroup;
FComputePipeline:TvComputePipeline2;
pa:TPushConstAllocator;
begin
Result:=False;
@ -2269,7 +2285,9 @@ begin
GFXRing.AllocCmdBuffer;
GFXRing.CmdBuffer.EndRenderPass;
FCSShader:=FetchShader(vShaderStageCs,0,GPU_REGS);
pa.Init;
FCSShader:=FetchShader(vShaderStageCs,0,GPU_REGS,@pa);
if (FCSShader=nil) then Exit;

View File

@ -835,6 +835,7 @@ begin
B[p]:=Default(TVkPushConstantRange);
B[p].stageFlags:=ord(FShaders[i].FStage);
B[p].offset :=FShaders[i].FPushConst.offset;
B[p].size :=FShaders[i].FPushConst.size;
Inc(p);

View File

@ -47,7 +47,16 @@ type
Destructor Destroy; override;
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;
implementation
@ -192,7 +201,27 @@ begin
FileClose(F);
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
SprvEmit:TSprvEmit;
begin
@ -227,12 +256,16 @@ begin
SprvEmit.Config.maxUniformBufferRange :=0; // $FFFF
SprvEmit.Config.PushConstantsOffset :=0; // 0
SprvEmit.Config.maxPushConstantsSize :=limits.maxPushConstantsSize; // 128
SprvEmit.Config.minStorageBufferOffsetAlignment:=limits.minStorageBufferOffsetAlignment; // $10
SprvEmit.Config.minUniformBufferOffsetAlignment:=limits.minUniformBufferOffsetAlignment; // $100
SprvEmit.Config.maxPushConstantsSize:=16*4;
SprvEmit.Config.maxPushConstantsSize:=12;
SprvEmit.Config.maxPushConstantsSize:=0;
if (pc<>nil) then
begin
SprvEmit.Config.PushConstantsOffset :=pc^.offset;
SprvEmit.Config.maxPushConstantsSize:=pc^.GetAvailable;
end;
//SprvEmit.Config.UseVertexInput:=False;
if (SprvEmit.ParseStage(pData)>1) then
@ -253,7 +286,7 @@ begin
//DumpSpv(FStage,Result);
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
F:TShaderDataKey;
@ -296,7 +329,20 @@ begin
FShader.EnumUnifLayout(@ch.AddAttr,FDescSetId,pUserData);
if ch.FResult then
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
begin
FShader:=nil;
@ -306,13 +352,20 @@ begin
if (FShader=nil) then
begin
M:=ParseShader(FStage,pData,GPU_REGS);
M:=ParseShader(FStage,pData,GPU_REGS,pc);
Assert(M<>nil);
FShader:=TvShaderExt.Create;
FShader.FDescSetId:=FDescSetId;
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;
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);
FShader:=TvShaderExt.Create;
@ -359,6 +412,12 @@ begin
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);
t.FShaders[0]:=FShader;
@ -369,7 +428,7 @@ begin
Result:=FShader;
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
pData:PDWORD;
begin
@ -387,7 +446,7 @@ begin
FShaderCacheSet.Lock_wr;
Result:=_FetchShader(FStage,pData,FDescSetId,GPU_REGS);
Result:=_FetchShader(FStage,pData,FDescSetId,GPU_REGS,pc);
FShaderCacheSet.Unlock;
end;